diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 930e19ccf..35cc8344c 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -74,7 +74,7 @@ impl Sweep for Handle { } } - Ok(Shell::builder(objects).with_faces(faces).build()) + Ok(Shell::builder().with_faces(faces).build(objects)) } } @@ -102,10 +102,10 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let solid = Sketch::builder(&objects) + let solid = Sketch::builder() .with_surface(surface.clone()) - .with_polygon_from_points(TRIANGLE) - .build() + .with_polygon_from_points(TRIANGLE, &objects) + .build(&objects) .sweep(UP, &objects)?; let bottom = Face::partial() @@ -149,10 +149,10 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let solid = Sketch::builder(&objects) + let solid = Sketch::builder() .with_surface(surface.clone()) - .with_polygon_from_points(TRIANGLE) - .build() + .with_polygon_from_points(TRIANGLE, &objects) + .build(&objects) .sweep(DOWN, &objects)?; let bottom = Face::partial() diff --git a/crates/fj-kernel/src/algorithms/sweep/sketch.rs b/crates/fj-kernel/src/algorithms/sweep/sketch.rs index fbd1a691f..49d49bbfd 100644 --- a/crates/fj-kernel/src/algorithms/sweep/sketch.rs +++ b/crates/fj-kernel/src/algorithms/sweep/sketch.rs @@ -25,6 +25,6 @@ impl Sweep for Handle { shells.push(shell); } - Ok(Solid::builder(objects).with_shells(shells).build()) + Ok(Solid::builder().with_shells(shells).build(objects)) } } diff --git a/crates/fj-kernel/src/algorithms/transform/shell.rs b/crates/fj-kernel/src/algorithms/transform/shell.rs index cb86a6e4d..167b06e3c 100644 --- a/crates/fj-kernel/src/algorithms/transform/shell.rs +++ b/crates/fj-kernel/src/algorithms/transform/shell.rs @@ -22,6 +22,6 @@ impl TransformObject for Handle { face.transform(transform, objects) }) .collect::, _>>()?; - Ok(Shell::builder(objects).with_faces(faces).build()) + Ok(Shell::builder().with_faces(faces).build(objects)) } } diff --git a/crates/fj-kernel/src/algorithms/transform/sketch.rs b/crates/fj-kernel/src/algorithms/transform/sketch.rs index ed327d45f..2b8ee131c 100644 --- a/crates/fj-kernel/src/algorithms/transform/sketch.rs +++ b/crates/fj-kernel/src/algorithms/transform/sketch.rs @@ -20,6 +20,6 @@ impl TransformObject for Handle { .cloned() .map(|face| face.transform(transform, objects)) .collect::, _>>()?; - Ok(Sketch::builder(objects).with_faces(faces).build()) + Ok(Sketch::builder().with_faces(faces).build(objects)) } } diff --git a/crates/fj-kernel/src/algorithms/transform/solid.rs b/crates/fj-kernel/src/algorithms/transform/solid.rs index 684ce0b79..0230f8ddf 100644 --- a/crates/fj-kernel/src/algorithms/transform/solid.rs +++ b/crates/fj-kernel/src/algorithms/transform/solid.rs @@ -21,6 +21,6 @@ impl TransformObject for Handle { shell.transform(transform, objects) }) .collect::, _>>()?; - Ok(Solid::builder(objects).with_shells(faces).build()) + Ok(Solid::builder().with_shells(faces).build(objects)) } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index fe381beb9..b33ab9ddd 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -19,15 +19,12 @@ use crate::{ /// API for building a [`Shell`] /// /// Also see [`Shell::builder`]. -pub struct ShellBuilder<'a> { - /// The stores that the created objects are put in - pub objects: &'a Objects, - +pub struct ShellBuilder { /// The faces that make up the [`Shell`] pub faces: FaceSet, } -impl<'a> ShellBuilder<'a> { +impl ShellBuilder { /// Build the [`Shell`] with the provided faces pub fn with_faces( mut self, @@ -41,6 +38,7 @@ impl<'a> ShellBuilder<'a> { pub fn with_cube_from_edge_length( mut self, edge_length: impl Into, + objects: &Objects, ) -> Self { let edge_length = edge_length.into(); @@ -49,11 +47,10 @@ impl<'a> ShellBuilder<'a> { let h = edge_length / 2.; let bottom = { - let surface = self - .objects + let surface = objects .surfaces .xy_plane() - .translate([Z, Z, -h], self.objects) + .translate([Z, Z, -h], objects) .unwrap(); Face::partial() @@ -64,9 +61,9 @@ impl<'a> ShellBuilder<'a> { [h, h], [-h, h], ]) - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }; @@ -82,9 +79,9 @@ impl<'a> ShellBuilder<'a> { let c = a + [Z, Z, edge_length]; PartialSurface::plane_from_points([a, b, c]) - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }) .collect::>(); @@ -102,9 +99,9 @@ impl<'a> ShellBuilder<'a> { surface.clone(), [[Z, Z], [edge_length, Z]], ) - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }) .collect::>(); @@ -138,9 +135,9 @@ impl<'a> ShellBuilder<'a> { ..Default::default() } .update_as_line_segment() - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }) .collect::>(); @@ -190,9 +187,9 @@ impl<'a> ShellBuilder<'a> { ..Default::default() } .update_as_line_segment() - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }) .collect::>() @@ -223,9 +220,9 @@ impl<'a> ShellBuilder<'a> { ..Default::default() } .update_as_line_segment() - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }) .collect::>(); @@ -238,16 +235,16 @@ impl<'a> ShellBuilder<'a> { .map(|(((bottom, side_up), top), side_down)| { let cycle = Cycle::partial() .with_half_edges([bottom, side_up, top, side_down]) - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap(); Face::partial() .with_exterior(cycle) - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }); @@ -255,11 +252,10 @@ impl<'a> ShellBuilder<'a> { }; let top = { - let surface = self - .objects + let surface = objects .surfaces .xy_plane() - .translate([Z, Z, h], self.objects) + .translate([Z, Z, h], objects) .unwrap(); let mut top_edges = top_edges; @@ -283,9 +279,9 @@ impl<'a> ShellBuilder<'a> { surface: Some(surface.clone()), global_form: vertex.global_form().clone().into(), } - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }); @@ -317,18 +313,18 @@ impl<'a> ShellBuilder<'a> { ..Default::default() } .update_as_line_segment() - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap(), ); } Face::partial() - .with_exterior(Cycle::new(edges).insert(self.objects).unwrap()) - .build(self.objects) + .with_exterior(Cycle::new(edges).insert(objects).unwrap()) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap() }; @@ -340,7 +336,7 @@ impl<'a> ShellBuilder<'a> { } /// Build the [`Shell`] - pub fn build(self) -> Handle { - Shell::new(self.faces).insert(self.objects).unwrap() + pub fn build(self, objects: &Objects) -> Handle { + Shell::new(self.faces).insert(objects).unwrap() } } diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 85f2a3f26..0e475933e 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -12,10 +12,7 @@ use super::FaceBuilder; /// API for building a [`Sketch`] /// /// Also see [`Sketch::builder`]. -pub struct SketchBuilder<'a> { - /// The stores that the created objects are put in - pub objects: &'a Objects, - +pub struct SketchBuilder { /// The surface that the [`Sketch`] is defined in pub surface: Option>, @@ -23,7 +20,7 @@ pub struct SketchBuilder<'a> { pub faces: FaceSet, } -impl<'a> SketchBuilder<'a> { +impl SketchBuilder { /// Build the [`Sketch`] with the provided [`Surface`] pub fn with_surface(mut self, surface: Handle) -> Self { self.surface = Some(surface); @@ -43,6 +40,7 @@ impl<'a> SketchBuilder<'a> { pub fn with_polygon_from_points( mut self, points: impl IntoIterator>>, + objects: &Objects, ) -> Self { let surface = self .surface @@ -51,15 +49,15 @@ impl<'a> SketchBuilder<'a> { self.faces.extend([Face::partial() .with_surface(surface.clone()) .with_exterior_polygon_from_points(points) - .build(self.objects) + .build(objects) .unwrap() - .insert(self.objects) + .insert(objects) .unwrap()]); self } /// Build the [`Sketch`] - pub fn build(self) -> Handle { - Sketch::new(self.faces).insert(self.objects).unwrap() + pub fn build(self, objects: &Objects) -> Handle { + Sketch::new(self.faces).insert(objects).unwrap() } } diff --git a/crates/fj-kernel/src/builder/solid.rs b/crates/fj-kernel/src/builder/solid.rs index d42c6480e..d8c3ecc40 100644 --- a/crates/fj-kernel/src/builder/solid.rs +++ b/crates/fj-kernel/src/builder/solid.rs @@ -11,15 +11,12 @@ use crate::{ /// API for building a [`Solid`] /// /// Also see [`Solid::builder`]. -pub struct SolidBuilder<'a> { - /// The stores that the created objects are put in - pub objects: &'a Objects, - +pub struct SolidBuilder { /// The shells that make up the [`Solid`] pub shells: BTreeSet>, } -impl<'a> SolidBuilder<'a> { +impl SolidBuilder { /// Build the [`Solid`] with the provided shells pub fn with_shells( mut self, @@ -33,16 +30,17 @@ impl<'a> SolidBuilder<'a> { pub fn with_cube_from_edge_length( mut self, edge_length: impl Into, + objects: &Objects, ) -> Self { - let shell = Shell::builder(self.objects) - .with_cube_from_edge_length(edge_length) - .build(); + let shell = Shell::builder() + .with_cube_from_edge_length(edge_length, objects) + .build(objects); self.shells.insert(shell); self } /// Build the [`Solid`] - pub fn build(self) -> Handle { - Solid::new(self.shells).insert(self.objects).unwrap() + pub fn build(self, objects: &Objects) -> Handle { + Solid::new(self.shells).insert(objects).unwrap() } } diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index cfe8020b8..2f7417597 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -527,9 +527,9 @@ mod tests { fn shell() { let objects = Objects::new(); - let object = Shell::builder(&objects) - .with_cube_from_edge_length(1.) - .build(); + let object = Shell::builder() + .with_cube_from_edge_length(1., &objects) + .build(&objects); assert_eq!(24, object.curve_iter().count()); assert_eq!(6, object.cycle_iter().count()); @@ -554,7 +554,7 @@ mod tests { .with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]]) .build(&objects)? .insert(&objects)?; - let object = Sketch::builder(&objects).with_faces([face]).build(); + let object = Sketch::builder().with_faces([face]).build(&objects); assert_eq!(3, object.curve_iter().count()); assert_eq!(1, object.cycle_iter().count()); @@ -575,9 +575,9 @@ mod tests { fn solid() { let objects = Objects::new(); - let object = Solid::builder(&objects) - .with_cube_from_edge_length(1.) - .build(); + let object = Solid::builder() + .with_cube_from_edge_length(1., &objects) + .build(&objects); assert_eq!(24, object.curve_iter().count()); assert_eq!(6, object.cycle_iter().count()); diff --git a/crates/fj-kernel/src/objects/full/shell.rs b/crates/fj-kernel/src/objects/full/shell.rs index d1c1d6aac..31eb2de7a 100644 --- a/crates/fj-kernel/src/objects/full/shell.rs +++ b/crates/fj-kernel/src/objects/full/shell.rs @@ -1,6 +1,6 @@ use crate::{ builder::ShellBuilder, - objects::{Face, FaceSet, Objects}, + objects::{Face, FaceSet}, storage::Handle, }; @@ -17,9 +17,8 @@ pub struct Shell { impl Shell { /// Build a `Shell` using [`ShellBuilder`] - pub fn builder(objects: &Objects) -> ShellBuilder { + pub fn builder() -> ShellBuilder { ShellBuilder { - objects, faces: FaceSet::new(), } } diff --git a/crates/fj-kernel/src/objects/full/sketch.rs b/crates/fj-kernel/src/objects/full/sketch.rs index b3c314a91..ca58de263 100644 --- a/crates/fj-kernel/src/objects/full/sketch.rs +++ b/crates/fj-kernel/src/objects/full/sketch.rs @@ -1,6 +1,6 @@ use crate::{ builder::SketchBuilder, - objects::{Face, FaceSet, Objects}, + objects::{Face, FaceSet}, storage::Handle, }; @@ -17,9 +17,8 @@ pub struct Sketch { impl Sketch { /// Build a `Sketch` using [`SketchBuilder`] - pub fn builder(objects: &Objects) -> SketchBuilder { + pub fn builder() -> SketchBuilder { SketchBuilder { - objects, surface: None, faces: FaceSet::new(), } diff --git a/crates/fj-kernel/src/objects/full/solid.rs b/crates/fj-kernel/src/objects/full/solid.rs index 8ff6aa00e..7c0236a0f 100644 --- a/crates/fj-kernel/src/objects/full/solid.rs +++ b/crates/fj-kernel/src/objects/full/solid.rs @@ -2,7 +2,7 @@ use std::collections::BTreeSet; use crate::{ builder::SolidBuilder, - objects::{Face, Objects, Shell}, + objects::{Face, Shell}, storage::Handle, }; @@ -19,9 +19,8 @@ pub struct Solid { impl Solid { /// Build a `Solid` using [`SolidBuilder`] - pub fn builder(objects: &Objects) -> SolidBuilder { + pub fn builder() -> SolidBuilder { SolidBuilder { - objects, shells: BTreeSet::new(), } } diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 54b60414a..d4518dc61 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -89,7 +89,7 @@ impl Shape for fj::Difference2d { ); } - let difference = Sketch::builder(objects).with_faces(faces).build(); + let difference = Sketch::builder().with_faces(faces).build(objects); Ok(difference.deref().clone()) } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index a37ca92dd..041fca4eb 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -59,7 +59,7 @@ impl Shape for fj::Sketch { } }; - let sketch = Sketch::builder(objects).with_faces([face]).build(); + let sketch = Sketch::builder().with_faces([face]).build(objects); Ok(sketch.deref().clone()) }