From 9e18066ec2a5614c05e5035189231bf6051958a7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:43:11 +0100 Subject: [PATCH 01/15] Convert `HalfEdgeBuilder` into struct --- .../fj-kernel/src/algorithms/approx/edge.rs | 6 +- crates/fj-kernel/src/algorithms/sweep/edge.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 4 +- crates/fj-kernel/src/builder/edge.rs | 56 +++++-------------- crates/fj-operations/src/sketch.rs | 9 +-- 5 files changed, 25 insertions(+), 52 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 80e038c42..fac854ea6 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -267,7 +267,7 @@ mod tests { builder::{CycleBuilder, HalfEdgeBuilder}, geometry::{curve::GlobalPath, surface::SurfaceGeometry}, insert::Insert, - objects::{HalfEdge, Surface}, + objects::Surface, partial::{PartialCycle, PartialObject}, services::Services, }; @@ -332,7 +332,7 @@ mod tests { v: [0., 0., 1.].into(), }) .insert(&mut services.objects); - let half_edge = HalfEdge::make_line_segment( + let half_edge = HalfEdgeBuilder::make_line_segment( [[0., 1.], [TAU, 1.]], Some(range.boundary), None, @@ -362,7 +362,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = HalfEdge::make_circle(1., &mut services.objects); + let half_edge = HalfEdgeBuilder::make_circle(1., &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 bbcdc4961..5fc50e438 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -88,7 +88,7 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { .zip_ext(vertices) .zip_ext(global_edges) .map(|((((boundary, start), end), start_vertex), global_edge)| { - let half_edge = HalfEdge::make_line_segment( + let half_edge = HalfEdgeBuilder::make_line_segment( [start, end], Some(boundary), Some(start_vertex), diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 77e7bff35..2a5e79361 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -63,7 +63,7 @@ impl CycleBuilder for PartialCycle { P: Clone + Into>, { points.map_with_next(|start, end| { - let half_edge = HalfEdge::make_line_segment( + let half_edge = HalfEdgeBuilder::make_line_segment( [start, end], None, None, @@ -86,7 +86,7 @@ impl CycleBuilder for PartialCycle { O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, { edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { - let half_edge = HalfEdge::make_half_edge( + let half_edge = HalfEdgeBuilder::make_half_edge( curve, boundary, Some(prev.start_vertex().clone()), diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 1ac9e6bdc..0c8391b93 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -10,46 +10,11 @@ use crate::{ }; /// Builder API for [`HalfEdge`] -pub trait HalfEdgeBuilder { - /// Create a circle - fn make_circle( - radius: impl Into, - objects: &mut Service, - ) -> Handle; - - /// Create an arc - /// - /// # Panics - /// - /// Panics if the given angle is not within the range (-2pi, 2pi) radians. - fn make_arc( - start: impl Into>, - end: impl Into>, - angle_rad: impl Into, - objects: &mut Service, - ) -> Handle; - - /// Create a line segment - fn make_line_segment( - points_surface: [impl Into>; 2], - boundary: Option<[Point<1>; 2]>, - start_vertex: Option>, - global_form: Option>, - objects: &mut Service, - ) -> Handle; - - /// Create a half-edge - fn make_half_edge( - curve: Curve, - boundary: [Point<1>; 2], - start_vertex: Option>, - global_form: Option>, - objects: &mut Service, - ) -> Handle; -} +pub struct HalfEdgeBuilder {} -impl HalfEdgeBuilder for HalfEdge { - fn make_circle( +impl HalfEdgeBuilder { + /// Create a circle + pub fn make_circle( radius: impl Into, objects: &mut Service, ) -> Handle { @@ -60,7 +25,12 @@ impl HalfEdgeBuilder for HalfEdge { Self::make_half_edge(curve, boundary, None, None, objects) } - fn make_arc( + /// Create an arc + /// + /// # Panics + /// + /// Panics if the given angle is not within the range (-2pi, 2pi) radians. + pub fn make_arc( start: impl Into>, end: impl Into>, angle_rad: impl Into, @@ -81,7 +51,8 @@ impl HalfEdgeBuilder for HalfEdge { Self::make_half_edge(curve, boundary, None, None, objects) } - fn make_line_segment( + /// Create a line segment + pub fn make_line_segment( points_surface: [impl Into>; 2], boundary: Option<[Point<1>; 2]>, start_vertex: Option>, @@ -103,7 +74,8 @@ impl HalfEdgeBuilder for HalfEdge { ) } - fn make_half_edge( + /// Create a half-edge + pub fn make_half_edge( curve: Curve, boundary: [Point<1>; 2], start_vertex: Option>, diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index c84cbc5fd..e889bd983 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -4,7 +4,7 @@ use fj_interop::{debug::DebugInfo, mesh::Color}; use fj_kernel::{ builder::{CycleBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{HalfEdge, Objects, Sketch}, + objects::{Objects, Sketch}, partial::{ Partial, PartialCycle, PartialFace, PartialObject, PartialSketch, }, @@ -27,7 +27,8 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { - let half_edge = HalfEdge::make_circle(circle.radius(), objects); + let half_edge = + HalfEdgeBuilder::make_circle(circle.radius(), objects); let exterior = { let mut cycle = PartialCycle::new(objects); cycle.half_edges.push(half_edge); @@ -63,7 +64,7 @@ impl Shape for fj::Sketch { for ((start, route), (end, _)) in segments { let half_edge = match route { fj::SketchSegmentRoute::Direct => { - HalfEdge::make_line_segment( + HalfEdgeBuilder::make_line_segment( [start, end], None, None, @@ -72,7 +73,7 @@ impl Shape for fj::Sketch { ) } fj::SketchSegmentRoute::Arc { angle } => { - HalfEdge::make_arc( + HalfEdgeBuilder::make_arc( start, end, angle.rad(), From a9b96d1bb3aedba0da8ffb18105dec51dfaf4aef Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:44:01 +0100 Subject: [PATCH 02/15] Simplify method name to `HalfEdgeBuilder::circle` --- crates/fj-kernel/src/algorithms/approx/edge.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 2 +- crates/fj-operations/src/sketch.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index fac854ea6..35cb482a5 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -362,7 +362,7 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = HalfEdgeBuilder::make_circle(1., &mut services.objects); + let half_edge = HalfEdgeBuilder::circle(1., &mut services.objects); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 0c8391b93..03ef67eb5 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -14,7 +14,7 @@ pub struct HalfEdgeBuilder {} impl HalfEdgeBuilder { /// Create a circle - pub fn make_circle( + pub fn circle( radius: impl Into, objects: &mut Service, ) -> Handle { diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index e889bd983..e8c703256 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -28,7 +28,7 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { let half_edge = - HalfEdgeBuilder::make_circle(circle.radius(), objects); + HalfEdgeBuilder::circle(circle.radius(), objects); let exterior = { let mut cycle = PartialCycle::new(objects); cycle.half_edges.push(half_edge); From 9e7c0dcfb2438dfbafd1431df374b91449ac000a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:44:48 +0100 Subject: [PATCH 03/15] Simplify method name to `HalfEdgeBuilder::arc` --- crates/fj-kernel/src/builder/edge.rs | 2 +- crates/fj-operations/src/sketch.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 03ef67eb5..93f518946 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -30,7 +30,7 @@ impl HalfEdgeBuilder { /// # Panics /// /// Panics if the given angle is not within the range (-2pi, 2pi) radians. - pub fn make_arc( + pub fn arc( start: impl Into>, end: impl Into>, angle_rad: impl Into, diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index e8c703256..a91fbed16 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -73,7 +73,7 @@ impl Shape for fj::Sketch { ) } fj::SketchSegmentRoute::Arc { angle } => { - HalfEdgeBuilder::make_arc( + HalfEdgeBuilder::arc( start, end, angle.rad(), From f2d403adc37a85d82ff340d7c80482dd01eb09f4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:45:26 +0100 Subject: [PATCH 04/15] Move method to establish alphabetical ordering --- crates/fj-kernel/src/builder/edge.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 93f518946..96bd6e0f7 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -13,18 +13,6 @@ use crate::{ pub struct HalfEdgeBuilder {} impl HalfEdgeBuilder { - /// Create a circle - pub fn circle( - radius: impl Into, - objects: &mut Service, - ) -> Handle { - let curve = Curve::circle_from_radius(radius); - let boundary = - [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - - Self::make_half_edge(curve, boundary, None, None, objects) - } - /// Create an arc /// /// # Panics @@ -51,6 +39,18 @@ impl HalfEdgeBuilder { Self::make_half_edge(curve, boundary, None, None, objects) } + /// Create a circle + pub fn circle( + radius: impl Into, + objects: &mut Service, + ) -> Handle { + let curve = Curve::circle_from_radius(radius); + let boundary = + [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); + + Self::make_half_edge(curve, boundary, None, None, objects) + } + /// Create a line segment pub fn make_line_segment( points_surface: [impl Into>; 2], From d87f886f733e81f45277112b29eb71347d5f9ef8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:46:14 +0100 Subject: [PATCH 05/15] Simplify name to `HalfEdgeBuilder::line_segment` --- crates/fj-kernel/src/algorithms/approx/edge.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/edge.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 2 +- crates/fj-operations/src/sketch.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 35cb482a5..95d8cddb4 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -332,7 +332,7 @@ mod tests { v: [0., 0., 1.].into(), }) .insert(&mut services.objects); - let half_edge = HalfEdgeBuilder::make_line_segment( + let half_edge = HalfEdgeBuilder::line_segment( [[0., 1.], [TAU, 1.]], Some(range.boundary), None, diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 5fc50e438..5ce2e7020 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -88,7 +88,7 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { .zip_ext(vertices) .zip_ext(global_edges) .map(|((((boundary, start), end), start_vertex), global_edge)| { - let half_edge = HalfEdgeBuilder::make_line_segment( + let half_edge = HalfEdgeBuilder::line_segment( [start, end], Some(boundary), Some(start_vertex), diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 2a5e79361..4cebc67bc 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -63,7 +63,7 @@ impl CycleBuilder for PartialCycle { P: Clone + Into>, { points.map_with_next(|start, end| { - let half_edge = HalfEdgeBuilder::make_line_segment( + let half_edge = HalfEdgeBuilder::line_segment( [start, end], None, None, diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 96bd6e0f7..c246e8d87 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -52,7 +52,7 @@ impl HalfEdgeBuilder { } /// Create a line segment - pub fn make_line_segment( + pub fn line_segment( points_surface: [impl Into>; 2], boundary: Option<[Point<1>; 2]>, start_vertex: Option>, diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index a91fbed16..2961fe065 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -64,7 +64,7 @@ impl Shape for fj::Sketch { for ((start, route), (end, _)) in segments { let half_edge = match route { fj::SketchSegmentRoute::Direct => { - HalfEdgeBuilder::make_line_segment( + HalfEdgeBuilder::line_segment( [start, end], None, None, From cf81d2f3db5e830600010ffc5dadfe97244bc4ac Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:47:18 +0100 Subject: [PATCH 06/15] Simplify method name to `HalfEdgeBuilder::build` It doesn't quite fit right now, but it will fit once I finish refactoring the API. --- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 4cebc67bc..8490659c2 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -86,7 +86,7 @@ impl CycleBuilder for PartialCycle { O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, { edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { - let half_edge = HalfEdgeBuilder::make_half_edge( + let half_edge = HalfEdgeBuilder::build( curve, boundary, Some(prev.start_vertex().clone()), diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index c246e8d87..1d0c109b2 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -36,7 +36,7 @@ impl HalfEdgeBuilder { let boundary = [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); - Self::make_half_edge(curve, boundary, None, None, objects) + Self::build(curve, boundary, None, None, objects) } /// Create a circle @@ -48,7 +48,7 @@ impl HalfEdgeBuilder { let boundary = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - Self::make_half_edge(curve, boundary, None, None, objects) + Self::build(curve, boundary, None, None, objects) } /// Create a line segment @@ -65,17 +65,11 @@ impl HalfEdgeBuilder { boundary.zip_ext(points_surface), ); - Self::make_half_edge( - curve, - boundary, - start_vertex, - global_form, - objects, - ) + Self::build(curve, boundary, start_vertex, global_form, objects) } /// Create a half-edge - pub fn make_half_edge( + pub fn build( curve: Curve, boundary: [Point<1>; 2], start_vertex: Option>, From 2f6fbb37092726a256548711fb0d3b42d092c9b2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:55:16 +0100 Subject: [PATCH 07/15] Separate actual build step in `HalfEdgeBuilder` --- .../fj-kernel/src/algorithms/approx/edge.rs | 6 ++- crates/fj-kernel/src/algorithms/sweep/edge.rs | 5 +++ crates/fj-kernel/src/builder/cycle.rs | 7 ++-- crates/fj-kernel/src/builder/edge.rs | 40 ++++++++++--------- crates/fj-operations/src/sketch.rs | 4 +- 5 files changed, 37 insertions(+), 25 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 95d8cddb4..5ab5ce028 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -338,7 +338,8 @@ mod tests { None, None, &mut services.objects, - ); + ) + .build(None, None, &mut services.objects); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); @@ -362,7 +363,8 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = HalfEdgeBuilder::circle(1., &mut services.objects); + let half_edge = HalfEdgeBuilder::circle(1., &mut services.objects) + .build(None, None, &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 5ce2e7020..46eb20744 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -91,6 +91,11 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { let half_edge = HalfEdgeBuilder::line_segment( [start, end], Some(boundary), + None, + None, + objects, + ) + .build( Some(start_vertex), global_edge, objects, diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 8490659c2..6390abb9e 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -69,7 +69,8 @@ impl CycleBuilder for PartialCycle { None, None, objects, - ); + ) + .build(None, None, objects); self.add_half_edge(half_edge.clone()); @@ -86,9 +87,7 @@ impl CycleBuilder for PartialCycle { O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, { edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { - let half_edge = HalfEdgeBuilder::build( - curve, - boundary, + let half_edge = HalfEdgeBuilder::new(curve, boundary).build( Some(prev.start_vertex().clone()), None, objects, diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 1d0c109b2..377975408 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -10,9 +10,17 @@ use crate::{ }; /// Builder API for [`HalfEdge`] -pub struct HalfEdgeBuilder {} +pub struct HalfEdgeBuilder { + curve: Curve, + boundary: [Point<1>; 2], +} impl HalfEdgeBuilder { + /// Create an instance of `HalfEdgeBuilder` + pub fn new(curve: Curve, boundary: [Point<1>; 2]) -> Self { + Self { curve, boundary } + } + /// Create an arc /// /// # Panics @@ -22,8 +30,8 @@ impl HalfEdgeBuilder { start: impl Into>, end: impl Into>, angle_rad: impl Into, - objects: &mut Service, - ) -> Handle { + _: &mut Service, + ) -> Self { let angle_rad = angle_rad.into(); if angle_rad <= -Scalar::TAU || angle_rad >= Scalar::TAU { panic!("arc angle must be in the range (-2pi, 2pi) radians"); @@ -36,49 +44,45 @@ impl HalfEdgeBuilder { let boundary = [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); - Self::build(curve, boundary, None, None, objects) + Self { curve, boundary } } /// Create a circle - pub fn circle( - radius: impl Into, - objects: &mut Service, - ) -> Handle { + pub fn circle(radius: impl Into, _: &mut Service) -> Self { let curve = Curve::circle_from_radius(radius); let boundary = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - Self::build(curve, boundary, None, None, objects) + Self { curve, boundary } } /// Create a line segment pub fn line_segment( points_surface: [impl Into>; 2], boundary: Option<[Point<1>; 2]>, - start_vertex: Option>, - global_form: Option>, - objects: &mut Service, - ) -> Handle { + _: Option>, + _: Option>, + _: &mut Service, + ) -> Self { let boundary = boundary.unwrap_or_else(|| [[0.], [1.]].map(Point::from)); let curve = Curve::line_from_points_with_coords( boundary.zip_ext(points_surface), ); - Self::build(curve, boundary, start_vertex, global_form, objects) + Self { curve, boundary } } /// Create a half-edge pub fn build( - curve: Curve, - boundary: [Point<1>; 2], + self, start_vertex: Option>, global_form: Option>, objects: &mut Service, ) -> Handle { HalfEdge::new( - curve, - boundary, + self.curve, + self.boundary, start_vertex.unwrap_or_else(|| Vertex::new().insert(objects)), global_form.unwrap_or_else(|| GlobalEdge::new().insert(objects)), ) diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 2961fe065..a71fcfadb 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -28,7 +28,8 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { let half_edge = - HalfEdgeBuilder::circle(circle.radius(), objects); + HalfEdgeBuilder::circle(circle.radius(), objects) + .build(None, None, objects); let exterior = { let mut cycle = PartialCycle::new(objects); cycle.half_edges.push(half_edge); @@ -82,6 +83,7 @@ impl Shape for fj::Sketch { } }; + let half_edge = half_edge.build(None, None, objects); cycle.add_half_edge(half_edge); } From b640c856772efebc032c42ef9675b2fbb34582bf Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:56:25 +0100 Subject: [PATCH 08/15] Remove unused argument --- crates/fj-kernel/src/builder/edge.rs | 1 - crates/fj-operations/src/sketch.rs | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 377975408..737c61e82 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -30,7 +30,6 @@ impl HalfEdgeBuilder { start: impl Into>, end: impl Into>, angle_rad: impl Into, - _: &mut Service, ) -> Self { let angle_rad = angle_rad.into(); if angle_rad <= -Scalar::TAU || angle_rad >= Scalar::TAU { diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index a71fcfadb..8c76bf6c2 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -74,12 +74,7 @@ impl Shape for fj::Sketch { ) } fj::SketchSegmentRoute::Arc { angle } => { - HalfEdgeBuilder::arc( - start, - end, - angle.rad(), - objects, - ) + HalfEdgeBuilder::arc(start, end, angle.rad()) } }; From 00906c83d01edd935022e2d4f085581db543dae7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:57:21 +0100 Subject: [PATCH 09/15] Remove unused argument --- crates/fj-kernel/src/algorithms/approx/edge.rs | 7 +++++-- crates/fj-kernel/src/builder/edge.rs | 2 +- crates/fj-operations/src/sketch.rs | 5 ++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 5ab5ce028..287d65e63 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -363,8 +363,11 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = HalfEdgeBuilder::circle(1., &mut services.objects) - .build(None, None, &mut services.objects); + let half_edge = HalfEdgeBuilder::circle(1.).build( + None, + None, + &mut services.objects, + ); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 737c61e82..068443d9c 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -47,7 +47,7 @@ impl HalfEdgeBuilder { } /// Create a circle - pub fn circle(radius: impl Into, _: &mut Service) -> Self { + pub fn circle(radius: impl Into) -> Self { let curve = Curve::circle_from_radius(radius); let boundary = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 8c76bf6c2..53736c11b 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -27,9 +27,8 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { - let half_edge = - HalfEdgeBuilder::circle(circle.radius(), objects) - .build(None, None, objects); + let half_edge = HalfEdgeBuilder::circle(circle.radius()) + .build(None, None, objects); let exterior = { let mut cycle = PartialCycle::new(objects); cycle.half_edges.push(half_edge); From c1d3eae71958e73e2ac7ee3395f007a2c82229eb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 11:58:24 +0100 Subject: [PATCH 10/15] Remove unused arguments --- crates/fj-kernel/src/algorithms/approx/edge.rs | 3 --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 15 +++------------ crates/fj-kernel/src/builder/cycle.rs | 10 ++-------- crates/fj-kernel/src/builder/edge.rs | 3 --- crates/fj-operations/src/sketch.rs | 3 --- 5 files changed, 5 insertions(+), 29 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 287d65e63..5197c7dfe 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -335,9 +335,6 @@ mod tests { let half_edge = HalfEdgeBuilder::line_segment( [[0., 1.], [TAU, 1.]], Some(range.boundary), - None, - None, - &mut services.objects, ) .build(None, None, &mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 46eb20744..b9362a8c8 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -88,18 +88,9 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { .zip_ext(vertices) .zip_ext(global_edges) .map(|((((boundary, start), end), start_vertex), global_edge)| { - let half_edge = HalfEdgeBuilder::line_segment( - [start, end], - Some(boundary), - None, - None, - objects, - ) - .build( - Some(start_vertex), - global_edge, - objects, - ); + let half_edge = + HalfEdgeBuilder::line_segment([start, end], Some(boundary)) + .build(Some(start_vertex), global_edge, 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 6390abb9e..70ed16f94 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -63,14 +63,8 @@ impl CycleBuilder for PartialCycle { P: Clone + Into>, { points.map_with_next(|start, end| { - let half_edge = HalfEdgeBuilder::line_segment( - [start, end], - None, - None, - None, - objects, - ) - .build(None, None, objects); + let half_edge = HalfEdgeBuilder::line_segment([start, end], None) + .build(None, None, 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 068443d9c..2c57764ee 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -59,9 +59,6 @@ impl HalfEdgeBuilder { pub fn line_segment( points_surface: [impl Into>; 2], boundary: Option<[Point<1>; 2]>, - _: Option>, - _: Option>, - _: &mut Service, ) -> Self { let boundary = boundary.unwrap_or_else(|| [[0.], [1.]].map(Point::from)); diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 53736c11b..9200d0dc8 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -67,9 +67,6 @@ impl Shape for fj::Sketch { HalfEdgeBuilder::line_segment( [start, end], None, - None, - None, - objects, ) } fj::SketchSegmentRoute::Arc { angle } => { From b7f0919d7c12bd2b2e47bba972b2e3491669c83b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 12:00:48 +0100 Subject: [PATCH 11/15] Refactor code to prepare for follow-on change --- crates/fj-kernel/src/builder/edge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 2c57764ee..74cb85b5c 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -43,7 +43,7 @@ impl HalfEdgeBuilder { let boundary = [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); - Self { curve, boundary } + Self::new(curve, boundary) } /// Create a circle @@ -52,7 +52,7 @@ impl HalfEdgeBuilder { let boundary = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - Self { curve, boundary } + Self::new(curve, boundary) } /// Create a line segment @@ -66,7 +66,7 @@ impl HalfEdgeBuilder { boundary.zip_ext(points_surface), ); - Self { curve, boundary } + Self::new(curve, boundary) } /// Create a half-edge From a3b4a699dcedafeaabe58b0a895b0ed561413e54 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 12:11:38 +0100 Subject: [PATCH 12/15] Add `HalfEdgeBuilder::with_start_vertex` --- crates/fj-kernel/src/algorithms/approx/edge.rs | 9 +++------ crates/fj-kernel/src/algorithms/sweep/edge.rs | 3 ++- crates/fj-kernel/src/builder/cycle.rs | 10 ++++------ crates/fj-kernel/src/builder/edge.rs | 17 ++++++++++++++--- crates/fj-operations/src/sketch.rs | 4 ++-- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 5197c7dfe..5a9b9e38e 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -336,7 +336,7 @@ mod tests { [[0., 1.], [TAU, 1.]], Some(range.boundary), ) - .build(None, None, &mut services.objects); + .build(None, &mut services.objects); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); @@ -360,11 +360,8 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xz_plane(); - let half_edge = HalfEdgeBuilder::circle(1.).build( - None, - None, - &mut services.objects, - ); + let half_edge = + HalfEdgeBuilder::circle(1.).build(None, &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 b9362a8c8..6e3a1bbe4 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -90,7 +90,8 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { .map(|((((boundary, start), end), start_vertex), global_edge)| { let half_edge = HalfEdgeBuilder::line_segment([start, end], Some(boundary)) - .build(Some(start_vertex), global_edge, objects); + .with_start_vertex(start_vertex) + .build(global_edge, 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 70ed16f94..2443d941d 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -64,7 +64,7 @@ impl CycleBuilder for PartialCycle { { points.map_with_next(|start, end| { let half_edge = HalfEdgeBuilder::line_segment([start, end], None) - .build(None, None, objects); + .build(None, objects); self.add_half_edge(half_edge.clone()); @@ -81,11 +81,9 @@ impl CycleBuilder for PartialCycle { O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, { edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { - let half_edge = HalfEdgeBuilder::new(curve, boundary).build( - Some(prev.start_vertex().clone()), - None, - objects, - ); + let half_edge = HalfEdgeBuilder::new(curve, boundary) + .with_start_vertex(prev.start_vertex().clone()) + .build(None, 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 74cb85b5c..1739748a2 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -13,12 +13,17 @@ use crate::{ pub struct HalfEdgeBuilder { curve: Curve, boundary: [Point<1>; 2], + start_vertex: Option>, } impl HalfEdgeBuilder { /// Create an instance of `HalfEdgeBuilder` pub fn new(curve: Curve, boundary: [Point<1>; 2]) -> Self { - Self { curve, boundary } + Self { + curve, + boundary, + start_vertex: None, + } } /// Create an arc @@ -69,17 +74,23 @@ impl HalfEdgeBuilder { Self::new(curve, boundary) } + /// Build the half-edge with a specific start vertex + pub fn with_start_vertex(mut self, start_vertex: Handle) -> Self { + self.start_vertex = Some(start_vertex); + self + } + /// Create a half-edge pub fn build( self, - start_vertex: Option>, global_form: Option>, objects: &mut Service, ) -> Handle { HalfEdge::new( self.curve, self.boundary, - start_vertex.unwrap_or_else(|| Vertex::new().insert(objects)), + self.start_vertex + .unwrap_or_else(|| Vertex::new().insert(objects)), 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 9200d0dc8..46955495d 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -28,7 +28,7 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { let half_edge = HalfEdgeBuilder::circle(circle.radius()) - .build(None, None, objects); + .build(None, objects); let exterior = { let mut cycle = PartialCycle::new(objects); cycle.half_edges.push(half_edge); @@ -74,7 +74,7 @@ impl Shape for fj::Sketch { } }; - let half_edge = half_edge.build(None, None, objects); + let half_edge = half_edge.build(None, objects); cycle.add_half_edge(half_edge); } From 501f5709b85d6a0f6fa8f5d1211b621ec5925489 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 12:14:00 +0100 Subject: [PATCH 13/15] Refactor code to prepare for follow-on change --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 6e3a1bbe4..ce4fa4d22 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -88,10 +88,15 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { .zip_ext(vertices) .zip_ext(global_edges) .map(|((((boundary, start), end), start_vertex), global_edge)| { - let half_edge = - HalfEdgeBuilder::line_segment([start, end], Some(boundary)) - .with_start_vertex(start_vertex) - .build(global_edge, objects); + let half_edge = { + let builder = HalfEdgeBuilder::line_segment( + [start, end], + Some(boundary), + ) + .with_start_vertex(start_vertex); + + builder.build(global_edge, objects) + }; face.exterior.write().add_half_edge(half_edge.clone()); From 5c2fdde0fdab188b1e83ef9bd18a35c49fec5aeb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 12:15:56 +0100 Subject: [PATCH 14/15] Add `HalfEdgeBuilder::with_global_form` --- crates/fj-kernel/src/algorithms/approx/edge.rs | 4 ++-- crates/fj-kernel/src/algorithms/sweep/edge.rs | 8 +++++++- crates/fj-kernel/src/builder/cycle.rs | 4 ++-- crates/fj-kernel/src/builder/edge.rs | 17 +++++++++++------ crates/fj-operations/src/sketch.rs | 6 +++--- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/edge.rs b/crates/fj-kernel/src/algorithms/approx/edge.rs index 5a9b9e38e..97e30e50f 100644 --- a/crates/fj-kernel/src/algorithms/approx/edge.rs +++ b/crates/fj-kernel/src/algorithms/approx/edge.rs @@ -336,7 +336,7 @@ mod tests { [[0., 1.], [TAU, 1.]], Some(range.boundary), ) - .build(None, &mut services.objects); + .build(&mut services.objects); let tolerance = 1.; let approx = (&half_edge, surface.deref()).approx(tolerance); @@ -361,7 +361,7 @@ mod tests { let surface = services.objects.surfaces.xz_plane(); let half_edge = - HalfEdgeBuilder::circle(1.).build(None, &mut services.objects); + HalfEdgeBuilder::circle(1.).build(&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 ce4fa4d22..1558977dc 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -95,7 +95,13 @@ impl Sweep for (Handle, &Handle, &Surface, Color) { ) .with_start_vertex(start_vertex); - builder.build(global_edge, objects) + let builder = if let Some(global_edge) = global_edge { + builder.with_global_form(global_edge) + } else { + builder + }; + + builder.build(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 2443d941d..d71b9e565 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -64,7 +64,7 @@ impl CycleBuilder for PartialCycle { { points.map_with_next(|start, end| { let half_edge = HalfEdgeBuilder::line_segment([start, end], None) - .build(None, objects); + .build(objects); self.add_half_edge(half_edge.clone()); @@ -83,7 +83,7 @@ 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(None, objects); + .build(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 1739748a2..834c50e3f 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -14,6 +14,7 @@ pub struct HalfEdgeBuilder { curve: Curve, boundary: [Point<1>; 2], start_vertex: Option>, + global_form: Option>, } impl HalfEdgeBuilder { @@ -23,6 +24,7 @@ impl HalfEdgeBuilder { curve, boundary, start_vertex: None, + global_form: None, } } @@ -80,18 +82,21 @@ impl HalfEdgeBuilder { self } + /// Build the half-edge with a specific global form + pub fn with_global_form(mut self, global_form: Handle) -> Self { + self.global_form = Some(global_form); + self + } + /// Create a half-edge - pub fn build( - self, - global_form: Option>, - objects: &mut Service, - ) -> Handle { + pub fn build(self, objects: &mut Service) -> Handle { HalfEdge::new( self.curve, self.boundary, self.start_vertex .unwrap_or_else(|| Vertex::new().insert(objects)), - global_form.unwrap_or_else(|| GlobalEdge::new().insert(objects)), + 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 46955495d..4b1650180 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -27,8 +27,8 @@ impl Shape for fj::Sketch { let face = match self.chain() { fj::Chain::Circle(circle) => { - let half_edge = HalfEdgeBuilder::circle(circle.radius()) - .build(None, objects); + let half_edge = + HalfEdgeBuilder::circle(circle.radius()).build(objects); let exterior = { let mut cycle = PartialCycle::new(objects); cycle.half_edges.push(half_edge); @@ -74,7 +74,7 @@ impl Shape for fj::Sketch { } }; - let half_edge = half_edge.build(None, objects); + let half_edge = half_edge.build(objects); cycle.add_half_edge(half_edge); } From 92da422da6a9232b6f82d3b8f0e48af4d1b5e090 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 10 Mar 2023 12:18:56 +0100 Subject: [PATCH 15/15] 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); }