From a8a03748c8dc219c2344bd80e30b2b9c9db589d8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 20 May 2022 13:52:57 +0200 Subject: [PATCH 1/3] Make test-only method available in general --- crates/fj-kernel/src/geometry/surfaces/swept.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index ca5bdfd2a..9f09272e9 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -14,7 +14,6 @@ pub struct SweptCurve { impl SweptCurve { /// Construct a plane from 3 points - #[cfg(test)] pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self { let curve = Curve::Line(Line::from_points([a, b])); let path = c - a; From 6ffb7497e3a70d6e830bf384ed95b75ce0811f93 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 20 May 2022 13:54:25 +0200 Subject: [PATCH 2/3] Move method to make API more ergonomic --- crates/fj-kernel/src/algorithms/sweep.rs | 5 ++--- crates/fj-kernel/src/geometry/surfaces/mod.rs | 10 +++++++++- crates/fj-kernel/src/geometry/surfaces/swept.rs | 8 -------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index d93883c01..3dad26b5d 100644 --- a/crates/fj-kernel/src/algorithms/sweep.rs +++ b/crates/fj-kernel/src/algorithms/sweep.rs @@ -154,7 +154,7 @@ mod tests { use crate::{ algorithms::Tolerance, - geometry::{Surface, SweptCurve}, + geometry::Surface, shape::{Handle, Shape}, topology::{Cycle, Edge, Face}, }; @@ -230,8 +230,7 @@ mod tests { let cycles = shape.insert(Cycle::new(vec![ab, bc, ca]))?; - let surface = - Surface::SweptCurve(SweptCurve::plane_from_points([a, b, c])); + let surface = Surface::plane_from_points([a, b, c]); let surface = if reverse { surface.reverse() } else { surface }; let surface = shape.insert(surface)?; diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index b71a5dc77..0a8b0ab08 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -2,7 +2,7 @@ pub mod swept; pub use self::swept::SweptCurve; -use fj_math::{Point, Transform, Vector}; +use fj_math::{Line, Point, Transform, Vector}; use crate::geometry; @@ -40,6 +40,14 @@ impl Surface { }) } + /// Construct a plane from 3 points + pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self { + let curve = Curve::Line(Line::from_points([a, b])); + let path = c - a; + + Self::SweptCurve(SweptCurve { curve, path }) + } + /// Create a new instance that is reversed #[must_use] pub fn reverse(self) -> Self { diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index 9f09272e9..d3458126f 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -13,14 +13,6 @@ pub struct SweptCurve { } impl SweptCurve { - /// Construct a plane from 3 points - pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self { - let curve = Curve::Line(Line::from_points([a, b])); - let path = c - a; - - Self { curve, path } - } - /// Create a new instance that is reversed #[must_use] pub fn reverse(mut self) -> Self { From 58f6b086e8fe4afafad5f00f514681c5cdd8d3cf Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 20 May 2022 14:15:18 +0200 Subject: [PATCH 3/3] Make `Surface::plane_from_points` easier to call --- crates/fj-kernel/src/geometry/surfaces/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index 0a8b0ab08..219864dcd 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -41,7 +41,9 @@ impl Surface { } /// Construct a plane from 3 points - pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self { + pub fn plane_from_points(points: [impl Into>; 3]) -> Self { + let [a, b, c] = points.map(Into::into); + let curve = Curve::Line(Line::from_points([a, b])); let path = c - a;