From 959735e223db392336c5d2d67e43aa17c7853de7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 14 Sep 2022 12:53:20 +0200 Subject: [PATCH 1/7] Update nomenclature in doc comments They are builders. They build. --- crates/fj-kernel/src/builder/curve.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index b51858ae9..d4e079821 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -18,7 +18,7 @@ impl CurveBuilder { Self { surface } } - /// Create a line that represents the u-axis on the surface + /// Build a line that represents the u-axis on the surface pub fn u_axis(&self) -> Curve { let a = Point::origin(); let b = a + Vector::unit_u(); @@ -26,7 +26,7 @@ impl CurveBuilder { self.line_from_points([a, b]) } - /// Create a line that represents the v-axis on the surface + /// Build a line that represents the v-axis on the surface pub fn v_axis(&self) -> Curve { let a = Point::origin(); let b = a + Vector::unit_v(); @@ -34,7 +34,7 @@ impl CurveBuilder { self.line_from_points([a, b]) } - /// Create a line from the given points + /// Build a line from the given points pub fn line_from_points(&self, points: [impl Into>; 2]) -> Curve { let points = points.map(Into::into); @@ -55,17 +55,17 @@ impl CurveBuilder { pub struct GlobalCurveBuilder; impl GlobalCurveBuilder { - /// Create a line that represents the x-axis + /// Build a line that represents the x-axis pub fn x_axis(&self) -> GlobalCurve { GlobalCurve::from_path(GlobalPath::x_axis()) } - /// Create a line that represents the y-axis + /// Build a line that represents the y-axis pub fn y_axis(&self) -> GlobalCurve { GlobalCurve::from_path(GlobalPath::y_axis()) } - /// Create a line that represents the z-axis + /// Build a line that represents the z-axis pub fn z_axis(&self) -> GlobalCurve { GlobalCurve::from_path(GlobalPath::z_axis()) } From 359befce1c6c8040474e75ad158ade247c9f7b53 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 14 Sep 2022 12:55:02 +0200 Subject: [PATCH 2/7] Make method more convenient to call --- crates/fj-kernel/src/builder/edge.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index d2340292e..144d07411 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -22,7 +22,9 @@ impl HalfEdgeBuilder { } /// Build a circle from the given radius - pub fn circle_from_radius(&self, radius: Scalar) -> HalfEdge { + pub fn circle_from_radius(&self, radius: impl Into) -> HalfEdge { + let radius = radius.into(); + let curve = { let path = SurfacePath::Circle(Circle::new( Point::origin(), From fbb4f1147a58d0e6b777a2889b6f83314e398094 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 14 Sep 2022 12:57:06 +0200 Subject: [PATCH 3/7] Add `CurveBuilder::circle_from_radius` --- crates/fj-kernel/src/builder/curve.rs | 21 ++++++++++++++++++++- crates/fj-kernel/src/builder/edge.rs | 20 ++------------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index d4e079821..c14d65c5f 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -1,4 +1,4 @@ -use fj_math::{Line, Point, Vector}; +use fj_math::{Circle, Line, Point, Scalar, Vector}; use crate::{ objects::{Curve, GlobalCurve, Surface}, @@ -34,6 +34,25 @@ impl CurveBuilder { self.line_from_points([a, b]) } + /// Build a circle from the given radius + pub fn circle_from_radius(&self, radius: impl Into) -> Curve { + let radius = radius.into(); + + let path = SurfacePath::Circle(Circle::new( + Point::origin(), + Vector::from([radius, Scalar::ZERO]), + Vector::from([Scalar::ZERO, radius]), + )); + let global_form = + GlobalCurve::from_path(GlobalPath::Circle(Circle::new( + Point::origin(), + Vector::from([radius, Scalar::ZERO, Scalar::ZERO]), + Vector::from([Scalar::ZERO, radius, Scalar::ZERO]), + ))); + + Curve::new(self.surface, path, global_form) + } + /// Build a line from the given points pub fn line_from_points(&self, points: [impl Into>; 2]) -> Curve { let points = points.map(Into::into); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 144d07411..0c53e87fe 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -1,4 +1,4 @@ -use fj_math::{Circle, Line, Point, Scalar, Vector}; +use fj_math::{Line, Point, Scalar}; use crate::{ objects::{ @@ -23,23 +23,7 @@ impl HalfEdgeBuilder { /// Build a circle from the given radius pub fn circle_from_radius(&self, radius: impl Into) -> HalfEdge { - let radius = radius.into(); - - let curve = { - let path = SurfacePath::Circle(Circle::new( - Point::origin(), - Vector::from([radius, Scalar::ZERO]), - Vector::from([Scalar::ZERO, radius]), - )); - let global = - GlobalCurve::from_path(GlobalPath::Circle(Circle::new( - Point::origin(), - Vector::from([radius, Scalar::ZERO, Scalar::ZERO]), - Vector::from([Scalar::ZERO, radius, Scalar::ZERO]), - ))); - - Curve::new(self.surface, path, global) - }; + let curve = Curve::build(self.surface).circle_from_radius(radius); let vertices = { let [a_curve, b_curve] = From b3fd94af9200aaf2662d07cc15d106243c8060c7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 14 Sep 2022 13:00:05 +0200 Subject: [PATCH 4/7] Add `GlobalCurveBuilder::circle_from_radius` --- crates/fj-kernel/src/builder/curve.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index c14d65c5f..32fde0ef8 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -43,12 +43,7 @@ impl CurveBuilder { Vector::from([radius, Scalar::ZERO]), Vector::from([Scalar::ZERO, radius]), )); - let global_form = - GlobalCurve::from_path(GlobalPath::Circle(Circle::new( - Point::origin(), - Vector::from([radius, Scalar::ZERO, Scalar::ZERO]), - Vector::from([Scalar::ZERO, radius, Scalar::ZERO]), - ))); + let global_form = GlobalCurveBuilder.circle_from_radius(radius); Curve::new(self.surface, path, global_form) } @@ -89,6 +84,17 @@ impl GlobalCurveBuilder { GlobalCurve::from_path(GlobalPath::z_axis()) } + /// Build a circle from the given radius + pub fn circle_from_radius(&self, radius: impl Into) -> GlobalCurve { + let radius = radius.into(); + + GlobalCurve::from_path(GlobalPath::Circle(Circle::new( + Point::origin(), + Vector::from([radius, Scalar::ZERO, Scalar::ZERO]), + Vector::from([Scalar::ZERO, radius, Scalar::ZERO]), + ))) + } + /// Create a line from the given points pub fn line_from_points( &self, From 9ec6e46211c94fe8babb07987d55d29b66e08827 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 14 Sep 2022 13:01:56 +0200 Subject: [PATCH 5/7] Add `SurfacePath::circle_from_radius` --- crates/fj-kernel/src/builder/curve.rs | 6 +----- crates/fj-kernel/src/path.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 32fde0ef8..b2801c5ff 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -38,11 +38,7 @@ impl CurveBuilder { pub fn circle_from_radius(&self, radius: impl Into) -> Curve { let radius = radius.into(); - let path = SurfacePath::Circle(Circle::new( - Point::origin(), - Vector::from([radius, Scalar::ZERO]), - Vector::from([Scalar::ZERO, radius]), - )); + let path = SurfacePath::circle_from_radius(radius); let global_form = GlobalCurveBuilder.circle_from_radius(radius); Curve::new(self.surface, path, global_form) diff --git a/crates/fj-kernel/src/path.rs b/crates/fj-kernel/src/path.rs index de796d118..4ec64f1b9 100644 --- a/crates/fj-kernel/src/path.rs +++ b/crates/fj-kernel/src/path.rs @@ -22,7 +22,7 @@ //! [`Surface`]: crate::objects::Surface //! [#1021]: https://github.com/hannobraun/Fornjot/issues/1021 -use fj_math::{Circle, Line, Point, Vector}; +use fj_math::{Circle, Line, Point, Scalar, Vector}; /// A path through surface (2D) space #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] @@ -35,6 +35,17 @@ pub enum SurfacePath { } impl SurfacePath { + /// Build a circle from the given radius + pub fn circle_from_radius(radius: impl Into) -> Self { + let radius = radius.into(); + + SurfacePath::Circle(Circle::new( + Point::origin(), + Vector::from([radius, Scalar::ZERO]), + Vector::from([Scalar::ZERO, radius]), + )) + } + /// Construct a line from two points pub fn line_from_points(points: [impl Into>; 2]) -> Self { Self::Line(Line::from_points(points)) From 02241f98b4c21b7e8bdb0820b19747934307a260 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 14 Sep 2022 13:03:37 +0200 Subject: [PATCH 6/7] Add `GlobalPath::circle_from_radius` --- crates/fj-kernel/src/builder/curve.rs | 11 +++-------- crates/fj-kernel/src/path.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index b2801c5ff..21783fc2a 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -1,4 +1,4 @@ -use fj_math::{Circle, Line, Point, Scalar, Vector}; +use fj_math::{Line, Point, Scalar, Vector}; use crate::{ objects::{Curve, GlobalCurve, Surface}, @@ -82,13 +82,8 @@ impl GlobalCurveBuilder { /// Build a circle from the given radius pub fn circle_from_radius(&self, radius: impl Into) -> GlobalCurve { - let radius = radius.into(); - - GlobalCurve::from_path(GlobalPath::Circle(Circle::new( - Point::origin(), - Vector::from([radius, Scalar::ZERO, Scalar::ZERO]), - Vector::from([Scalar::ZERO, radius, Scalar::ZERO]), - ))) + let path = GlobalPath::circle_from_radius(radius); + GlobalCurve::from_path(path) } /// Create a line from the given points diff --git a/crates/fj-kernel/src/path.rs b/crates/fj-kernel/src/path.rs index 4ec64f1b9..739063a2e 100644 --- a/crates/fj-kernel/src/path.rs +++ b/crates/fj-kernel/src/path.rs @@ -103,6 +103,17 @@ impl GlobalPath { )) } + /// Build a circle from the given radius + pub fn circle_from_radius(radius: impl Into) -> Self { + let radius = radius.into(); + + GlobalPath::Circle(Circle::new( + Point::origin(), + Vector::from([radius, Scalar::ZERO, Scalar::ZERO]), + Vector::from([Scalar::ZERO, radius, Scalar::ZERO]), + )) + } + /// Access the origin of the path's coordinate system pub fn origin(&self) -> Point<3> { match self { From 691e7d6ecc8dfaff03b97c4a99b5bf92c406f145 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 14 Sep 2022 13:08:36 +0200 Subject: [PATCH 7/7] Make order of methods consistent with other types --- crates/fj-kernel/src/path.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/path.rs b/crates/fj-kernel/src/path.rs index 739063a2e..2515bc0a3 100644 --- a/crates/fj-kernel/src/path.rs +++ b/crates/fj-kernel/src/path.rs @@ -74,11 +74,6 @@ pub enum GlobalPath { } impl GlobalPath { - /// Construct a line from two points - pub fn line_from_points(points: [impl Into>; 2]) -> Self { - Self::Line(Line::from_points(points)) - } - /// Construct a `GlobalPath` that represents the x-axis pub fn x_axis() -> Self { Self::Line(Line::from_origin_and_direction( @@ -114,6 +109,11 @@ impl GlobalPath { )) } + /// Construct a line from two points + pub fn line_from_points(points: [impl Into>; 2]) -> Self { + Self::Line(Line::from_points(points)) + } + /// Access the origin of the path's coordinate system pub fn origin(&self) -> Point<3> { match self {