From 757a3980faca2d8f74e5fbd70e9d7adc128ff505 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Mar 2024 13:15:34 +0100 Subject: [PATCH 1/3] Provide `&Handle` to cycle approximation --- crates/fj-core/src/algorithms/approx/cycle.rs | 11 ++++++++--- crates/fj-core/src/algorithms/approx/face.rs | 10 ++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/fj-core/src/algorithms/approx/cycle.rs b/crates/fj-core/src/algorithms/approx/cycle.rs index f2b473afb..59d9bddc8 100644 --- a/crates/fj-core/src/algorithms/approx/cycle.rs +++ b/crates/fj-core/src/algorithms/approx/cycle.rs @@ -4,14 +4,18 @@ use fj_math::Segment; -use crate::{geometry::SurfaceGeometry, topology::Cycle, Core}; +use crate::{ + storage::Handle, + topology::{Cycle, Surface}, + Core, +}; use super::{ edge::{HalfEdgeApprox, HalfEdgeApproxCache}, Approx, ApproxPoint, Tolerance, }; -impl Approx for (&Cycle, &SurfaceGeometry) { +impl Approx for (&Cycle, &Handle) { type Approximation = CycleApprox; type Cache = HalfEdgeApproxCache; @@ -28,7 +32,8 @@ impl Approx for (&Cycle, &SurfaceGeometry) { .half_edges() .iter() .map(|half_edge| { - (half_edge, surface).approx_with_cache(tolerance, cache, core) + (half_edge, &core.layers.geometry.of_surface(surface)) + .approx_with_cache(tolerance, cache, core) }) .collect(); diff --git a/crates/fj-core/src/algorithms/approx/face.rs b/crates/fj-core/src/algorithms/approx/face.rs index 8deb299e7..be81fbc9f 100644 --- a/crates/fj-core/src/algorithms/approx/face.rs +++ b/crates/fj-core/src/algorithms/approx/face.rs @@ -90,18 +90,12 @@ impl Approx for &Face { // would need to provide its own approximation, as the edges that bound // it have nothing to do with its curvature. - let exterior = ( - self.region().exterior().deref(), - &core.layers.geometry.of_surface(self.surface()), - ) + let exterior = (self.region().exterior().deref(), self.surface()) .approx_with_cache(tolerance, cache, core); let mut interiors = BTreeSet::new(); for cycle in self.region().interiors() { - let cycle = ( - cycle.deref(), - &core.layers.geometry.of_surface(self.surface()), - ) + let cycle = (cycle.deref(), self.surface()) .approx_with_cache(tolerance, cache, core); interiors.insert(cycle); } From 35d763c18bcaa0716755408ec016e834742c662d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Mar 2024 13:15:34 +0100 Subject: [PATCH 2/3] Provide `&Handle` to half-edge approx --- crates/fj-core/src/algorithms/approx/cycle.rs | 3 +-- crates/fj-core/src/algorithms/approx/edge.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/fj-core/src/algorithms/approx/cycle.rs b/crates/fj-core/src/algorithms/approx/cycle.rs index 59d9bddc8..fd4311231 100644 --- a/crates/fj-core/src/algorithms/approx/cycle.rs +++ b/crates/fj-core/src/algorithms/approx/cycle.rs @@ -32,8 +32,7 @@ impl Approx for (&Cycle, &Handle) { .half_edges() .iter() .map(|half_edge| { - (half_edge, &core.layers.geometry.of_surface(surface)) - .approx_with_cache(tolerance, cache, core) + (half_edge, surface).approx_with_cache(tolerance, cache, core) }) .collect(); diff --git a/crates/fj-core/src/algorithms/approx/edge.rs b/crates/fj-core/src/algorithms/approx/edge.rs index 0484ea7b9..e668fb119 100644 --- a/crates/fj-core/src/algorithms/approx/edge.rs +++ b/crates/fj-core/src/algorithms/approx/edge.rs @@ -6,7 +6,9 @@ //! the caller doesn't have to deal with duplicate vertices. use crate::{ - geometry::SurfaceGeometry, storage::Handle, topology::HalfEdge, Core, + storage::Handle, + topology::{HalfEdge, Surface}, + Core, }; use super::{ @@ -14,7 +16,7 @@ use super::{ Tolerance, }; -impl Approx for (&Handle, &SurfaceGeometry) { +impl Approx for (&Handle, &Handle) { type Approximation = HalfEdgeApprox; type Cache = HalfEdgeApproxCache; @@ -36,7 +38,10 @@ impl Approx for (&Handle, &SurfaceGeometry) { match cache.start_position.get(half_edge.start_vertex()) { Some(position) => position, None => { - let position_global = surface + let position_global = core + .layers + .geometry + .of_surface(surface) .point_from_surface_coords(start_position_surface); cache.start_position.insert( half_edge.start_vertex().clone(), @@ -51,7 +56,7 @@ impl Approx for (&Handle, &SurfaceGeometry) { let approx = ( half_edge.curve(), &core.layers.geometry.of_half_edge(half_edge), - surface, + &core.layers.geometry.of_surface(surface), ) .approx_with_cache( tolerance, From 2e176fcb468a0847c78c48ebd52279a419ddd301 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 25 Mar 2024 13:15:34 +0100 Subject: [PATCH 3/3] Provide `&Handle` to curve approximation --- crates/fj-core/src/algorithms/approx/curve.rs | 47 ++++++++++--------- crates/fj-core/src/algorithms/approx/edge.rs | 2 +- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/crates/fj-core/src/algorithms/approx/curve.rs b/crates/fj-core/src/algorithms/approx/curve.rs index 43e7ddd15..837a24fe5 100644 --- a/crates/fj-core/src/algorithms/approx/curve.rs +++ b/crates/fj-core/src/algorithms/approx/curve.rs @@ -10,13 +10,13 @@ use crate::{ SurfacePath, }, storage::Handle, - topology::Curve, + topology::{Curve, Surface}, Core, }; use super::{Approx, ApproxPoint, Tolerance}; -impl Approx for (&Handle, &HalfEdgeGeometry, &SurfaceGeometry) { +impl Approx for (&Handle, &HalfEdgeGeometry, &Handle) { type Approximation = CurveApprox; type Cache = CurveApproxCache; @@ -33,7 +33,7 @@ impl Approx for (&Handle, &HalfEdgeGeometry, &SurfaceGeometry) { None => { let approx = approx_curve( &half_edge.path, - surface, + &core.layers.geometry.of_surface(surface), half_edge.boundary, tolerance, core, @@ -183,12 +183,9 @@ mod tests { use crate::{ algorithms::approx::{Approx, ApproxPoint}, - geometry::{ - CurveBoundary, GlobalPath, HalfEdgeGeometry, SurfaceGeometry, - SurfacePath, - }, - operations::insert::Insert, - topology::Curve, + geometry::{CurveBoundary, GlobalPath, HalfEdgeGeometry, SurfacePath}, + operations::{build::BuildSurface, insert::Insert}, + topology::{Curve, Surface}, Core, }; @@ -201,7 +198,7 @@ mod tests { SurfacePath::line_from_points([[1., 1.], [2., 1.]]); let boundary = CurveBoundary::from(boundary); let half_edge = HalfEdgeGeometry { path, boundary }; - let surface = core.layers.geometry.xz_plane(); + let surface = core.layers.topology.surfaces.xz_plane(); let tolerance = 1.; let approx = @@ -219,10 +216,11 @@ mod tests { SurfacePath::line_from_points([[1., 1.], [2., 1.]]); let boundary = CurveBoundary::from(boundary); let half_edge = HalfEdgeGeometry { path, boundary }; - let surface = SurfaceGeometry { - u: GlobalPath::circle_from_radius(1.), - v: [0., 0., 1.].into(), - }; + let surface = Surface::from_uv( + GlobalPath::circle_from_radius(1.), + [0., 0., 1.], + &mut core, + ); let tolerance = 1.; let approx = @@ -243,10 +241,7 @@ mod tests { ]); let boundary = CurveBoundary::from([[0.], [TAU]]); let half_edge = HalfEdgeGeometry { path, boundary }; - let surface = SurfaceGeometry { - u: global_path, - v: [0., 0., 1.].into(), - }; + let surface = Surface::from_uv(global_path, [0., 0., 1.], &mut core); let tolerance = 1.; let approx = @@ -257,8 +252,11 @@ mod tests { .into_iter() .map(|(point_local, _)| { let point_surface = path.point_from_path_coords(point_local); - let point_global = - surface.point_from_surface_coords(point_surface); + let point_global = core + .layers + .geometry + .of_surface(&surface) + .point_from_surface_coords(point_surface); ApproxPoint::new(point_local, point_global) }) .collect::>(); @@ -273,7 +271,7 @@ mod tests { let path = SurfacePath::circle_from_center_and_radius([0., 0.], 1.); let boundary = CurveBoundary::from([[0.], [TAU]]); let half_edge = HalfEdgeGeometry { path, boundary }; - let surface = core.layers.geometry.xz_plane(); + let surface = core.layers.topology.surfaces.xz_plane(); let tolerance = 1.; let approx = @@ -284,8 +282,11 @@ mod tests { .into_iter() .map(|(point_local, _)| { let point_surface = path.point_from_path_coords(point_local); - let point_global = - surface.point_from_surface_coords(point_surface); + let point_global = core + .layers + .geometry + .of_surface(&surface) + .point_from_surface_coords(point_surface); ApproxPoint::new(point_local, point_global) }) .collect::>(); diff --git a/crates/fj-core/src/algorithms/approx/edge.rs b/crates/fj-core/src/algorithms/approx/edge.rs index e668fb119..aa6f73f2a 100644 --- a/crates/fj-core/src/algorithms/approx/edge.rs +++ b/crates/fj-core/src/algorithms/approx/edge.rs @@ -56,7 +56,7 @@ impl Approx for (&Handle, &Handle) { let approx = ( half_edge.curve(), &core.layers.geometry.of_half_edge(half_edge), - &core.layers.geometry.of_surface(surface), + surface, ) .approx_with_cache( tolerance,