From bf084c952b4e8b0416ae6b9c665c2c500fa98f07 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 16 Dec 2022 16:23:19 +0100 Subject: [PATCH 1/6] Refactor --- crates/fj-kernel/src/builder/curve.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 9f03f186d..0e01c8352 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -37,6 +37,7 @@ impl CurveBuilder for PartialCurve { } fn update_as_line_from_points(&mut self, points: [impl Into>; 2]) { - self.path = Some(SurfacePath::line_from_points(points)); + let path = SurfacePath::line_from_points(points); + self.path = Some(path); } } From 57f42dd0397c636fb2f7642d775244cc344798b6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 16 Dec 2022 16:24:02 +0100 Subject: [PATCH 2/6] Return coords from `SurfacePath::line_from_points` --- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 2 +- crates/fj-kernel/src/builder/curve.rs | 2 +- crates/fj-kernel/src/geometry/path.rs | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index e9db52458..132280431 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -87,7 +87,7 @@ impl Sweep for (Handle, Handle) { // Armed with those coordinates, creating the `Curve` of the output // `Edge` is straight-forward. let curve = { - let path = SurfacePath::line_from_points(points_surface); + let (path, _) = SurfacePath::line_from_points(points_surface); Curve::new(surface.clone(), path, edge_global.curve().clone()) .insert(objects) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 0e01c8352..9eb520bd5 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -37,7 +37,7 @@ impl CurveBuilder for PartialCurve { } fn update_as_line_from_points(&mut self, points: [impl Into>; 2]) { - let path = SurfacePath::line_from_points(points); + let (path, _) = SurfacePath::line_from_points(points); self.path = Some(path); } } diff --git a/crates/fj-kernel/src/geometry/path.rs b/crates/fj-kernel/src/geometry/path.rs index 4bce78030..39bd8450e 100644 --- a/crates/fj-kernel/src/geometry/path.rs +++ b/crates/fj-kernel/src/geometry/path.rs @@ -43,9 +43,11 @@ impl SurfacePath { } /// Construct a line from two points - pub fn line_from_points(points: [impl Into>; 2]) -> Self { - let (line, _) = Line::from_points(points); - Self::Line(line) + pub fn line_from_points( + points: [impl Into>; 2], + ) -> (Self, [Point<1>; 2]) { + let (line, coords) = Line::from_points(points); + (Self::Line(line), coords) } /// Convert a point on the path into surface coordinates From a8a10c418dcf2f46555618905c2f52bd50549c60 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 16 Dec 2022 16:25:48 +0100 Subject: [PATCH 3/6] Return coords from `GlobalPath::line_from_points` --- crates/fj-kernel/src/builder/surface.rs | 2 +- crates/fj-kernel/src/geometry/path.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/surface.rs b/crates/fj-kernel/src/builder/surface.rs index 9a5bfb66e..fa94685e7 100644 --- a/crates/fj-kernel/src/builder/surface.rs +++ b/crates/fj-kernel/src/builder/surface.rs @@ -26,7 +26,7 @@ impl SurfaceBuilder for PartialSurface { fn plane_from_points(points: [impl Into>; 3]) -> Self { let [a, b, c] = points.map(Into::into); - let u = GlobalPath::line_from_points([a, b]); + let (u, _) = GlobalPath::line_from_points([a, b]); let v = c - a; Self { diff --git a/crates/fj-kernel/src/geometry/path.rs b/crates/fj-kernel/src/geometry/path.rs index 39bd8450e..2c1a0ed24 100644 --- a/crates/fj-kernel/src/geometry/path.rs +++ b/crates/fj-kernel/src/geometry/path.rs @@ -105,9 +105,11 @@ impl GlobalPath { } /// Construct a line from two points - pub fn line_from_points(points: [impl Into>; 2]) -> Self { - let (line, _) = Line::from_points(points); - Self::Line(line) + pub fn line_from_points( + points: [impl Into>; 2], + ) -> (Self, [Point<1>; 2]) { + let (line, coords) = Line::from_points(points); + (Self::Line(line), coords) } /// Access the origin of the path's coordinate system From 223802eadd5683c5a86202d7840c346b658dfc8f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 16 Dec 2022 16:24:36 +0100 Subject: [PATCH 4/6] Update doc comments --- crates/fj-kernel/src/geometry/path.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/fj-kernel/src/geometry/path.rs b/crates/fj-kernel/src/geometry/path.rs index 2c1a0ed24..d1cc59980 100644 --- a/crates/fj-kernel/src/geometry/path.rs +++ b/crates/fj-kernel/src/geometry/path.rs @@ -43,6 +43,8 @@ impl SurfacePath { } /// Construct a line from two points + /// + /// Also returns the coordinates of the points on the path. pub fn line_from_points( points: [impl Into>; 2], ) -> (Self, [Point<1>; 2]) { @@ -105,6 +107,8 @@ impl GlobalPath { } /// Construct a line from two points + /// + /// Also returns the coordinates of the points on the path. pub fn line_from_points( points: [impl Into>; 2], ) -> (Self, [Point<1>; 2]) { From 9a2c1681cf36e2f268e5424b7b19ba42d3b4b363 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 16 Dec 2022 16:50:55 +0100 Subject: [PATCH 5/6] Require `SurfaceBuilder` to be `Sized` This provides more flexibility in regards to use of `Self`. --- crates/fj-kernel/src/builder/surface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/surface.rs b/crates/fj-kernel/src/builder/surface.rs index fa94685e7..dc0b8db40 100644 --- a/crates/fj-kernel/src/builder/surface.rs +++ b/crates/fj-kernel/src/builder/surface.rs @@ -6,7 +6,7 @@ use crate::{ }; /// Builder API for [`PartialSurface`] -pub trait SurfaceBuilder { +pub trait SurfaceBuilder: Sized { /// Build a surface from its two axes fn from_axes(u: GlobalPath, v: impl Into>) -> Self; From bedf2fd14e102854d9f959ce8cbbc62800a5a8fd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 16 Dec 2022 16:55:42 +0100 Subject: [PATCH 6/6] Return coords from `SurfaceBuilder` method --- crates/fj-kernel/src/builder/shell.rs | 3 ++- crates/fj-kernel/src/builder/surface.rs | 27 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 75bc79f49..1e2006ba5 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -67,7 +67,8 @@ impl ShellBuilder for PartialShell { }); let c = a + [Z, Z, edge_length]; - let surface = PartialSurface::plane_from_points([a, b, c]); + let (surface, _) = + PartialSurface::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 dc0b8db40..54f1efcdd 100644 --- a/crates/fj-kernel/src/builder/surface.rs +++ b/crates/fj-kernel/src/builder/surface.rs @@ -1,4 +1,4 @@ -use fj_math::{Point, Vector}; +use fj_math::{Point, Scalar, Vector}; use crate::{ geometry::{path::GlobalPath, surface::SurfaceGeometry}, @@ -11,7 +11,9 @@ pub trait SurfaceBuilder: Sized { fn from_axes(u: GlobalPath, v: impl Into>) -> Self; /// Construct a plane from 3 points - fn plane_from_points(points: [impl Into>; 3]) -> Self; + fn plane_from_points( + points: [impl Into>; 3], + ) -> (Self, [Point<2>; 3]); } impl SurfaceBuilder for PartialSurface { @@ -23,14 +25,25 @@ impl SurfaceBuilder for PartialSurface { } } - fn plane_from_points(points: [impl Into>; 3]) -> Self { + fn plane_from_points( + points: [impl Into>; 3], + ) -> (Self, [Point<2>; 3]) { let [a, b, c] = points.map(Into::into); - let (u, _) = GlobalPath::line_from_points([a, b]); + let (u, u_coords) = GlobalPath::line_from_points([a, b]); let v = c - a; - Self { - geometry: Some(SurfaceGeometry { u, v }), - } + 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, + ) } }