From da5f6b02eecb3f71baf1a4c1c280b3744347b080 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 2 Jan 2023 13:38:00 +0100 Subject: [PATCH 1/4] Remove redundant code --- crates/fj-kernel/src/builder/cycle.rs | 7 ------- 1 file changed, 7 deletions(-) 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); From 42e708965e45cd0c7efd774ee68fd2ea01683b60 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Dec 2022 15:51:01 +0100 Subject: [PATCH 2/4] Add `ShellBuilder::add_face` --- crates/fj-kernel/src/builder/shell.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 77d952867..a50c722f9 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, From 0b2f71a46114e753db7900db56a69adf1cd32c9f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 4 Jan 2023 12:48:16 +0100 Subject: [PATCH 3/4] Make `SurfaceBuilder` method more idiomatic Make it follow the `&mut` style followed by most other builder methods. --- crates/fj-kernel/src/builder/shell.rs | 5 +++-- crates/fj-kernel/src/builder/surface.rs | 23 +++++++++-------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index a50c722f9..33824def3 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -82,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.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..21eec2ccf 100644 --- a/crates/fj-kernel/src/builder/surface.rs +++ b/crates/fj-kernel/src/builder/surface.rs @@ -12,8 +12,9 @@ pub trait SurfaceBuilder: Sized { /// Construct a plane from 3 points fn plane_from_points( + &mut self, points: [impl Into>; 3], - ) -> (Self, [Point<2>; 3]); + ) -> [Point<2>; 3]; } impl SurfaceBuilder for PartialSurface { @@ -26,24 +27,18 @@ impl SurfaceBuilder for PartialSurface { } fn 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) } } From 3a53f8fa74702ac162f2e40edb90a36d277386e2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 4 Jan 2023 12:49:11 +0100 Subject: [PATCH 4/4] Update trait method name --- crates/fj-kernel/src/builder/shell.rs | 2 +- crates/fj-kernel/src/builder/surface.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 33824def3..c673449b4 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -83,7 +83,7 @@ impl ShellBuilder for PartialShell { let c = a + [Z, Z, edge_length]; let mut surface = PartialSurface::default(); - surface.plane_from_points([a, b, c]); + surface.update_as_plane_from_points([a, b, c]); Partial::from_partial(surface) }) diff --git a/crates/fj-kernel/src/builder/surface.rs b/crates/fj-kernel/src/builder/surface.rs index 21eec2ccf..358e60589 100644 --- a/crates/fj-kernel/src/builder/surface.rs +++ b/crates/fj-kernel/src/builder/surface.rs @@ -11,7 +11,7 @@ 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], ) -> [Point<2>; 3]; @@ -26,7 +26,7 @@ impl SurfaceBuilder for PartialSurface { } } - fn plane_from_points( + fn update_as_plane_from_points( &mut self, points: [impl Into>; 3], ) -> [Point<2>; 3] {