diff --git a/crates/fj-core/src/algorithms/bounding_volume/cycle.rs b/crates/fj-core/src/algorithms/bounding_volume/cycle.rs index 434f0454b..138583387 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/cycle.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/cycle.rs @@ -2,13 +2,16 @@ use fj_math::Aabb; use crate::{geometry::Geometry, topology::Cycle}; -impl super::BoundingVolume<2> for Cycle { - fn aabb(&self, geometry: &Geometry) -> Option> { +impl super::BoundingVolume<2> for &Cycle { + fn aabb(self, geometry: &Geometry) -> Option> { + let cycle = self; + let mut aabb: Option> = None; - for edge in self.half_edges() { - let new_aabb = - edge.aabb(geometry).expect("`Edge` can always compute AABB"); + for half_edge in cycle.half_edges() { + let new_aabb = half_edge + .aabb(geometry) + .expect("`HalfEdge` can always compute AABB"); aabb = Some(aabb.map_or(new_aabb, |aabb| aabb.merged(&new_aabb))); } diff --git a/crates/fj-core/src/algorithms/bounding_volume/face.rs b/crates/fj-core/src/algorithms/bounding_volume/face.rs index dcc188c23..dd2411435 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/face.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/face.rs @@ -5,8 +5,8 @@ use crate::{ topology::Face, }; -impl super::BoundingVolume<3> for Face { - fn aabb(&self, geometry: &Geometry) -> Option> { +impl super::BoundingVolume<3> for &Face { + fn aabb(self, geometry: &Geometry) -> Option> { self.region().exterior().aabb(geometry).map(|aabb2| { let surface = geometry.of_surface(self.surface()); diff --git a/crates/fj-core/src/algorithms/bounding_volume/edge.rs b/crates/fj-core/src/algorithms/bounding_volume/half_edge.rs similarity index 65% rename from crates/fj-core/src/algorithms/bounding_volume/edge.rs rename to crates/fj-core/src/algorithms/bounding_volume/half_edge.rs index 7a5187806..76523409f 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/edge.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/half_edge.rs @@ -6,9 +6,14 @@ use crate::{ topology::HalfEdge, }; -impl super::BoundingVolume<2> for Handle { - fn aabb(&self, geometry: &Geometry) -> Option> { - match geometry.of_half_edge(self).path { +impl super::BoundingVolume<2> for &Handle { + fn aabb(self, geometry: &Geometry) -> Option> { + let half_edge = self; + + let half_edge = geometry.of_half_edge(half_edge); + let path = half_edge.path; + + match path { SurfacePath::Circle(circle) => { // Just calculate the AABB of the whole circle. This is not the // most precise, but it should do for now. @@ -22,10 +27,8 @@ impl super::BoundingVolume<2> for Handle { }) } SurfacePath::Line(_) => { - let geometry = geometry.of_half_edge(self); - - let points = geometry.boundary.inner.map(|point_curve| { - geometry.path.point_from_path_coords(point_curve) + let points = half_edge.boundary.inner.map(|point_curve| { + path.point_from_path_coords(point_curve) }); Some(Aabb::<2>::from_points(points)) diff --git a/crates/fj-core/src/algorithms/bounding_volume/mod.rs b/crates/fj-core/src/algorithms/bounding_volume/mod.rs index 748bd534b..6efc6ff8a 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/mod.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/mod.rs @@ -1,8 +1,8 @@ //! Compute a bounding volume for an object mod cycle; -mod edge; mod face; +mod half_edge; mod shell; mod solid; @@ -15,5 +15,5 @@ pub trait BoundingVolume { /// Compute an axis-aligned bounding box (AABB) /// /// Return `None`, if no AABB can be computed (if the object is empty). - fn aabb(&self, geometry: &Geometry) -> Option>; + fn aabb(self, geometry: &Geometry) -> Option>; } diff --git a/crates/fj-core/src/algorithms/bounding_volume/shell.rs b/crates/fj-core/src/algorithms/bounding_volume/shell.rs index 6cafda424..fe9978ea1 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/shell.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/shell.rs @@ -2,8 +2,8 @@ use fj_math::Aabb; use crate::{geometry::Geometry, topology::Shell}; -impl super::BoundingVolume<3> for Shell { - fn aabb(&self, geometry: &Geometry) -> Option> { +impl super::BoundingVolume<3> for &Shell { + fn aabb(self, geometry: &Geometry) -> Option> { let mut aabb: Option> = None; for face in self.faces() { diff --git a/crates/fj-core/src/algorithms/bounding_volume/solid.rs b/crates/fj-core/src/algorithms/bounding_volume/solid.rs index e2ad4397b..a09bf2053 100644 --- a/crates/fj-core/src/algorithms/bounding_volume/solid.rs +++ b/crates/fj-core/src/algorithms/bounding_volume/solid.rs @@ -2,8 +2,8 @@ use fj_math::Aabb; use crate::{geometry::Geometry, topology::Solid}; -impl super::BoundingVolume<3> for Solid { - fn aabb(&self, geometry: &Geometry) -> Option> { +impl super::BoundingVolume<3> for &Solid { + fn aabb(self, geometry: &Geometry) -> Option> { let mut aabb: Option> = None; for shell in self.shells() { diff --git a/crates/fj/src/instance.rs b/crates/fj/src/instance.rs index 9e01f8eec..a6f147aec 100644 --- a/crates/fj/src/instance.rs +++ b/crates/fj/src/instance.rs @@ -47,7 +47,7 @@ impl Instance { pub fn process_model(&mut self, model: &M) -> Result where for<'r> (&'r M, Tolerance): Triangulate, - M: BoundingVolume<3>, + for<'r> &'r M: BoundingVolume<3>, { tracing_subscriber::registry() .with(tracing_subscriber::fmt::layer())