From e1121606baa84e4adb4bde1f725d81da4dc9ff62 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 15:30:37 +0100 Subject: [PATCH 01/25] Accept `HalfEdgeBuilder` in `Cycle::add_half_edge` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 6 ++---- crates/fj-kernel/src/builder/cycle.rs | 12 +++++------- crates/fj-kernel/src/validate/cycle.rs | 6 ++---- crates/fj-operations/src/sketch.rs | 1 - 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 372e942f3..aed925a5a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -85,13 +85,11 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { ) .with_start_vertex(start_vertex); - let builder = if let Some(global_edge) = global_edge { + if let Some(global_edge) = global_edge { builder.with_global_form(global_edge) } else { builder - }; - - builder.build(objects) + } }; let (updated, half_edge) = diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index f4ce6ba82..6e4785e8a 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -23,7 +23,7 @@ pub trait CycleBuilder: Sized { /// meaning its front and back vertices are the same. fn add_half_edge( self, - half_edge: HalfEdge, + half_edge: HalfEdgeBuilder, objects: &mut Service, ) -> (Self, Handle); @@ -55,10 +55,10 @@ pub trait CycleBuilder: Sized { impl CycleBuilder for Cycle { fn add_half_edge( self, - half_edge: HalfEdge, + half_edge: HalfEdgeBuilder, objects: &mut Service, ) -> (Self, Handle) { - let half_edge = half_edge.insert(objects); + let half_edge = half_edge.build(objects).insert(objects); let cycle = Cycle::new(self.half_edges().cloned().chain([half_edge.clone()])); (cycle, half_edge) @@ -74,8 +74,7 @@ impl CycleBuilder for Cycle { P: Clone + Into>, { let half_edges = points.map_with_next(|start, end| { - let half_edge = HalfEdgeBuilder::line_segment([start, end], None) - .build(objects); + let half_edge = HalfEdgeBuilder::line_segment([start, end], None); let (cycle, half_edge) = self.clone().add_half_edge(half_edge, objects); @@ -98,8 +97,7 @@ impl CycleBuilder for Cycle { let edges = edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { let half_edge = HalfEdgeBuilder::new(curve, boundary) - .with_start_vertex(prev.start_vertex().clone()) - .build(objects); + .with_start_vertex(prev.start_vertex().clone()); let (cycle, half_edge) = self.clone().add_half_edge(half_edge, objects); diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 0c0442038..2dc2c297a 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -115,11 +115,9 @@ mod tests { let disconnected = { let first = - HalfEdgeBuilder::line_segment([[0., 0.], [1., 0.]], None) - .build(&mut services.objects); + HalfEdgeBuilder::line_segment([[0., 0.], [1., 0.]], None); let second = - HalfEdgeBuilder::line_segment([[0., 0.], [1., 0.]], None) - .build(&mut services.objects); + HalfEdgeBuilder::line_segment([[0., 0.], [1., 0.]], None); Cycle::new([]) .add_half_edge(first, &mut services.objects) diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 5246fdc09..a1e9a11a4 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -68,7 +68,6 @@ impl Shape for fj::Sketch { } }; - let half_edge = half_edge.build(objects); cycle = cycle.add_half_edge(half_edge, objects).0; } From 374489ab2da974141c04dde210a750291c4ed531 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 15:31:43 +0100 Subject: [PATCH 02/25] Refactor code to make it more explicit --- crates/fj-operations/src/sketch.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index a1e9a11a4..e1d76f6f3 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -68,7 +68,9 @@ impl Shape for fj::Sketch { } }; - cycle = cycle.add_half_edge(half_edge, objects).0; + let (updated, _) = + cycle.add_half_edge(half_edge, objects); + cycle = updated; } cycle.insert(objects) From a3b769c3debab5c51dceca6395665edba4e25578 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 15:54:00 +0100 Subject: [PATCH 03/25] Remove unused return value --- .../src/algorithms/intersect/curve_face.rs | 18 +++-- .../src/algorithms/intersect/face_face.rs | 4 +- .../src/algorithms/intersect/face_point.rs | 72 +++++++++---------- .../src/algorithms/intersect/ray_face.rs | 63 ++++++++-------- .../src/algorithms/triangulate/mod.rs | 36 +++++----- crates/fj-kernel/src/builder/cycle.rs | 8 +-- crates/fj-kernel/src/validate/face.rs | 18 +++-- 7 files changed, 98 insertions(+), 121 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 9910f6440..a60f2725d 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -183,19 +183,17 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - exterior_points, - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + exterior_points, + &mut services.objects, + ); exterior.insert(&mut services.objects) }, vec![{ - let (interior, _) = Cycle::new([]) - .update_as_polygon_from_points( - interior_points, - &mut services.objects, - ); + let interior = Cycle::new([]).update_as_polygon_from_points( + interior_points, + &mut services.objects, + ); interior.insert(&mut services.objects) }], None, diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 24c426e3a..439fb02e9 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -90,7 +90,7 @@ mod tests { Face::new( surface, { - let (exterior, _) = Cycle::new([]) + let exterior = Cycle::new([]) .update_as_polygon_from_points( points, &mut services.objects, @@ -126,7 +126,7 @@ mod tests { Face::new( surface, { - let (exterior, _) = Cycle::new([]) + let exterior = Cycle::new([]) .update_as_polygon_from_points( points, &mut services.objects, diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 80c669b90..74ee154f5 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -151,11 +151,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[0., 0.], [1., 1.], [0., 2.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[0., 0.], [1., 1.], [0., 2.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -174,11 +173,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[0., 0.], [2., 1.], [0., 2.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[0., 0.], [2., 1.], [0., 2.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -200,11 +198,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[4., 2.], [0., 4.], [0., 0.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[4., 2.], [0., 4.], [0., 0.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -226,11 +223,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[0., 0.], [2., 1.], [3., 0.], [3., 4.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[0., 0.], [2., 1.], [3., 0.], [3., 4.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -252,11 +248,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[0., 0.], [2., 1.], [3., 1.], [0., 2.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[0., 0.], [2., 1.], [3., 1.], [0., 2.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -278,11 +273,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -304,11 +298,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[0., 0.], [2., 0.], [0., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[0., 0.], [2., 0.], [0., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -336,11 +329,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[0., 0.], [1., 0.], [0., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[0., 0.], [1., 0.], [0., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index 7cbeeb92a..dab106e16 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -166,11 +166,10 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -190,11 +189,10 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -217,11 +215,10 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -241,11 +238,10 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -273,11 +269,10 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -308,11 +303,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -334,11 +328,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index bf3c67ce2..fd570ab24 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -99,11 +99,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [a, b, c, d], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [a, b, c, d], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), @@ -144,19 +143,17 @@ mod tests { let face = Face::new( surface.clone(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [a, b, c, d], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [a, b, c, d], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, vec![{ - let (interior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [e, f, g, h], - &mut services.objects, - ); + let interior = Cycle::new([]).update_as_polygon_from_points( + [e, f, g, h], + &mut services.objects, + ); interior.insert(&mut services.objects) }], None, @@ -218,11 +215,10 @@ mod tests { let face = Face::new( surface.clone(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [a, b, c, d, e], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [a, b, c, d, e], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, Vec::new(), diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 6e4785e8a..d29cf9d95 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -32,7 +32,7 @@ pub trait CycleBuilder: Sized { self, points: O, objects: &mut Service, - ) -> (Self, O::SameSize>) + ) -> Self where O: ObjectArgument

, P: Clone + Into>; @@ -68,12 +68,12 @@ impl CycleBuilder for Cycle { mut self, points: O, objects: &mut Service, - ) -> (Self, O::SameSize>) + ) -> Self where O: ObjectArgument

, P: Clone + Into>, { - let half_edges = points.map_with_next(|start, end| { + points.map_with_next(|start, end| { let half_edge = HalfEdgeBuilder::line_segment([start, end], None); let (cycle, half_edge) = @@ -83,7 +83,7 @@ impl CycleBuilder for Cycle { half_edge }); - (self, half_edges) + self } fn connect_to_edges( diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 3201e9612..9f1e0d92a 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -86,19 +86,17 @@ mod tests { let valid = Face::new( services.objects.surfaces.xy_plane(), { - let (exterior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[0., 0.], [3., 0.], [0., 3.]], - &mut services.objects, - ); + let exterior = Cycle::new([]).update_as_polygon_from_points( + [[0., 0.], [3., 0.], [0., 3.]], + &mut services.objects, + ); exterior.insert(&mut services.objects) }, vec![{ - let (interior, _) = Cycle::new([]) - .update_as_polygon_from_points( - [[1., 1.], [1., 2.], [2., 1.]], - &mut services.objects, - ); + let interior = Cycle::new([]).update_as_polygon_from_points( + [[1., 1.], [1., 2.], [2., 1.]], + &mut services.objects, + ); interior.insert(&mut services.objects) }], None, From 44f504a58d67a618f3bb6126aaa5c82b733697fa Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 16:13:33 +0100 Subject: [PATCH 04/25] Replace use of `ObjectArgument` --- crates/fj-kernel/src/builder/cycle.rs | 37 +++++++++++++++------------ 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index d29cf9d95..a47cd2da9 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -1,4 +1,5 @@ use fj_math::Point; +use itertools::Itertools; use crate::{ geometry::curve::Curve, @@ -28,14 +29,15 @@ pub trait CycleBuilder: Sized { ) -> (Self, Handle); /// Update cycle as a polygon from the provided points - fn update_as_polygon_from_points( + fn update_as_polygon_from_points( self, - points: O, + points: Ps, objects: &mut Service, ) -> Self where - O: ObjectArgument

, - P: Clone + Into>; + P: Into>, + Ps: IntoIterator, + Ps::IntoIter: Clone + ExactSizeIterator; /// Connect the cycles to the provided half-edges /// @@ -64,24 +66,27 @@ impl CycleBuilder for Cycle { (cycle, half_edge) } - fn update_as_polygon_from_points( + fn update_as_polygon_from_points( mut self, - points: O, + points: Ps, objects: &mut Service, ) -> Self where - O: ObjectArgument

, - P: Clone + Into>, + P: Into>, + Ps: IntoIterator, + Ps::IntoIter: Clone + ExactSizeIterator, { - points.map_with_next(|start, end| { - let half_edge = HalfEdgeBuilder::line_segment([start, end], None); + points + .into_iter() + .map(Into::into) + .circular_tuple_windows() + .for_each(|(start, end)| { + let half_edge = + HalfEdgeBuilder::line_segment([start, end], None); - let (cycle, half_edge) = - self.clone().add_half_edge(half_edge, objects); - self = cycle; - - half_edge - }); + let (cycle, _) = self.clone().add_half_edge(half_edge, objects); + self = cycle; + }); self } From 096e8c658157d312bbcd8c135dc6c1dd43995355 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 16:20:30 +0100 Subject: [PATCH 05/25] Add `CycleBuilder2` --- crates/fj-kernel/src/builder/cycle.rs | 35 +++++++++++++++++++++++++++ crates/fj-kernel/src/builder/mod.rs | 5 +++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index a47cd2da9..740288678 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -114,3 +114,38 @@ impl CycleBuilder for Cycle { (self, edges) } } + +/// Builder API for [`Cycle`] +pub struct CycleBuilder2 { + half_edges: Vec, +} + +impl CycleBuilder2 { + /// Create a polygon + pub fn polygon(points: Ps) -> Self + where + P: Into>, + Ps: IntoIterator, + Ps::IntoIter: Clone + ExactSizeIterator, + { + let half_edges = points + .into_iter() + .map(Into::into) + .circular_tuple_windows() + .map(|(start, end)| { + HalfEdgeBuilder::line_segment([start, end], None) + }) + .collect(); + + Self { half_edges } + } + + /// Build the cycle + pub fn build(self, objects: &mut Service) -> Cycle { + let half_edges = self + .half_edges + .into_iter() + .map(|half_edge| half_edge.build(objects).insert(objects)); + Cycle::new(half_edges) + } +} diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index bef39d519..7e3d59d7c 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -6,7 +6,10 @@ mod edge; use std::array; -pub use self::{cycle::CycleBuilder, edge::HalfEdgeBuilder}; +pub use self::{ + cycle::{CycleBuilder, CycleBuilder2}, + edge::HalfEdgeBuilder, +}; /// Pass objects to a builder method /// From 6dfe07aaf89832711e36b0f658e4cd71ffd686b6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 16:21:40 +0100 Subject: [PATCH 06/25] Update doc comment --- crates/fj-kernel/src/builder/edge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 943a48508..46e106423 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -88,7 +88,7 @@ impl HalfEdgeBuilder { self } - /// Create a half-edge + /// Build the half-edge pub fn build(self, objects: &mut Service) -> HalfEdge { HalfEdge::new( self.curve, From 2ef8ed01032eadb084122b093bb161e03882478c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 16:23:36 +0100 Subject: [PATCH 07/25] Replace uses of `CycleBuilder` with `CycleBuilder2` --- .../src/algorithms/intersect/curve_face.rs | 23 ++--- .../src/algorithms/intersect/face_face.rs | 25 ++--- .../src/algorithms/intersect/face_point.rs | 74 +++++++-------- .../src/algorithms/intersect/ray_face.rs | 95 +++++++++++-------- .../src/algorithms/triangulate/mod.rs | 36 +++---- crates/fj-kernel/src/validate/cycle.rs | 11 +-- crates/fj-kernel/src/validate/face.rs | 20 ++-- 7 files changed, 132 insertions(+), 152 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index a60f2725d..ac5ae7ac4 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -150,11 +150,8 @@ where #[cfg(test)] mod tests { use crate::{ - builder::CycleBuilder, - geometry::curve::Curve, - insert::Insert, - objects::{Cycle, Face}, - services::Services, + builder::CycleBuilder2, geometry::curve::Curve, insert::Insert, + objects::Face, services::Services, }; use super::CurveFaceIntersection; @@ -183,18 +180,14 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - exterior_points, - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon(exterior_points) + .build(&mut services.objects) + .insert(&mut services.objects) }, vec![{ - let interior = Cycle::new([]).update_as_polygon_from_points( - interior_points, - &mut services.objects, - ); - interior.insert(&mut services.objects) + CycleBuilder2::polygon(interior_points) + .build(&mut services.objects) + .insert(&mut services.objects) }], None, ); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 439fb02e9..2e2100f81 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -61,11 +61,8 @@ mod tests { use pretty_assertions::assert_eq; use crate::{ - algorithms::intersect::CurveFaceIntersection, - builder::CycleBuilder, - geometry::curve::Curve, - insert::Insert, - objects::{Cycle, Face}, + algorithms::intersect::CurveFaceIntersection, builder::CycleBuilder2, + geometry::curve::Curve, insert::Insert, objects::Face, services::Services, }; @@ -90,12 +87,9 @@ mod tests { Face::new( surface, { - let exterior = Cycle::new([]) - .update_as_polygon_from_points( - points, - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon(points) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -126,12 +120,9 @@ mod tests { Face::new( surface, { - let exterior = Cycle::new([]) - .update_as_polygon_from_points( - points, - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon(points) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 74ee154f5..4e3eaf5c0 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -138,9 +138,9 @@ mod tests { use crate::{ algorithms::intersect::{face_point::FacePointIntersection, Intersect}, - builder::CycleBuilder, + builder::CycleBuilder2, insert::Insert, - objects::{Cycle, Face}, + objects::Face, services::Services, }; @@ -151,11 +151,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[0., 0.], [1., 1.], [0., 2.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([[0., 0.], [1., 1.], [0., 2.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -173,11 +171,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[0., 0.], [2., 1.], [0., 2.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([[0., 0.], [2., 1.], [0., 2.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -198,11 +194,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[4., 2.], [0., 4.], [0., 0.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([[4., 2.], [0., 4.], [0., 0.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -223,11 +217,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[0., 0.], [2., 1.], [3., 0.], [3., 4.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([[0., 0.], [2., 1.], [3., 0.], [3., 4.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -248,11 +240,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[0., 0.], [2., 1.], [3., 1.], [0., 2.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([[0., 0.], [2., 1.], [3., 1.], [0., 2.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -273,11 +263,15 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([ + [0., 0.], + [2., 1.], + [3., 1.], + [4., 0.], + [4., 5.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -298,11 +292,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[0., 0.], [2., 0.], [0., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([[0., 0.], [2., 0.], [0., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -329,11 +321,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[0., 0.], [1., 0.], [0., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([[0., 0.], [1., 0.], [0., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index dab106e16..7b0d5df2b 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -151,9 +151,9 @@ mod tests { }, transform::TransformObject, }, - builder::CycleBuilder, + builder::CycleBuilder2, insert::Insert, - objects::{Cycle, Face}, + objects::Face, services::Services, }; @@ -166,11 +166,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -189,11 +192,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -215,11 +221,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -238,11 +247,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -269,11 +281,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -303,11 +318,14 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -328,11 +346,14 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index fd570ab24..732f5a27d 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -79,9 +79,9 @@ mod tests { use crate::{ algorithms::approx::{Approx, Tolerance}, - builder::CycleBuilder, + builder::CycleBuilder2, insert::Insert, - objects::{Cycle, Face}, + objects::Face, services::Services, }; @@ -99,11 +99,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [a, b, c, d], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([a, b, c, d]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, @@ -143,18 +141,14 @@ mod tests { let face = Face::new( surface.clone(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [a, b, c, d], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([a, b, c, d]) + .build(&mut services.objects) + .insert(&mut services.objects) }, vec![{ - let interior = Cycle::new([]).update_as_polygon_from_points( - [e, f, g, h], - &mut services.objects, - ); - interior.insert(&mut services.objects) + CycleBuilder2::polygon([e, f, g, h]) + .build(&mut services.objects) + .insert(&mut services.objects) }], None, ); @@ -215,11 +209,9 @@ mod tests { let face = Face::new( surface.clone(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [a, b, c, d, e], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([a, b, c, d, e]) + .build(&mut services.objects) + .insert(&mut services.objects) }, Vec::new(), None, diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 2dc2c297a..e97fa709d 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -94,7 +94,7 @@ impl CycleValidationError { mod tests { use crate::{ - builder::{CycleBuilder, HalfEdgeBuilder}, + builder::{CycleBuilder, CycleBuilder2, HalfEdgeBuilder}, objects::Cycle, services::Services, validate::{cycle::CycleValidationError, Validate, ValidationError}, @@ -104,12 +104,9 @@ mod tests { fn half_edges_connected() -> anyhow::Result<()> { let mut services = Services::new(); - let valid = Cycle::new([]) - .update_as_polygon_from_points( - [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]], - &mut services.objects, - ) - .0; + let valid = + CycleBuilder2::polygon([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]) + .build(&mut services.objects); valid.validate_and_return_first_error()?; diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 9f1e0d92a..c8700d440 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -72,9 +72,9 @@ impl FaceValidationError { mod tests { use crate::{ algorithms::reverse::Reverse, - builder::CycleBuilder, + builder::CycleBuilder2, insert::Insert, - objects::{Cycle, Face}, + objects::Face, services::Services, validate::{FaceValidationError, Validate, ValidationError}, }; @@ -86,18 +86,14 @@ mod tests { let valid = Face::new( services.objects.surfaces.xy_plane(), { - let exterior = Cycle::new([]).update_as_polygon_from_points( - [[0., 0.], [3., 0.], [0., 3.]], - &mut services.objects, - ); - exterior.insert(&mut services.objects) + CycleBuilder2::polygon([[0., 0.], [3., 0.], [0., 3.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }, vec![{ - let interior = Cycle::new([]).update_as_polygon_from_points( - [[1., 1.], [1., 2.], [2., 1.]], - &mut services.objects, - ); - interior.insert(&mut services.objects) + CycleBuilder2::polygon([[1., 1.], [1., 2.], [2., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects) }], None, ); From 8e7c1008229247019ac5df19ca0ab633a000235a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 16:57:05 +0100 Subject: [PATCH 08/25] Remove unused builder method --- crates/fj-kernel/src/builder/cycle.rs | 36 --------------------------- 1 file changed, 36 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 740288678..2c7ea23f7 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -28,17 +28,6 @@ pub trait CycleBuilder: Sized { objects: &mut Service, ) -> (Self, Handle); - /// Update cycle as a polygon from the provided points - fn update_as_polygon_from_points( - self, - points: Ps, - objects: &mut Service, - ) -> Self - where - P: Into>, - Ps: IntoIterator, - Ps::IntoIter: Clone + ExactSizeIterator; - /// Connect the cycles to the provided half-edges /// /// Assumes that the provided half-edges, once translated into local @@ -66,31 +55,6 @@ impl CycleBuilder for Cycle { (cycle, half_edge) } - fn update_as_polygon_from_points( - mut self, - points: Ps, - objects: &mut Service, - ) -> Self - where - P: Into>, - Ps: IntoIterator, - Ps::IntoIter: Clone + ExactSizeIterator, - { - points - .into_iter() - .map(Into::into) - .circular_tuple_windows() - .for_each(|(start, end)| { - let half_edge = - HalfEdgeBuilder::line_segment([start, end], None); - - let (cycle, _) = self.clone().add_half_edge(half_edge, objects); - self = cycle; - }); - - self - } - fn connect_to_edges( mut self, edges: O, From 67a9536188a2698bce83b122f39e5a0eb593b69d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 15 Mar 2023 17:00:55 +0100 Subject: [PATCH 09/25] Remove redundant blocks --- .../src/algorithms/intersect/curve_face.rs | 16 +-- .../src/algorithms/intersect/face_face.rs | 16 +-- .../src/algorithms/intersect/face_point.rs | 76 +++++------ .../src/algorithms/intersect/ray_face.rs | 126 ++++++++---------- .../src/algorithms/triangulate/mod.rs | 32 ++--- crates/fj-kernel/src/validate/face.rs | 16 +-- 6 files changed, 116 insertions(+), 166 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index ac5ae7ac4..e34138ea2 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -179,16 +179,12 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon(exterior_points) - .build(&mut services.objects) - .insert(&mut services.objects) - }, - vec![{ - CycleBuilder2::polygon(interior_points) - .build(&mut services.objects) - .insert(&mut services.objects) - }], + CycleBuilder2::polygon(exterior_points) + .build(&mut services.objects) + .insert(&mut services.objects), + vec![CycleBuilder2::polygon(interior_points) + .build(&mut services.objects) + .insert(&mut services.objects)], None, ); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 2e2100f81..e3115b70d 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -86,11 +86,9 @@ mod tests { .map(|surface| { Face::new( surface, - { - CycleBuilder2::polygon(points) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon(points) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ) @@ -119,11 +117,9 @@ mod tests { let [a, b] = surfaces.clone().map(|surface| { Face::new( surface, - { - CycleBuilder2::polygon(points) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon(points) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ) diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 4e3eaf5c0..9dd227cc8 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -150,11 +150,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([[0., 0.], [1., 1.], [0., 2.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([[0., 0.], [1., 1.], [0., 2.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -170,11 +168,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([[0., 0.], [2., 1.], [0., 2.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([[0., 0.], [2., 1.], [0., 2.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -193,11 +189,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([[4., 2.], [0., 4.], [0., 0.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([[4., 2.], [0., 4.], [0., 0.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -216,11 +210,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([[0., 0.], [2., 1.], [3., 0.], [3., 4.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([[0., 0.], [2., 1.], [3., 0.], [3., 4.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -239,11 +231,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([[0., 0.], [2., 1.], [3., 1.], [0., 2.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([[0., 0.], [2., 1.], [3., 1.], [0., 2.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -262,17 +252,15 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([ - [0., 0.], - [2., 1.], - [3., 1.], - [4., 0.], - [4., 5.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([ + [0., 0.], + [2., 1.], + [3., 1.], + [4., 0.], + [4., 5.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -291,11 +279,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([[0., 0.], [2., 0.], [0., 1.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([[0., 0.], [2., 0.], [0., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -320,11 +306,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([[0., 0.], [1., 0.], [0., 1.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([[0., 0.], [1., 0.], [0., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index 7b0d5df2b..faa2b6763 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -165,16 +165,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - { - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -191,16 +189,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - { - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -220,16 +216,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - { - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -246,16 +240,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - { - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -280,16 +272,14 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - { - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -317,16 +307,14 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -345,16 +333,14 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([ + [-1., -1.], + [1., -1.], + [1., 1.], + [-1., 1.], + ]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 732f5a27d..6b8f8f267 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -98,11 +98,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([a, b, c, d]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([a, b, c, d]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -140,16 +138,12 @@ mod tests { let face = Face::new( surface.clone(), - { - CycleBuilder2::polygon([a, b, c, d]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, - vec![{ - CycleBuilder2::polygon([e, f, g, h]) - .build(&mut services.objects) - .insert(&mut services.objects) - }], + CycleBuilder2::polygon([a, b, c, d]) + .build(&mut services.objects) + .insert(&mut services.objects), + vec![CycleBuilder2::polygon([e, f, g, h]) + .build(&mut services.objects) + .insert(&mut services.objects)], None, ); @@ -208,11 +202,9 @@ mod tests { let face = Face::new( surface.clone(), - { - CycleBuilder2::polygon([a, b, c, d, e]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, + CycleBuilder2::polygon([a, b, c, d, e]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index c8700d440..6cfd2ff29 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -85,16 +85,12 @@ mod tests { let valid = Face::new( services.objects.surfaces.xy_plane(), - { - CycleBuilder2::polygon([[0., 0.], [3., 0.], [0., 3.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }, - vec![{ - CycleBuilder2::polygon([[1., 1.], [1., 2.], [2., 1.]]) - .build(&mut services.objects) - .insert(&mut services.objects) - }], + CycleBuilder2::polygon([[0., 0.], [3., 0.], [0., 3.]]) + .build(&mut services.objects) + .insert(&mut services.objects), + vec![CycleBuilder2::polygon([[1., 1.], [1., 2.], [2., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects)], None, ); let invalid = { From 18238c1b1a833a0f4f7bfe845fda0c5564406fd6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:06:47 +0100 Subject: [PATCH 10/25] Remove unused return value --- crates/fj-kernel/src/algorithms/sweep/face.rs | 3 +-- crates/fj-kernel/src/builder/cycle.rs | 23 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 00e7fbfe0..07f25df1c 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -82,8 +82,7 @@ impl Sweep for Handle { )); } - let (top_cycle, _) = - Cycle::new([]).connect_to_edges(top_edges, objects); + let top_cycle = Cycle::new([]).connect_to_edges(top_edges, objects); if i == 0 { exterior = Some(top_cycle.insert(objects)); diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 2c7ea23f7..3c7d8d825 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -38,7 +38,7 @@ pub trait CycleBuilder: Sized { self, edges: O, objects: &mut Service, - ) -> (Self, O::SameSize>) + ) -> Self where O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>; } @@ -59,23 +59,22 @@ impl CycleBuilder for Cycle { mut self, edges: O, objects: &mut Service, - ) -> (Self, O::SameSize>) + ) -> Self where O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, { - let edges = - edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { - let half_edge = HalfEdgeBuilder::new(curve, boundary) - .with_start_vertex(prev.start_vertex().clone()); + edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { + let half_edge = HalfEdgeBuilder::new(curve, boundary) + .with_start_vertex(prev.start_vertex().clone()); - let (cycle, half_edge) = - self.clone().add_half_edge(half_edge, objects); - self = cycle; + let (cycle, half_edge) = + self.clone().add_half_edge(half_edge, objects); + self = cycle; - half_edge - }); + half_edge + }); - (self, edges) + self } } From d3a61cae277a8cca88be14394974ea579aab2529 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:09:06 +0100 Subject: [PATCH 11/25] Remove redundant variable --- crates/fj-kernel/src/builder/cycle.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 3c7d8d825..2ac7f9808 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -67,11 +67,8 @@ impl CycleBuilder for Cycle { let half_edge = HalfEdgeBuilder::new(curve, boundary) .with_start_vertex(prev.start_vertex().clone()); - let (cycle, half_edge) = - self.clone().add_half_edge(half_edge, objects); + let (cycle, _) = self.clone().add_half_edge(half_edge, objects); self = cycle; - - half_edge }); self From 30c10531796c83f503d2f077ac790fc0d10e1e20 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:11:21 +0100 Subject: [PATCH 12/25] Update name of type parameter --- crates/fj-kernel/src/builder/cycle.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 2ac7f9808..cae41a7a0 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -34,13 +34,13 @@ pub trait CycleBuilder: Sized { /// equivalents of this cycle, form a cycle themselves. /// /// Returns the local equivalents of the provided half-edges. - fn connect_to_edges( + fn connect_to_edges( self, - edges: O, + edges: Es, objects: &mut Service, ) -> Self where - O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>; + Es: ObjectArgument<(Handle, Curve, [Point<1>; 2])>; } impl CycleBuilder for Cycle { @@ -55,13 +55,13 @@ impl CycleBuilder for Cycle { (cycle, half_edge) } - fn connect_to_edges( + fn connect_to_edges( mut self, - edges: O, + edges: Es, objects: &mut Service, ) -> Self where - O: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, + Es: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, { edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { let half_edge = HalfEdgeBuilder::new(curve, boundary) From decb4cc3bcb996ed2b593214b646600080d593ee Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:13:34 +0100 Subject: [PATCH 13/25] Refactor code to prepare for follow-on change --- crates/fj-kernel/src/builder/cycle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index cae41a7a0..4eabd0107 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -63,7 +63,7 @@ impl CycleBuilder for Cycle { where Es: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, { - edges.map_with_prev(|(_, curve, boundary), (prev, _, _)| { + edges.map_with_next(|(prev, _, _), (_, curve, boundary)| { let half_edge = HalfEdgeBuilder::new(curve, boundary) .with_start_vertex(prev.start_vertex().clone()); From c5c47d12cc37be56d0981f3e3f18ac02d018c68d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:16:59 +0100 Subject: [PATCH 14/25] Replace use of `ObjectArgument` --- crates/fj-kernel/src/builder/cycle.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 4eabd0107..76c1ac34f 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -9,7 +9,7 @@ use crate::{ storage::Handle, }; -use super::{HalfEdgeBuilder, ObjectArgument}; +use super::HalfEdgeBuilder; /// Builder API for [`Cycle`] pub trait CycleBuilder: Sized { @@ -40,7 +40,8 @@ pub trait CycleBuilder: Sized { objects: &mut Service, ) -> Self where - Es: ObjectArgument<(Handle, Curve, [Point<1>; 2])>; + Es: IntoIterator, Curve, [Point<1>; 2])>, + Es::IntoIter: Clone + ExactSizeIterator; } impl CycleBuilder for Cycle { @@ -61,15 +62,18 @@ impl CycleBuilder for Cycle { objects: &mut Service, ) -> Self where - Es: ObjectArgument<(Handle, Curve, [Point<1>; 2])>, + Es: IntoIterator, Curve, [Point<1>; 2])>, + Es::IntoIter: Clone + ExactSizeIterator, { - edges.map_with_next(|(prev, _, _), (_, curve, boundary)| { - let half_edge = HalfEdgeBuilder::new(curve, boundary) - .with_start_vertex(prev.start_vertex().clone()); + edges.into_iter().circular_tuple_windows().for_each( + |((prev, _, _), (_, curve, boundary))| { + let half_edge = HalfEdgeBuilder::new(curve, boundary) + .with_start_vertex(prev.start_vertex().clone()); - let (cycle, _) = self.clone().add_half_edge(half_edge, objects); - self = cycle; - }); + let (cycle, _) = self.clone().add_half_edge(half_edge, objects); + self = cycle; + }, + ); self } From 4d7b43d2bee2a1060cd8402079cfb386b7efa92b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:17:39 +0100 Subject: [PATCH 15/25] Remove unused `ObjectArgument` infrastructure --- crates/fj-kernel/src/builder/mod.rs | 203 ---------------------------- 1 file changed, 203 deletions(-) diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 7e3d59d7c..03e7f3487 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -4,210 +4,7 @@ mod cycle; mod edge; -use std::array; - pub use self::{ cycle::{CycleBuilder, CycleBuilder2}, edge::HalfEdgeBuilder, }; - -/// Pass objects to a builder method -/// -/// Many builder methods receive objects as arguments, and many builder -/// arguments return objects back, based on their input. In the general case, -/// the number of objects passed and returned is usually arbitrary, but many -/// callers pass a specific number of objects, and expect the same number of -/// objects back. -/// -/// This trait can be used to do exactly that. It is implemented for `Vec` and -/// arrays. When passing a `Vec`, a `Vec` is returned. When passing an array, an -/// array of the same size is returned. -pub trait ObjectArgument: IntoIterator { - /// The value returned, if the implementing type is passed on an argument - /// - /// The return value has the same length as the implementing type, but it is - /// not necessarily of the same type. For this reason, this associated type - /// is generic. - type SameSize; - - /// A return value that has one more element than the argument - type SizePlusOne; - - /// Return the number of objects - fn num_objects(&self) -> usize; - - /// Create a return value by mapping the implementing type - fn map(self, f: F) -> Self::SameSize - where - F: FnMut(T) -> R; - - /// Create a return value by mapping the implementing type - /// - /// Provides access to the (circular) next item. - fn map_with_next(self, f: F) -> Self::SameSize - where - F: FnMut(T, T) -> R, - T: Clone; - - /// Create a return value by mapping the implementing type - /// - /// Provides access to the (circular) previous item. - fn map_with_prev(self, f: F) -> Self::SameSize - where - F: FnMut(T, T) -> R, - T: Clone; - - /// Create a return value with one more element - fn map_plus_one(self, item: R, f: F) -> Self::SizePlusOne - where - F: FnMut(T) -> R; -} - -impl ObjectArgument for Vec { - type SameSize = Vec; - type SizePlusOne = Vec; - - fn num_objects(&self) -> usize { - self.len() - } - - fn map(self, mut f: F) -> Self::SameSize - where - F: FnMut(T) -> R, - { - let mut ret = Vec::new(); - - for item in self { - ret.push(f(item)); - } - - ret - } - - fn map_with_next(self, mut f: F) -> Self::SameSize - where - F: FnMut(T, T) -> R, - T: Clone, - { - let mut next = self.clone(); - next.rotate_left(1); - - let mut ret = Vec::new(); - for (item, next) in self.into_iter().zip(next) { - ret.push(f(item, next)); - } - - ret - } - - fn map_with_prev(self, mut f: F) -> Self::SameSize - where - F: FnMut(T, T) -> R, - T: Clone, - { - let mut prev = self.clone(); - prev.rotate_right(1); - - let mut ret = Vec::new(); - for (item, prev) in self.into_iter().zip(prev) { - ret.push(f(item, prev)); - } - - ret - } - - fn map_plus_one(self, item: R, f: F) -> Self::SizePlusOne - where - F: FnMut(T) -> R, - { - let mut ret = self.map(f); - ret.push(item); - ret - } -} - -// This macro implements `ObjectArgument` for a number of array types. This -// should just be a single implementation, but while const generic expressions -// are still unstable, this is unfortunately not possible: -// -macro_rules! impl_object_argument_for_arrays { - ($($len:expr, $len_plus_one:expr;)*) => { - $( - impl ObjectArgument for [T; $len] { - type SameSize = [R; $len]; - type SizePlusOne = [R; $len_plus_one]; - - fn num_objects(&self) -> usize { - self.len() - } - - fn map(self, f: F) -> Self::SameSize - where - F: FnMut(T) -> R, - { - self.map(f) - } - - fn map_with_next(self, mut f: F) -> Self::SameSize - where - F: FnMut(T, T) -> R, - T: Clone, - { - let mut next = self.clone(); - next.rotate_left(1); - - let mut i = 0; - self.map(|item| { - let next = next[i].clone(); - i += 1; - - f(item, next) - }) - } - - fn map_with_prev(self, mut f: F) -> Self::SameSize - where - F: FnMut(T, T) -> R, - T: Clone, - { - let mut prev = self.clone(); - prev.rotate_right(1); - - let mut i = 0; - self.map(|item| { - let prev = prev[i].clone(); - i += 1; - - f(item, prev) - }) - } - - fn map_plus_one(self, item: R, mut f: F) - -> Self::SizePlusOne - where - F: FnMut(T) -> R, - { - let mut tmp = array::from_fn(|_| None); - for (i, item) in self.into_iter().enumerate() { - tmp[i] = Some(f(item)); - } - - tmp[tmp.len() - 1] = Some(item); - - tmp.map(Option::unwrap) - } - } - )* - }; -} - -impl_object_argument_for_arrays!( - 0, 1; - 1, 2; - 2, 3; - 3, 4; - 4, 5; - 5, 6; - 6, 7; - 7, 8; -); From 11a5a29d774a4b02f7324f4ac5d071ae2bc6dcb0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:22:30 +0100 Subject: [PATCH 16/25] Add `CycleBuilder2::connect_to_edges` --- crates/fj-kernel/src/builder/cycle.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 76c1ac34f..34af16a18 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -85,6 +85,30 @@ pub struct CycleBuilder2 { } impl CycleBuilder2 { + /// Create a cycle whose half-edges are connected to the provided half-edges + /// + /// The half-edges of the new circle will be coincident with the provided + /// half-edges, but will point in the opposite direction. + /// + /// Assumes that the provided half-edges, once translated into local + /// equivalents of this cycle, form a cycle themselves. + pub fn connect_to_edges(edges: Es) -> Self + where + Es: IntoIterator, Curve, [Point<1>; 2])>, + Es::IntoIter: Clone + ExactSizeIterator, + { + let half_edges = edges + .into_iter() + .circular_tuple_windows() + .map(|((prev, _, _), (_, curve, boundary))| { + HalfEdgeBuilder::new(curve, boundary) + .with_start_vertex(prev.start_vertex().clone()) + }) + .collect(); + + Self { half_edges } + } + /// Create a polygon pub fn polygon(points: Ps) -> Self where From da0c50f7cd6eb1596fb69621207de4f88ae85a58 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:23:53 +0100 Subject: [PATCH 17/25] Replace use of `CycleBuilder` --- crates/fj-kernel/src/algorithms/sweep/face.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 07f25df1c..2d223f028 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -5,10 +5,10 @@ use itertools::Itertools; use crate::{ algorithms::{reverse::Reverse, transform::TransformObject}, - builder::CycleBuilder, + builder::CycleBuilder2, geometry::curve::GlobalPath, insert::Insert, - objects::{Cycle, Face, Objects, Shell}, + objects::{Face, Objects, Shell}, services::Service, storage::Handle, }; @@ -82,7 +82,8 @@ impl Sweep for Handle { )); } - let top_cycle = Cycle::new([]).connect_to_edges(top_edges, objects); + let top_cycle = + CycleBuilder2::connect_to_edges(top_edges).build(objects); if i == 0 { exterior = Some(top_cycle.insert(objects)); From 74596f298281d4e0d79b8edb8348fd09b865c493 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:25:02 +0100 Subject: [PATCH 18/25] Remove unused builder method --- crates/fj-kernel/src/builder/cycle.rs | 37 --------------------------- 1 file changed, 37 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 34af16a18..9ef1fda31 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -27,21 +27,6 @@ pub trait CycleBuilder: Sized { half_edge: HalfEdgeBuilder, objects: &mut Service, ) -> (Self, Handle); - - /// Connect the cycles to the provided half-edges - /// - /// Assumes that the provided half-edges, once translated into local - /// equivalents of this cycle, form a cycle themselves. - /// - /// Returns the local equivalents of the provided half-edges. - fn connect_to_edges( - self, - edges: Es, - objects: &mut Service, - ) -> Self - where - Es: IntoIterator, Curve, [Point<1>; 2])>, - Es::IntoIter: Clone + ExactSizeIterator; } impl CycleBuilder for Cycle { @@ -55,28 +40,6 @@ impl CycleBuilder for Cycle { Cycle::new(self.half_edges().cloned().chain([half_edge.clone()])); (cycle, half_edge) } - - fn connect_to_edges( - mut self, - edges: Es, - objects: &mut Service, - ) -> Self - where - Es: IntoIterator, Curve, [Point<1>; 2])>, - Es::IntoIter: Clone + ExactSizeIterator, - { - edges.into_iter().circular_tuple_windows().for_each( - |((prev, _, _), (_, curve, boundary))| { - let half_edge = HalfEdgeBuilder::new(curve, boundary) - .with_start_vertex(prev.start_vertex().clone()); - - let (cycle, _) = self.clone().add_half_edge(half_edge, objects); - self = cycle; - }, - ); - - self - } } /// Builder API for [`Cycle`] From 9769db7e40551b660bea5b1ab33a6df9009b56e2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:26:16 +0100 Subject: [PATCH 19/25] Add `CycleBuilder2::new` Its documentation is not correct yet, but that will soon change, as I complete the replacement of `CycleBuilder`. --- crates/fj-kernel/src/builder/cycle.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 9ef1fda31..61c999862 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -43,11 +43,17 @@ impl CycleBuilder for Cycle { } /// Builder API for [`Cycle`] +#[derive(Default)] pub struct CycleBuilder2 { half_edges: Vec, } impl CycleBuilder2 { + /// Create an instance of `CycleBuilder` + pub fn new() -> Self { + Self::default() + } + /// Create a cycle whose half-edges are connected to the provided half-edges /// /// The half-edges of the new circle will be coincident with the provided From d43696b420f944d3f625a1d08aee0a9fe488bfcb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:27:54 +0100 Subject: [PATCH 20/25] Add `CycleBuilder2::add_half_edge` --- crates/fj-kernel/src/builder/cycle.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 61c999862..21ecde579 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -54,6 +54,12 @@ impl CycleBuilder2 { Self::default() } + /// Add a half-edge to the cycle + pub fn add_half_edge(mut self, half_edge: HalfEdgeBuilder) -> Self { + self.half_edges.push(half_edge); + self + } + /// Create a cycle whose half-edges are connected to the provided half-edges /// /// The half-edges of the new circle will be coincident with the provided From 4074b3c24079d6898f4365400e5998a13e3eaefd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:39:10 +0100 Subject: [PATCH 21/25] Replace use of `CycleBuilder` --- crates/fj-kernel/src/validate/cycle.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index e97fa709d..3771bcef7 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -94,7 +94,7 @@ impl CycleValidationError { mod tests { use crate::{ - builder::{CycleBuilder, CycleBuilder2, HalfEdgeBuilder}, + builder::{CycleBuilder2, HalfEdgeBuilder}, objects::Cycle, services::Services, validate::{cycle::CycleValidationError, Validate, ValidationError}, @@ -116,11 +116,10 @@ mod tests { let second = HalfEdgeBuilder::line_segment([[0., 0.], [1., 0.]], None); - Cycle::new([]) - .add_half_edge(first, &mut services.objects) - .0 - .add_half_edge(second, &mut services.objects) - .0 + CycleBuilder2::new() + .add_half_edge(first) + .add_half_edge(second) + .build(&mut services.objects) }; assert!(matches!( disconnected.validate_and_return_first_error(), From 8148770d36dbcab190ed89bcc33f4b4862e8cbb4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:41:03 +0100 Subject: [PATCH 22/25] Replace use of `CycleBuilder` --- crates/fj-operations/src/sketch.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index e1d76f6f3..45e8be3f2 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -2,7 +2,7 @@ use std::ops::Deref; use fj_interop::{debug::DebugInfo, mesh::Color}; use fj_kernel::{ - builder::{CycleBuilder, HalfEdgeBuilder}, + builder::{CycleBuilder2, HalfEdgeBuilder}, insert::Insert, objects::{Cycle, Face, Objects, Sketch}, services::Service, @@ -44,7 +44,7 @@ impl Shape for fj::Sketch { ); let exterior = { - let mut cycle = Cycle::new([]); + let mut cycle = CycleBuilder2::new(); let segments = poly_chain .to_segments() @@ -68,12 +68,10 @@ impl Shape for fj::Sketch { } }; - let (updated, _) = - cycle.add_half_edge(half_edge, objects); - cycle = updated; + cycle = cycle.add_half_edge(half_edge); } - cycle.insert(objects) + cycle.build(objects).insert(objects) }; Face::new( From 1934d50c34db0c5689e12c17043443cabad6632b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:45:47 +0100 Subject: [PATCH 23/25] Replace use of `CycleBuilder` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index aed925a5a..dfe033f8d 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -2,7 +2,7 @@ use fj_interop::{ext::ArrayExt, mesh::Color}; use fj_math::{Point, Scalar, Vector}; use crate::{ - builder::{CycleBuilder, HalfEdgeBuilder}, + builder::HalfEdgeBuilder, insert::Insert, objects::{Cycle, Face, HalfEdge, Objects, Surface, Vertex}, services::Service, @@ -85,15 +85,23 @@ impl Sweep for (&HalfEdge, &Handle, &Surface, Option) { ) .with_start_vertex(start_vertex); - if let Some(global_edge) = global_edge { + let builder = if let Some(global_edge) = global_edge { builder.with_global_form(global_edge) } else { builder - } + }; + + builder.build(objects).insert(objects) }; - let (updated, half_edge) = - exterior.take().unwrap().add_half_edge(half_edge, objects); + let updated = { + let exterior = exterior.take().unwrap(); + let half_edges = exterior + .half_edges() + .cloned() + .chain([half_edge.clone()]); + Cycle::new(half_edges) + }; exterior = Some(updated); half_edge From c51a80507f311411cb96150611e38924f1130163 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:46:29 +0100 Subject: [PATCH 24/25] Remove unused trait `CycleBuilder` --- crates/fj-kernel/src/builder/cycle.rs | 31 --------------------------- crates/fj-kernel/src/builder/mod.rs | 5 +---- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 21ecde579..afb5aa72b 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -11,37 +11,6 @@ use crate::{ use super::HalfEdgeBuilder; -/// Builder API for [`Cycle`] -pub trait CycleBuilder: Sized { - /// Add a new half-edge to the cycle - /// - /// Creates a half-edge and adds it to the cycle. The new half-edge is - /// connected to the front vertex of the last half-edge , and the back - /// vertex of the first edge, making sure the half-edges actually form a - /// cycle. - /// - /// If this is the first half-edge being added, it is connected to itself, - /// meaning its front and back vertices are the same. - fn add_half_edge( - self, - half_edge: HalfEdgeBuilder, - objects: &mut Service, - ) -> (Self, Handle); -} - -impl CycleBuilder for Cycle { - fn add_half_edge( - self, - half_edge: HalfEdgeBuilder, - objects: &mut Service, - ) -> (Self, Handle) { - let half_edge = half_edge.build(objects).insert(objects); - let cycle = - Cycle::new(self.half_edges().cloned().chain([half_edge.clone()])); - (cycle, half_edge) - } -} - /// Builder API for [`Cycle`] #[derive(Default)] pub struct CycleBuilder2 { diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index 03e7f3487..f96b9388e 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -4,7 +4,4 @@ mod cycle; mod edge; -pub use self::{ - cycle::{CycleBuilder, CycleBuilder2}, - edge::HalfEdgeBuilder, -}; +pub use self::{cycle::CycleBuilder2, edge::HalfEdgeBuilder}; From 8d8bcca01956b40e419ef3451199ef47a244991f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 17 Mar 2023 10:47:55 +0100 Subject: [PATCH 25/25] Rename `CycleBuilder2` to `CycleBuilder` --- .../src/algorithms/intersect/curve_face.rs | 6 +- .../src/algorithms/intersect/face_face.rs | 6 +- .../src/algorithms/intersect/face_point.rs | 18 ++--- .../src/algorithms/intersect/ray_face.rs | 79 ++++++------------- crates/fj-kernel/src/algorithms/sweep/face.rs | 4 +- .../src/algorithms/triangulate/mod.rs | 10 +-- crates/fj-kernel/src/builder/cycle.rs | 4 +- crates/fj-kernel/src/builder/mod.rs | 2 +- crates/fj-kernel/src/validate/cycle.rs | 9 +-- crates/fj-kernel/src/validate/face.rs | 6 +- crates/fj-operations/src/sketch.rs | 4 +- 11 files changed, 56 insertions(+), 92 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index e34138ea2..051e5d87a 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -150,7 +150,7 @@ where #[cfg(test)] mod tests { use crate::{ - builder::CycleBuilder2, geometry::curve::Curve, insert::Insert, + builder::CycleBuilder, geometry::curve::Curve, insert::Insert, objects::Face, services::Services, }; @@ -179,10 +179,10 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon(exterior_points) + CycleBuilder::polygon(exterior_points) .build(&mut services.objects) .insert(&mut services.objects), - vec![CycleBuilder2::polygon(interior_points) + vec![CycleBuilder::polygon(interior_points) .build(&mut services.objects) .insert(&mut services.objects)], None, diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index e3115b70d..deff5c23b 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -61,7 +61,7 @@ mod tests { use pretty_assertions::assert_eq; use crate::{ - algorithms::intersect::CurveFaceIntersection, builder::CycleBuilder2, + algorithms::intersect::CurveFaceIntersection, builder::CycleBuilder, geometry::curve::Curve, insert::Insert, objects::Face, services::Services, }; @@ -86,7 +86,7 @@ mod tests { .map(|surface| { Face::new( surface, - CycleBuilder2::polygon(points) + CycleBuilder::polygon(points) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), @@ -117,7 +117,7 @@ mod tests { let [a, b] = surfaces.clone().map(|surface| { Face::new( surface, - CycleBuilder2::polygon(points) + CycleBuilder::polygon(points) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 9dd227cc8..b9fff0978 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -138,7 +138,7 @@ mod tests { use crate::{ algorithms::intersect::{face_point::FacePointIntersection, Intersect}, - builder::CycleBuilder2, + builder::CycleBuilder, insert::Insert, objects::Face, services::Services, @@ -150,7 +150,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([[0., 0.], [1., 1.], [0., 2.]]) + CycleBuilder::polygon([[0., 0.], [1., 1.], [0., 2.]]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), @@ -168,7 +168,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([[0., 0.], [2., 1.], [0., 2.]]) + CycleBuilder::polygon([[0., 0.], [2., 1.], [0., 2.]]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), @@ -189,7 +189,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([[4., 2.], [0., 4.], [0., 0.]]) + CycleBuilder::polygon([[4., 2.], [0., 4.], [0., 0.]]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), @@ -210,7 +210,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([[0., 0.], [2., 1.], [3., 0.], [3., 4.]]) + CycleBuilder::polygon([[0., 0.], [2., 1.], [3., 0.], [3., 4.]]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), @@ -231,7 +231,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([[0., 0.], [2., 1.], [3., 1.], [0., 2.]]) + CycleBuilder::polygon([[0., 0.], [2., 1.], [3., 1.], [0., 2.]]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), @@ -252,7 +252,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([ + CycleBuilder::polygon([ [0., 0.], [2., 1.], [3., 1.], @@ -279,7 +279,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([[0., 0.], [2., 0.], [0., 1.]]) + CycleBuilder::polygon([[0., 0.], [2., 0.], [0., 1.]]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), @@ -306,7 +306,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([[0., 0.], [1., 0.], [0., 1.]]) + CycleBuilder::polygon([[0., 0.], [1., 0.], [0., 1.]]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index faa2b6763..a57f782b0 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -151,7 +151,7 @@ mod tests { }, transform::TransformObject, }, - builder::CycleBuilder2, + builder::CycleBuilder, insert::Insert, objects::Face, services::Services, @@ -165,14 +165,9 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects), + CycleBuilder::polygon([[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -189,14 +184,9 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects), + CycleBuilder::polygon([[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -216,14 +206,9 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects), + CycleBuilder::polygon([[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -240,14 +225,9 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects), + CycleBuilder::polygon([[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -272,14 +252,9 @@ mod tests { let face = Face::new( services.objects.surfaces.yz_plane(), - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects), + CycleBuilder::polygon([[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -307,14 +282,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects), + CycleBuilder::polygon([[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); @@ -333,14 +303,9 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([ - [-1., -1.], - [1., -1.], - [1., 1.], - [-1., 1.], - ]) - .build(&mut services.objects) - .insert(&mut services.objects), + CycleBuilder::polygon([[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]]) + .build(&mut services.objects) + .insert(&mut services.objects), Vec::new(), None, ); diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 2d223f028..81006d69c 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -5,7 +5,7 @@ use itertools::Itertools; use crate::{ algorithms::{reverse::Reverse, transform::TransformObject}, - builder::CycleBuilder2, + builder::CycleBuilder, geometry::curve::GlobalPath, insert::Insert, objects::{Face, Objects, Shell}, @@ -83,7 +83,7 @@ impl Sweep for Handle { } let top_cycle = - CycleBuilder2::connect_to_edges(top_edges).build(objects); + CycleBuilder::connect_to_edges(top_edges).build(objects); if i == 0 { exterior = Some(top_cycle.insert(objects)); diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 6b8f8f267..14e7b6e04 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -79,7 +79,7 @@ mod tests { use crate::{ algorithms::approx::{Approx, Tolerance}, - builder::CycleBuilder2, + builder::CycleBuilder, insert::Insert, objects::Face, services::Services, @@ -98,7 +98,7 @@ mod tests { let face = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([a, b, c, d]) + CycleBuilder::polygon([a, b, c, d]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), @@ -138,10 +138,10 @@ mod tests { let face = Face::new( surface.clone(), - CycleBuilder2::polygon([a, b, c, d]) + CycleBuilder::polygon([a, b, c, d]) .build(&mut services.objects) .insert(&mut services.objects), - vec![CycleBuilder2::polygon([e, f, g, h]) + vec![CycleBuilder::polygon([e, f, g, h]) .build(&mut services.objects) .insert(&mut services.objects)], None, @@ -202,7 +202,7 @@ mod tests { let face = Face::new( surface.clone(), - CycleBuilder2::polygon([a, b, c, d, e]) + CycleBuilder::polygon([a, b, c, d, e]) .build(&mut services.objects) .insert(&mut services.objects), Vec::new(), diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index afb5aa72b..2f5a8cbb1 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -13,11 +13,11 @@ use super::HalfEdgeBuilder; /// Builder API for [`Cycle`] #[derive(Default)] -pub struct CycleBuilder2 { +pub struct CycleBuilder { half_edges: Vec, } -impl CycleBuilder2 { +impl CycleBuilder { /// Create an instance of `CycleBuilder` pub fn new() -> Self { Self::default() diff --git a/crates/fj-kernel/src/builder/mod.rs b/crates/fj-kernel/src/builder/mod.rs index f96b9388e..ef35bcfa3 100644 --- a/crates/fj-kernel/src/builder/mod.rs +++ b/crates/fj-kernel/src/builder/mod.rs @@ -4,4 +4,4 @@ mod cycle; mod edge; -pub use self::{cycle::CycleBuilder2, edge::HalfEdgeBuilder}; +pub use self::{cycle::CycleBuilder, edge::HalfEdgeBuilder}; diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 3771bcef7..bc2a96f31 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -94,7 +94,7 @@ impl CycleValidationError { mod tests { use crate::{ - builder::{CycleBuilder2, HalfEdgeBuilder}, + builder::{CycleBuilder, HalfEdgeBuilder}, objects::Cycle, services::Services, validate::{cycle::CycleValidationError, Validate, ValidationError}, @@ -104,9 +104,8 @@ mod tests { fn half_edges_connected() -> anyhow::Result<()> { let mut services = Services::new(); - let valid = - CycleBuilder2::polygon([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]) - .build(&mut services.objects); + let valid = CycleBuilder::polygon([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]]) + .build(&mut services.objects); valid.validate_and_return_first_error()?; @@ -116,7 +115,7 @@ mod tests { let second = HalfEdgeBuilder::line_segment([[0., 0.], [1., 0.]], None); - CycleBuilder2::new() + CycleBuilder::new() .add_half_edge(first) .add_half_edge(second) .build(&mut services.objects) diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 6cfd2ff29..fe3107183 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -72,7 +72,7 @@ impl FaceValidationError { mod tests { use crate::{ algorithms::reverse::Reverse, - builder::CycleBuilder2, + builder::CycleBuilder, insert::Insert, objects::Face, services::Services, @@ -85,10 +85,10 @@ mod tests { let valid = Face::new( services.objects.surfaces.xy_plane(), - CycleBuilder2::polygon([[0., 0.], [3., 0.], [0., 3.]]) + CycleBuilder::polygon([[0., 0.], [3., 0.], [0., 3.]]) .build(&mut services.objects) .insert(&mut services.objects), - vec![CycleBuilder2::polygon([[1., 1.], [1., 2.], [2., 1.]]) + vec![CycleBuilder::polygon([[1., 1.], [1., 2.], [2., 1.]]) .build(&mut services.objects) .insert(&mut services.objects)], None, diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 45e8be3f2..8091de253 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -2,7 +2,7 @@ use std::ops::Deref; use fj_interop::{debug::DebugInfo, mesh::Color}; use fj_kernel::{ - builder::{CycleBuilder2, HalfEdgeBuilder}, + builder::{CycleBuilder, HalfEdgeBuilder}, insert::Insert, objects::{Cycle, Face, Objects, Sketch}, services::Service, @@ -44,7 +44,7 @@ impl Shape for fj::Sketch { ); let exterior = { - let mut cycle = CycleBuilder2::new(); + let mut cycle = CycleBuilder::new(); let segments = poly_chain .to_segments()