diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index cc34a6d36..da31da187 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -50,15 +50,8 @@ impl CycleBuilder for PartialCycle { &mut self, points: impl IntoIterator>>, ) -> Vec> { - let mut points = points.into_iter().map(Into::into); - let mut half_edges = Vec::new(); - if let Some(point) = points.next() { - let half_edge = self.add_half_edge_from_point_to_start(point); - half_edges.push(half_edge); - } - for point in points { let half_edge = self.add_half_edge_from_point_to_start(point); half_edges.push(half_edge); diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 77d952867..c673449b4 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -9,7 +9,7 @@ use crate::{ builder::{ FaceBuilder, HalfEdgeBuilder, SurfaceBuilder, SurfaceVertexBuilder, }, - objects::{HalfEdge, Objects}, + objects::{Face, HalfEdge, Objects}, partial::{ Partial, PartialCycle, PartialFace, PartialHalfEdge, PartialShell, PartialSurface, PartialSurfaceVertex, @@ -19,6 +19,12 @@ use crate::{ /// Builder API for [`PartialShell`] pub trait ShellBuilder { + /// Add a face to the shell + /// + /// The face will not be connected to any other faces that the shell might + /// already have. + fn add_face(&mut self) -> Partial; + /// Create a cube from the length of its edges fn create_cube_from_edge_length( edge_length: impl Into, @@ -27,6 +33,12 @@ pub trait ShellBuilder { } impl ShellBuilder for PartialShell { + fn add_face(&mut self) -> Partial { + let face = Partial::default(); + self.faces.push(face.clone()); + face + } + fn create_cube_from_edge_length( edge_length: impl Into, objects: &mut Service, @@ -70,8 +82,9 @@ impl ShellBuilder for PartialShell { }); let c = a + [Z, Z, edge_length]; - let (surface, _) = - PartialSurface::plane_from_points([a, b, c]); + let mut surface = PartialSurface::default(); + surface.update_as_plane_from_points([a, b, c]); + Partial::from_partial(surface) }) .collect::>(); diff --git a/crates/fj-kernel/src/builder/surface.rs b/crates/fj-kernel/src/builder/surface.rs index 54f1efcdd..358e60589 100644 --- a/crates/fj-kernel/src/builder/surface.rs +++ b/crates/fj-kernel/src/builder/surface.rs @@ -11,9 +11,10 @@ pub trait SurfaceBuilder: Sized { fn from_axes(u: GlobalPath, v: impl Into>) -> Self; /// Construct a plane from 3 points - fn plane_from_points( + fn update_as_plane_from_points( + &mut self, points: [impl Into>; 3], - ) -> (Self, [Point<2>; 3]); + ) -> [Point<2>; 3]; } impl SurfaceBuilder for PartialSurface { @@ -25,25 +26,19 @@ impl SurfaceBuilder for PartialSurface { } } - fn plane_from_points( + fn update_as_plane_from_points( + &mut self, points: [impl Into>; 3], - ) -> (Self, [Point<2>; 3]) { + ) -> [Point<2>; 3] { let [a, b, c] = points.map(Into::into); let (u, u_coords) = GlobalPath::line_from_points([a, b]); let v = c - a; - let coords = { - let [a, b] = u_coords.map(|point| point.t); - [[a, Scalar::ZERO], [b, Scalar::ZERO], [a, Scalar::ONE]] - .map(Point::from) - }; - - ( - Self { - geometry: Some(SurfaceGeometry { u, v }), - }, - coords, - ) + self.geometry = Some(SurfaceGeometry { u, v }); + + let [a, b] = u_coords.map(|point| point.t); + [[a, Scalar::ZERO], [b, Scalar::ZERO], [a, Scalar::ONE]] + .map(Point::from) } }