Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace old transform code with Geometry::transform #354

Merged
merged 11 commits into from
Mar 15, 2022
77 changes: 72 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ map-macro = "0.2.0"
nalgebra = "0.30.0"
notify = "5.0.0-pre.14"
num-traits = "0.2.14"
parking_lot = "0.12.0"
parry2d-f64 = "0.8.0"
parry3d-f64 = "0.8.0"
spade = "2.0.0"
Expand Down
1 change: 0 additions & 1 deletion src/kernel/algorithms/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod approximation;
pub mod sweep;
pub mod transform;
pub mod triangulation;
2 changes: 1 addition & 1 deletion src/kernel/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod tests {
let mut contains_top_face = false;

for face in swept.topology().faces() {
if matches!(face.get(), Face::Face { .. }) {
if matches!(&*face.get(), Face::Face { .. }) {
if face.get().clone() == bottom_face {
contains_bottom_face = true;
}
Expand Down
100 changes: 0 additions & 100 deletions src/kernel/algorithms/transform.rs

This file was deleted.

57 changes: 54 additions & 3 deletions src/kernel/shape/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::{
kernel::geometry::{Curve, Surface},
math::Point,
kernel::{
geometry::{Curve, Surface},
topology::faces::Face,
},
math::{Point, Transform},
};

use super::{
handle::{Handle, Storage},
Curves, Iter, Points, Surfaces,
Curves, Faces, Iter, Points, Surfaces,
};

/// API to access a shape's geometry
Expand All @@ -27,6 +30,15 @@ pub struct Geometry<'r> {
pub(super) points: &'r mut Points,
pub(super) curves: &'r mut Curves,
pub(super) surfaces: &'r mut Surfaces,

// This is needed here for a weird workaround, which in turn is necessary
// because triangle representation still exists. Once triangle
// representation is no longer a thing, this field can be moved to
// `Topology`, where it belongs.
//
// This issue has some context on triangle representation:
// https://github.com/hannobraun/Fornjot/issues/97
pub(super) faces: &'r mut Faces,
}

impl Geometry<'_> {
Expand Down Expand Up @@ -60,6 +72,45 @@ impl Geometry<'_> {
handle
}

/// Transform the geometry of the shape
///
/// Since the topological types refer to geometry, and don't contain any
/// geometry themselves, this transforms the whole shape.
pub fn transform(&mut self, transform: &Transform) {
for point in self.points.iter_mut() {
let trans = {
let point = point.get();
transform.transform_point(&point)
};
*point.get_mut() = trans;
}
for curve in self.curves.iter_mut() {
let trans = {
let curve = curve.get();
curve.transform(transform)
};
*curve.get_mut() = trans;
}
for surface in self.surfaces.iter_mut() {
let trans = {
let surface = surface.get();
surface.transform(transform)
};
*surface.get_mut() = trans;
}

// While some faces use triangle representation, we need this weird
// workaround here.
for face in self.faces.iter_mut() {
use std::ops::DerefMut as _;
if let Face::Triangles(triangles) = face.get_mut().deref_mut() {
for triangle in triangles {
*triangle = transform.transform_triangle(triangle);
}
}
}
}

/// Access an iterator over all points
///
/// The caller must not make any assumptions about the order of points.
Expand Down
Loading