From c76f14dde8fc62bb0eec91bf1dcbe340ad88a61a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 13:23:33 +0100 Subject: [PATCH 01/10] Prepare code for follow-on change --- crates/fj-operations/src/sketch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index f6a463e6b..6754fb6ec 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -84,7 +84,7 @@ impl Shape for fj::Sketch { }, ); line_segments.into_iter().for_each(|mut half_edge| { - half_edge.write().update_as_line_segment() + half_edge.write().update_as_line_segment(); }); arcs.into_iter().for_each(|(mut half_edge, angle)| { half_edge.write().update_as_arc(angle.rad()) From c2ad422e62fab1519de7e197942dcd7be7f1767e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 13:24:12 +0100 Subject: [PATCH 02/10] Return updated path from `HalfEdgeBuilder` method --- crates/fj-kernel/src/builder/edge.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index a740408b3..470ae4366 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -32,7 +32,7 @@ pub trait HalfEdgeBuilder { ); /// Update partial half-edge to be a line segment - fn update_as_line_segment(&mut self); + fn update_as_line_segment(&mut self) -> SurfacePath; /// Infer the global form of the half-edge /// @@ -130,10 +130,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { surface_form.position = Some(point.into()); } - self.update_as_line_segment() + self.update_as_line_segment(); } - fn update_as_line_segment(&mut self) { + fn update_as_line_segment(&mut self) -> SurfacePath { let boundary = self.vertices.each_ref_ext().map(|vertex| vertex.0); let points_surface = self.vertices.each_ref_ext().map(|vertex| { vertex @@ -143,15 +143,16 @@ impl HalfEdgeBuilder for PartialHalfEdge { .expect("Can't infer line segment without surface position") }); - if let [Some(start), Some(end)] = boundary { + let path = if let [Some(start), Some(end)] = boundary { let boundary = [start, end]; self.curve .write() .update_as_line_from_points_with_line_coords( boundary.zip_ext(points_surface), - ); + ) } else { - self.curve + let path = self + .curve .write() .update_as_line_from_points(points_surface); @@ -160,9 +161,13 @@ impl HalfEdgeBuilder for PartialHalfEdge { { vertex.0 = Some([position].into()); } - } + + path + }; self.infer_global_form(); + + path } fn infer_global_form(&mut self) -> Partial { From b8bf0bffec766761d1fa69570193270dec69e227 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 13:24:12 +0100 Subject: [PATCH 03/10] Return updated path from `HalfEdgeBuilder` method --- crates/fj-kernel/src/builder/edge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 470ae4366..9ee8cf907 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -29,7 +29,7 @@ pub trait HalfEdgeBuilder { fn update_as_line_segment_from_points( &mut self, points: [impl Into>; 2], - ); + ) -> SurfacePath; /// Update partial half-edge to be a line segment fn update_as_line_segment(&mut self) -> SurfacePath; @@ -124,13 +124,13 @@ impl HalfEdgeBuilder for PartialHalfEdge { fn update_as_line_segment_from_points( &mut self, points: [impl Into>; 2], - ) { + ) -> SurfacePath { for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) { let mut surface_form = vertex.1.write(); surface_form.position = Some(point.into()); } - self.update_as_line_segment(); + self.update_as_line_segment() } fn update_as_line_segment(&mut self) -> SurfacePath { From 9f6658ba7894cfbf865ecbb5c1866cc5c1859e39 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 14:20:14 +0100 Subject: [PATCH 04/10] Move `CurveBuilder::update_as_u_axis` --- crates/fj-kernel/src/builder/curve.rs | 11 ----------- crates/fj-kernel/src/builder/edge.rs | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 19916b222..607adb56d 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -4,11 +4,6 @@ use crate::{geometry::path::SurfacePath, partial::PartialCurve}; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { - /// Update partial curve to represent the u-axis of the surface it is on - /// - /// Returns the updated path. - fn update_as_u_axis(&mut self) -> SurfacePath; - /// Update partial curve to represent the v-axis of the surface it is on /// /// Returns the updated path. @@ -49,12 +44,6 @@ pub trait CurveBuilder { } impl CurveBuilder for PartialCurve { - fn update_as_u_axis(&mut self) -> SurfacePath { - let path = SurfacePath::u_axis(); - self.path = Some(path.into()); - path - } - fn update_as_v_axis(&mut self) -> SurfacePath { let path = SurfacePath::v_axis(); self.path = Some(path.into()); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 9ee8cf907..523a70e7a 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -14,6 +14,11 @@ use super::CurveBuilder; /// Builder API for [`PartialHalfEdge`] pub trait HalfEdgeBuilder { + /// Update partial half-edge to represent the u-axis of the surface it is on + /// + /// Returns the updated path. + fn update_as_u_axis(&mut self) -> SurfacePath; + /// Update partial half-edge to be a circle, from the given radius fn update_as_circle_from_radius(&mut self, radius: impl Into); @@ -63,6 +68,12 @@ pub trait HalfEdgeBuilder { } impl HalfEdgeBuilder for PartialHalfEdge { + fn update_as_u_axis(&mut self) -> SurfacePath { + let path = SurfacePath::u_axis(); + self.curve.write().path = Some(path.into()); + path + } + fn update_as_circle_from_radius(&mut self, radius: impl Into) { let path = self.curve.write().update_as_circle_from_radius(radius); From 25590438626094f1e91739cdda15a29c9656c8bd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 14:20:14 +0100 Subject: [PATCH 05/10] Move `CurveBuilder::update_as_v_axis` --- crates/fj-kernel/src/builder/curve.rs | 11 ----------- crates/fj-kernel/src/builder/edge.rs | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 607adb56d..d91864962 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -4,11 +4,6 @@ use crate::{geometry::path::SurfacePath, partial::PartialCurve}; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { - /// Update partial curve to represent the v-axis of the surface it is on - /// - /// Returns the updated path. - fn update_as_v_axis(&mut self) -> SurfacePath; - /// Update partial curve to be a circle, from the provided radius /// /// Returns the updated path. @@ -44,12 +39,6 @@ pub trait CurveBuilder { } impl CurveBuilder for PartialCurve { - fn update_as_v_axis(&mut self) -> SurfacePath { - let path = SurfacePath::v_axis(); - self.path = Some(path.into()); - path - } - fn update_as_circle_from_radius( &mut self, radius: impl Into, diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 523a70e7a..42cd7d241 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -19,6 +19,11 @@ pub trait HalfEdgeBuilder { /// Returns the updated path. fn update_as_u_axis(&mut self) -> SurfacePath; + /// Update partial curve to represent the v-axis of the surface it is on + /// + /// Returns the updated path. + fn update_as_v_axis(&mut self) -> SurfacePath; + /// Update partial half-edge to be a circle, from the given radius fn update_as_circle_from_radius(&mut self, radius: impl Into); @@ -74,6 +79,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { path } + fn update_as_v_axis(&mut self) -> SurfacePath { + let path = SurfacePath::v_axis(); + self.curve.write().path = Some(path.into()); + path + } + fn update_as_circle_from_radius(&mut self, radius: impl Into) { let path = self.curve.write().update_as_circle_from_radius(radius); From ea5704cebe82fe50fdc3dc703dd10b0e997bba66 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 13:24:12 +0100 Subject: [PATCH 06/10] Return updated path from `HalfEdgeBuilder` method --- crates/fj-kernel/src/builder/edge.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 42cd7d241..8ba3a42e5 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -25,7 +25,10 @@ pub trait HalfEdgeBuilder { fn update_as_v_axis(&mut self) -> SurfacePath; /// Update partial half-edge to be a circle, from the given radius - fn update_as_circle_from_radius(&mut self, radius: impl Into); + fn update_as_circle_from_radius( + &mut self, + radius: impl Into, + ) -> SurfacePath; /// Update partial half-edge to be an arc, spanning the given angle in /// radians @@ -85,7 +88,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { path } - fn update_as_circle_from_radius(&mut self, radius: impl Into) { + fn update_as_circle_from_radius( + &mut self, + radius: impl Into, + ) -> SurfacePath { let path = self.curve.write().update_as_circle_from_radius(radius); let [a_curve, b_curve] = @@ -107,6 +113,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { } self.infer_global_form(); + + path } fn update_as_arc(&mut self, angle_rad: impl Into) { From b3cc84608ae2eb93ffef03fc69ca3720f5cf3066 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 14:26:11 +0100 Subject: [PATCH 07/10] Inline `CurveBuilder` method --- crates/fj-kernel/src/builder/curve.rs | 17 ----------------- crates/fj-kernel/src/builder/edge.rs | 3 ++- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index d91864962..44717b563 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -4,14 +4,6 @@ use crate::{geometry::path::SurfacePath, partial::PartialCurve}; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { - /// Update partial curve to be a circle, from the provided radius - /// - /// Returns the updated path. - fn update_as_circle_from_radius( - &mut self, - radius: impl Into, - ) -> SurfacePath; - /// Update partial curve to be a circle, from the provided radius /// /// Returns the updated path. @@ -39,15 +31,6 @@ pub trait CurveBuilder { } impl CurveBuilder for PartialCurve { - fn update_as_circle_from_radius( - &mut self, - radius: impl Into, - ) -> SurfacePath { - let path = SurfacePath::circle_from_radius(radius); - self.path = Some(path.into()); - path - } - fn update_as_circle_from_center_and_radius( &mut self, center: impl Into>, diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 8ba3a42e5..3d31d7415 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -92,7 +92,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { &mut self, radius: impl Into, ) -> SurfacePath { - let path = self.curve.write().update_as_circle_from_radius(radius); + let path = SurfacePath::circle_from_radius(radius); + self.curve.write().path = Some(path.into()); let [a_curve, b_curve] = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); From b94f9a7ab0344327de1770025508cf53096031c7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 14:27:43 +0100 Subject: [PATCH 08/10] Inline `CurveBuilder` method --- crates/fj-kernel/src/builder/curve.rs | 21 +-------------------- crates/fj-kernel/src/builder/edge.rs | 7 +++---- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 44717b563..1f6dab6b3 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -1,18 +1,9 @@ -use fj_math::{Point, Scalar}; +use fj_math::Point; use crate::{geometry::path::SurfacePath, partial::PartialCurve}; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { - /// Update partial curve to be a circle, from the provided radius - /// - /// Returns the updated path. - fn update_as_circle_from_center_and_radius( - &mut self, - center: impl Into>, - radius: impl Into, - ) -> SurfacePath; - /// Update partial curve to be a line, from the provided points /// /// Returns the updated path. @@ -31,16 +22,6 @@ pub trait CurveBuilder { } impl CurveBuilder for PartialCurve { - fn update_as_circle_from_center_and_radius( - &mut self, - center: impl Into>, - radius: impl Into, - ) -> SurfacePath { - let path = SurfacePath::circle_from_center_and_radius(center, radius); - self.path = Some(path.into()); - path - } - fn update_as_line_from_points( &mut self, points: [impl Into>; 2], diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 3d31d7415..d28e5d48e 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -133,10 +133,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { let arc = fj_math::Arc::from_endpoints_and_angle(start, end, angle_rad); - let path = self - .curve - .write() - .update_as_circle_from_center_and_radius(arc.center, arc.radius); + let path = + SurfacePath::circle_from_center_and_radius(arc.center, arc.radius); + self.curve.write().path = Some(path.into()); let [a_curve, b_curve] = [arc.start_angle, arc.end_angle].map(|coord| Point::from([coord])); From 0df6ef2e3fa346cffa342f5fce330839c5e763bf Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 14:28:43 +0100 Subject: [PATCH 09/10] Inline `CurveBuilder::update_as_line_from_points` --- crates/fj-kernel/src/builder/curve.rs | 17 ----------------- crates/fj-kernel/src/builder/edge.rs | 6 ++---- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 1f6dab6b3..f9e5f3c50 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -4,14 +4,6 @@ use crate::{geometry::path::SurfacePath, partial::PartialCurve}; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { - /// Update partial curve to be a line, from the provided points - /// - /// Returns the updated path. - fn update_as_line_from_points( - &mut self, - points: [impl Into>; 2], - ) -> SurfacePath; - /// Update partial curve to be a line, from provided points and line coords /// /// Returns the updated path. @@ -22,15 +14,6 @@ pub trait CurveBuilder { } impl CurveBuilder for PartialCurve { - fn update_as_line_from_points( - &mut self, - points: [impl Into>; 2], - ) -> SurfacePath { - let (path, _) = SurfacePath::line_from_points(points); - self.path = Some(path.into()); - path - } - fn update_as_line_from_points_with_line_coords( &mut self, points: [(impl Into>, impl Into>); 2], diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index d28e5d48e..92f8d66a3 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -181,10 +181,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { boundary.zip_ext(points_surface), ) } else { - let path = self - .curve - .write() - .update_as_line_from_points(points_surface); + let (path, _) = SurfacePath::line_from_points(points_surface); + self.curve.write().path = Some(path.into()); for (vertex, position) in self.vertices.each_mut_ext().zip_ext([0., 1.]) From ff5b39483dc58c2a5e1bd42fec51bb4d4e651e98 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Feb 2023 14:34:00 +0100 Subject: [PATCH 10/10] Inline `CurveBuilder` method --- crates/fj-kernel/src/builder/curve.rs | 24 ++++-------------------- crates/fj-kernel/src/builder/edge.rs | 14 ++++++-------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index f9e5f3c50..dc35072ca 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -1,25 +1,9 @@ -use fj_math::Point; - -use crate::{geometry::path::SurfacePath, partial::PartialCurve}; +use crate::partial::PartialCurve; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { - /// Update partial curve to be a line, from provided points and line coords - /// - /// Returns the updated path. - fn update_as_line_from_points_with_line_coords( - &mut self, - points: [(impl Into>, impl Into>); 2], - ) -> SurfacePath; + // No methods are currently defined. This trait serves as a placeholder, to + // make it clear where to add such methods, once necessary. } -impl CurveBuilder for PartialCurve { - fn update_as_line_from_points_with_line_coords( - &mut self, - points: [(impl Into>, impl Into>); 2], - ) -> SurfacePath { - let path = SurfacePath::from_points_with_line_coords(points); - self.path = Some(path.into()); - path - } -} +impl CurveBuilder for PartialCurve {} diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 92f8d66a3..8812b6810 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -10,8 +10,6 @@ use crate::{ partial::{MaybeSurfacePath, Partial, PartialGlobalEdge, PartialHalfEdge}, }; -use super::CurveBuilder; - /// Builder API for [`PartialHalfEdge`] pub trait HalfEdgeBuilder { /// Update partial half-edge to represent the u-axis of the surface it is on @@ -174,12 +172,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { }); let path = if let [Some(start), Some(end)] = boundary { - let boundary = [start, end]; - self.curve - .write() - .update_as_line_from_points_with_line_coords( - boundary.zip_ext(points_surface), - ) + let points = [start, end].zip_ext(points_surface); + + let path = SurfacePath::from_points_with_line_coords(points); + self.curve.write().path = Some(path.into()); + + path } else { let (path, _) = SurfacePath::line_from_points(points_surface); self.curve.write().path = Some(path.into());