From 92da422da6a9232b6f82d3b8f0e48af4d1b5e090 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 12:18:56 +0100 Subject: [PATCH] Return `HalfEdge` from `HalfEdgeBuilder::build` This is less convenient right now, but it makes `HalfEdgeBuilder` more composable and future-proof. --- crates/fj-kernel/src/algorithms/approx/edge.rs | 8 +++++--- crates/fj-kernel/src/algorithms/sweep/edge.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 7 +++++-- crates/fj-kernel/src/builder/edge.rs | 3 +-- crates/fj-operations/src/sketch.rs | 8 +++++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 97e30e50f..b647b7da5 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -336,7 +336,8 @@ mod tests { [[0., 1.], [TAU, 1.]], Some(range.boundary), ) - .build(&mut services.objects); + .build(&mut services.objects) + .insert(&mut services.objects); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); @@ -360,8 +361,9 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = - HalfEdgeBuilder::circle(1.).build(&mut services.objects); + let half_edge = HalfEdgeBuilder::circle(1.) + .build(&mut services.objects) + .insert(&mut services.objects); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 1558977dc..656a9d6b3 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -101,7 +101,7 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { builder }; - builder.build(objects) + builder.build(objects).insert(objects) }; face.exterior.write().add_half_edge(half_edge.clone()); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index d71b9e565..9151c671c 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -2,6 +2,7 @@ use fj_math::Point; use crate::{ geometry::curve::Curve, + insert::Insert, objects::{HalfEdge, Objects}, partial::PartialCycle, services::Service, @@ -64,7 +65,8 @@ impl CycleBuilder for PartialCycle { { points.map_with_next(|start, end| { let half_edge = HalfEdgeBuilder::line_segment([start, end], None) - .build(objects); + .build(objects) + .insert(objects); self.add_half_edge(half_edge.clone()); @@ -83,7 +85,8 @@ impl CycleBuilder for PartialCycle { edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { let half_edge = HalfEdgeBuilder::new(curve, boundary) .with_start_vertex(prev.start_vertex().clone()) - .build(objects); + .build(objects) + .insert(objects); self.add_half_edge(half_edge.clone()); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 834c50e3f..943a48508 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -89,7 +89,7 @@ impl HalfEdgeBuilder { } /// Create a half-edge - pub fn build(self, objects: &mut Service) -> Handle { + pub fn build(self, objects: &mut Service) -> HalfEdge { HalfEdge::new( self.curve, self.boundary, @@ -98,6 +98,5 @@ impl HalfEdgeBuilder { self.global_form .unwrap_or_else(|| GlobalEdge::new().insert(objects)), ) - .insert(objects) } } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 4b1650180..aefee9fa8 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -27,8 +27,9 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { - let half_edge = - HalfEdgeBuilder::circle(circle.radius()).build(objects); + let half_edge = HalfEdgeBuilder::circle(circle.radius()) + .build(objects) + .insert(objects); let exterior = { let mut cycle = PartialCycle::new(objects); cycle.half_edges.push(half_edge); @@ -74,7 +75,8 @@ impl Shape for fj::Sketch { } }; - let half_edge = half_edge.build(objects); + let half_edge = + half_edge.build(objects).insert(objects); cycle.add_half_edge(half_edge); }