diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index cc78784a0..7515d9e0f 100644 --- a/crates/fj-kernel/src/algorithms/sweep.rs +++ b/crates/fj-kernel/src/algorithms/sweep.rs @@ -63,7 +63,7 @@ pub fn sweep( } } - Solid::from_faces(target) + Solid::new().with_faces(target) } fn create_bottom_faces( @@ -300,7 +300,7 @@ mod tests { [1., 0.], [0., 1.], ]); - let sketch = Sketch::from_faces([face]); + let sketch = Sketch::new().with_faces([face]); let solid = super::sweep(sketch, direction, tolerance, Color([255, 0, 0, 255])); diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index 7493b8944..c187f0aba 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -102,21 +102,15 @@ impl TransformObject for GlobalVertex { impl TransformObject for Sketch { fn transform(self, transform: &Transform) -> Self { - let faces = self - .into_faces() - .into_iter() - .map(|face| face.transform(transform)); - Self::from_faces(faces) + let faces = self.into_faces().map(|face| face.transform(transform)); + Self::new().with_faces(faces) } } impl TransformObject for Solid { fn transform(self, transform: &Transform) -> Self { - let faces = self - .into_faces() - .into_iter() - .map(|face| face.transform(transform)); - Self::from_faces(faces) + let faces = self.into_faces().map(|face| face.transform(transform)); + Self::new().with_faces(faces) } } diff --git a/crates/fj-kernel/src/builder/solid.rs b/crates/fj-kernel/src/builder/solid.rs index 7e3ce29f0..53dbb45ba 100644 --- a/crates/fj-kernel/src/builder/solid.rs +++ b/crates/fj-kernel/src/builder/solid.rs @@ -33,6 +33,6 @@ impl SolidBuilder { let faces = planes.map(|plane| Face::build(plane).polygon_from_points(points)); - Solid::from_faces(faces) + Solid::new().with_faces(faces) } } diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index ceea836cc..66d338213 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -397,7 +397,7 @@ mod tests { [1., 0.], [0., 1.], ]); - let object = Sketch::from_faces([face]); + let object = Sketch::new().with_faces([face]); assert_eq!(3, object.curve_iter().count()); assert_eq!(1, object.cycle_iter().count()); diff --git a/crates/fj-kernel/src/objects/cycle.rs b/crates/fj-kernel/src/objects/cycle.rs index f2f44a531..38f7db80d 100644 --- a/crates/fj-kernel/src/objects/cycle.rs +++ b/crates/fj-kernel/src/objects/cycle.rs @@ -13,6 +13,11 @@ pub struct Cycle { } impl Cycle { + /// Build a cycle using [`CycleBuilder`] + pub fn build(surface: Surface) -> CycleBuilder { + CycleBuilder::new(surface) + } + /// Create a new cycle #[allow(clippy::new_without_default)] pub fn new() -> Self { @@ -33,11 +38,6 @@ impl Cycle { self } - /// Build a cycle using [`CycleBuilder`] - pub fn build(surface: Surface) -> CycleBuilder { - CycleBuilder::new(surface) - } - /// Access edges that make up the cycle pub fn edges(&self) -> impl Iterator + '_ { self.edges.iter() diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index 677545277..a294f43d8 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -12,16 +12,16 @@ pub struct Edge { } impl Edge { - /// Create a new instance - pub fn new(curve: Local>, vertices: VerticesOfEdge) -> Self { - Self { curve, vertices } - } - /// Build an edge using [`EdgeBuilder`] pub fn build() -> EdgeBuilder { EdgeBuilder } + /// Create a new instance + pub fn new(curve: Local>, vertices: VerticesOfEdge) -> Self { + Self { curve, vertices } + } + /// Access the curve that defines the edge's geometry /// /// The edge can be a segment of the curve that is bounded by two vertices, diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index d8ddb42aa..a02a6d928 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -12,6 +12,11 @@ pub struct Face { } impl Face { + /// Build a face using [`FaceBuilder`] + pub fn build(surface: Surface) -> FaceBuilder { + FaceBuilder::new(surface) + } + /// Construct a new instance of `Face` /// /// Creates the face with no exteriors, no interiors and the default color. @@ -27,7 +32,7 @@ impl Face { } } - /// Contact an instance that uses triangle representation + /// Construct an instance that uses triangle representation pub fn from_triangles(triangles: TriRep) -> Self { Self { representation: Representation::TriRep(triangles), @@ -70,11 +75,6 @@ impl Face { self } - /// Build a face using [`FaceBuilder`] - pub fn build(surface: Surface) -> FaceBuilder { - FaceBuilder::new(surface) - } - /// Access this face's surface pub fn surface(&self) -> &Surface { &self.brep().surface diff --git a/crates/fj-kernel/src/objects/sketch.rs b/crates/fj-kernel/src/objects/sketch.rs index 3f63b37e5..6df790452 100644 --- a/crates/fj-kernel/src/objects/sketch.rs +++ b/crates/fj-kernel/src/objects/sketch.rs @@ -14,12 +14,23 @@ pub struct Sketch { } impl Sketch { - /// Construct a sketch from faces - pub fn from_faces( + /// Construct an empty instance of `Sketch` + pub fn new() -> Self { + Self { + faces: BTreeSet::new(), + } + } + + /// Add faces to the sketch + /// + /// Consumes the sketch and returns the updated instance. + pub fn with_faces( + mut self, faces: impl IntoIterator>, ) -> Self { - let faces = faces.into_iter().map(Into::into).collect(); - Self { faces } + let faces = faces.into_iter().map(Into::into); + self.faces.extend(faces); + self } /// Access the sketch's faces @@ -28,7 +39,13 @@ impl Sketch { } /// Convert the sketch into a list of faces - pub fn into_faces(self) -> BTreeSet { - self.faces + pub fn into_faces(self) -> impl Iterator { + self.faces.into_iter() + } +} + +impl Default for Sketch { + fn default() -> Self { + Self::new() } } diff --git a/crates/fj-kernel/src/objects/solid.rs b/crates/fj-kernel/src/objects/solid.rs index a63da5e24..ce54ecd25 100644 --- a/crates/fj-kernel/src/objects/solid.rs +++ b/crates/fj-kernel/src/objects/solid.rs @@ -22,26 +22,43 @@ pub struct Solid { } impl Solid { - /// Construct a solid from faces - pub fn from_faces( - faces: impl IntoIterator>, - ) -> Self { - let faces = faces.into_iter().map(Into::into).collect(); - Self { faces } - } - /// Build a solid using [`SolidBuilder`] pub fn build() -> SolidBuilder { SolidBuilder } + /// Construct an empty instance of `Solid` + pub fn new() -> Self { + Self { + faces: BTreeSet::new(), + } + } + + /// Add faces to the solid + /// + /// Consumes the solid and returns the updated instance. + pub fn with_faces( + mut self, + faces: impl IntoIterator>, + ) -> Self { + let faces = faces.into_iter().map(Into::into); + self.faces.extend(faces); + self + } + /// Access the solid's faces pub fn faces(&self) -> impl Iterator { self.faces.iter() } /// Convert the solid into a list of faces - pub fn into_faces(self) -> BTreeSet { - self.faces + pub fn into_faces(self) -> impl Iterator { + self.faces.into_iter() + } +} + +impl Default for Solid { + fn default() -> Self { + Self::new() } } diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index b3fcf500f..46ce9e2c9 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -78,7 +78,7 @@ impl Shape for fj::Difference2d { ); } - let difference = Sketch::from_faces(faces); + let difference = Sketch::new().with_faces(faces); validate(difference, config) } diff --git a/crates/fj-operations/src/lib.rs b/crates/fj-operations/src/lib.rs index 3efb51e72..9105f7baf 100644 --- a/crates/fj-operations/src/lib.rs +++ b/crates/fj-operations/src/lib.rs @@ -67,7 +67,6 @@ impl Shape for fj::Shape { .compute_brep(config, tolerance, debug_info)? .into_inner() .into_faces() - .into_iter() .collect(), config, ), @@ -79,7 +78,6 @@ impl Shape for fj::Shape { .compute_brep(config, tolerance, debug_info)? .into_inner() .into_faces() - .into_iter() .collect(), config, ), diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 0eea8f950..a774c9950 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -43,7 +43,7 @@ impl Shape for fj::Sketch { } }; - let sketch = Sketch::from_faces([face]); + let sketch = Sketch::new().with_faces([face]); validate(sketch, config) }