From 61846656927eea1f4a562ca188a06a9eae67027e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 12:43:37 +0200 Subject: [PATCH 01/12] Improve method name --- crates/fj-kernel/src/geometry/curves/circle.rs | 10 +++++----- crates/fj-kernel/src/geometry/curves/mod.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/geometry/curves/circle.rs b/crates/fj-kernel/src/geometry/curves/circle.rs index bb19f0d1d..c84ba1bc1 100644 --- a/crates/fj-kernel/src/geometry/curves/circle.rs +++ b/crates/fj-kernel/src/geometry/curves/circle.rs @@ -55,7 +55,7 @@ impl Circle { /// Callers are advised to be careful about the points they pass, as the /// point not being on the curve, intentional or not, will not result in an /// error. - pub fn point_model_to_curve(&self, point: &Point<3>) -> Point<1> { + pub fn point_to_circle_coords(&self, point: &Point<3>) -> Point<1> { let v = point - self.center; let atan = Scalar::atan2(v.y, v.x); let coord = if atan >= Scalar::ZERO { @@ -97,19 +97,19 @@ mod tests { }; assert_eq!( - circle.point_model_to_curve(&Point::from([2., 2., 3.])), + circle.point_to_circle_coords(&Point::from([2., 2., 3.])), Point::from([0.]), ); assert_eq!( - circle.point_model_to_curve(&Point::from([1., 3., 3.])), + circle.point_to_circle_coords(&Point::from([1., 3., 3.])), Point::from([FRAC_PI_2]), ); assert_eq!( - circle.point_model_to_curve(&Point::from([0., 2., 3.])), + circle.point_to_circle_coords(&Point::from([0., 2., 3.])), Point::from([PI]), ); assert_eq!( - circle.point_model_to_curve(&Point::from([1., 1., 3.])), + circle.point_to_circle_coords(&Point::from([1., 1., 3.])), Point::from([FRAC_PI_2 * 3.]), ); } diff --git a/crates/fj-kernel/src/geometry/curves/mod.rs b/crates/fj-kernel/src/geometry/curves/mod.rs index f2f59ef16..15afa3ffe 100644 --- a/crates/fj-kernel/src/geometry/curves/mod.rs +++ b/crates/fj-kernel/src/geometry/curves/mod.rs @@ -84,7 +84,7 @@ impl Curve { /// an error. pub fn point_model_to_curve(&self, point: &Point<3>) -> Point<1> { match self { - Self::Circle(curve) => curve.point_model_to_curve(point), + Self::Circle(curve) => curve.point_to_circle_coords(point), Self::Line(curve) => curve.point_to_line_coords(*point), } } From e6ad974f2eb28a2ddec848128b1abba4b7915a4d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 12:44:03 +0200 Subject: [PATCH 02/12] Improve method name --- crates/fj-kernel/src/algorithms/approx/curves.rs | 2 +- crates/fj-kernel/src/geometry/curves/circle.rs | 2 +- crates/fj-kernel/src/geometry/curves/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curves.rs b/crates/fj-kernel/src/algorithms/approx/curves.rs index 6e3d7e88c..5df41fcd1 100644 --- a/crates/fj-kernel/src/algorithms/approx/curves.rs +++ b/crates/fj-kernel/src/algorithms/approx/curves.rs @@ -52,7 +52,7 @@ pub fn approx_circle( for i in 0..n { let angle = Scalar::PI * 2. / n as f64 * i as f64; - let point = circle.point_curve_to_model(&Point::from([angle])); + let point = circle.point_from_circle_coords(&Point::from([angle])); out.push(point); } } diff --git a/crates/fj-kernel/src/geometry/curves/circle.rs b/crates/fj-kernel/src/geometry/curves/circle.rs index c84ba1bc1..fc34ddd4e 100644 --- a/crates/fj-kernel/src/geometry/curves/circle.rs +++ b/crates/fj-kernel/src/geometry/curves/circle.rs @@ -67,7 +67,7 @@ impl Circle { } /// Convert a point on the curve into model coordinates - pub fn point_curve_to_model(&self, point: &Point<1>) -> Point<3> { + pub fn point_from_circle_coords(&self, point: &Point<1>) -> Point<3> { self.center + self.vector_curve_to_model(&point.coords) } diff --git a/crates/fj-kernel/src/geometry/curves/mod.rs b/crates/fj-kernel/src/geometry/curves/mod.rs index 15afa3ffe..9d71ba3fa 100644 --- a/crates/fj-kernel/src/geometry/curves/mod.rs +++ b/crates/fj-kernel/src/geometry/curves/mod.rs @@ -92,7 +92,7 @@ impl Curve { /// Convert a point on the curve into model coordinates pub fn point_curve_to_model(&self, point: &Point<1>) -> Point<3> { match self { - Self::Circle(curve) => curve.point_curve_to_model(point), + Self::Circle(curve) => curve.point_from_circle_coords(point), Self::Line(curve) => curve.point_from_line_coords(*point), } } From eae339cc8372599e2452eadee8b2b0d7835cacdd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 12:44:26 +0200 Subject: [PATCH 03/12] Improve method name --- crates/fj-kernel/src/geometry/curves/circle.rs | 4 ++-- crates/fj-kernel/src/geometry/curves/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/geometry/curves/circle.rs b/crates/fj-kernel/src/geometry/curves/circle.rs index fc34ddd4e..99df8e4bf 100644 --- a/crates/fj-kernel/src/geometry/curves/circle.rs +++ b/crates/fj-kernel/src/geometry/curves/circle.rs @@ -68,11 +68,11 @@ impl Circle { /// Convert a point on the curve into model coordinates pub fn point_from_circle_coords(&self, point: &Point<1>) -> Point<3> { - self.center + self.vector_curve_to_model(&point.coords) + self.center + self.vector_from_circle_coords(&point.coords) } /// Convert a vector on the curve into model coordinates - pub fn vector_curve_to_model(&self, vector: &Vector<1>) -> Vector<3> { + pub fn vector_from_circle_coords(&self, vector: &Vector<1>) -> Vector<3> { let angle = vector.t; let (sin, cos) = angle.sin_cos(); diff --git a/crates/fj-kernel/src/geometry/curves/mod.rs b/crates/fj-kernel/src/geometry/curves/mod.rs index 9d71ba3fa..0de412f4b 100644 --- a/crates/fj-kernel/src/geometry/curves/mod.rs +++ b/crates/fj-kernel/src/geometry/curves/mod.rs @@ -100,7 +100,7 @@ impl Curve { /// Convert a vector on the curve into model coordinates pub fn vector_curve_to_model(&self, point: &Vector<1>) -> Vector<3> { match self { - Self::Circle(curve) => curve.vector_curve_to_model(point), + Self::Circle(curve) => curve.vector_from_circle_coords(point), Self::Line(curve) => curve.vector_from_line_coords(*point), } } From d072403e4c2be19f0db994c742df74ef5d90c817 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 12:46:22 +0200 Subject: [PATCH 04/12] Make `Circle` conversion methods easier to call --- .../fj-kernel/src/algorithms/approx/curves.rs | 2 +- .../fj-kernel/src/geometry/curves/circle.rs | 29 ++++++++++++------- crates/fj-kernel/src/geometry/curves/mod.rs | 6 ++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/approx/curves.rs b/crates/fj-kernel/src/algorithms/approx/curves.rs index 5df41fcd1..1d76078f9 100644 --- a/crates/fj-kernel/src/algorithms/approx/curves.rs +++ b/crates/fj-kernel/src/algorithms/approx/curves.rs @@ -52,7 +52,7 @@ pub fn approx_circle( for i in 0..n { let angle = Scalar::PI * 2. / n as f64 * i as f64; - let point = circle.point_from_circle_coords(&Point::from([angle])); + let point = circle.point_from_circle_coords([angle]); out.push(point); } } diff --git a/crates/fj-kernel/src/geometry/curves/circle.rs b/crates/fj-kernel/src/geometry/curves/circle.rs index 99df8e4bf..a82609e94 100644 --- a/crates/fj-kernel/src/geometry/curves/circle.rs +++ b/crates/fj-kernel/src/geometry/curves/circle.rs @@ -55,8 +55,11 @@ impl Circle { /// Callers are advised to be careful about the points they pass, as the /// point not being on the curve, intentional or not, will not result in an /// error. - pub fn point_to_circle_coords(&self, point: &Point<3>) -> Point<1> { - let v = point - self.center; + pub fn point_to_circle_coords( + &self, + point: impl Into>, + ) -> Point<1> { + let v = point.into() - self.center; let atan = Scalar::atan2(v.y, v.x); let coord = if atan >= Scalar::ZERO { atan @@ -67,13 +70,19 @@ impl Circle { } /// Convert a point on the curve into model coordinates - pub fn point_from_circle_coords(&self, point: &Point<1>) -> Point<3> { - self.center + self.vector_from_circle_coords(&point.coords) + pub fn point_from_circle_coords( + &self, + point: impl Into>, + ) -> Point<3> { + self.center + self.vector_from_circle_coords(point.into().coords) } /// Convert a vector on the curve into model coordinates - pub fn vector_from_circle_coords(&self, vector: &Vector<1>) -> Vector<3> { - let angle = vector.t; + pub fn vector_from_circle_coords( + &self, + vector: impl Into>, + ) -> Vector<3> { + let angle = vector.into().t; let (sin, cos) = angle.sin_cos(); self.a * cos + self.b * sin @@ -97,19 +106,19 @@ mod tests { }; assert_eq!( - circle.point_to_circle_coords(&Point::from([2., 2., 3.])), + circle.point_to_circle_coords([2., 2., 3.]), Point::from([0.]), ); assert_eq!( - circle.point_to_circle_coords(&Point::from([1., 3., 3.])), + circle.point_to_circle_coords([1., 3., 3.]), Point::from([FRAC_PI_2]), ); assert_eq!( - circle.point_to_circle_coords(&Point::from([0., 2., 3.])), + circle.point_to_circle_coords([0., 2., 3.]), Point::from([PI]), ); assert_eq!( - circle.point_to_circle_coords(&Point::from([1., 1., 3.])), + circle.point_to_circle_coords([1., 1., 3.]), Point::from([FRAC_PI_2 * 3.]), ); } diff --git a/crates/fj-kernel/src/geometry/curves/mod.rs b/crates/fj-kernel/src/geometry/curves/mod.rs index 0de412f4b..81dce383b 100644 --- a/crates/fj-kernel/src/geometry/curves/mod.rs +++ b/crates/fj-kernel/src/geometry/curves/mod.rs @@ -84,7 +84,7 @@ impl Curve { /// an error. pub fn point_model_to_curve(&self, point: &Point<3>) -> Point<1> { match self { - Self::Circle(curve) => curve.point_to_circle_coords(point), + Self::Circle(curve) => curve.point_to_circle_coords(*point), Self::Line(curve) => curve.point_to_line_coords(*point), } } @@ -92,7 +92,7 @@ impl Curve { /// Convert a point on the curve into model coordinates pub fn point_curve_to_model(&self, point: &Point<1>) -> Point<3> { match self { - Self::Circle(curve) => curve.point_from_circle_coords(point), + Self::Circle(curve) => curve.point_from_circle_coords(*point), Self::Line(curve) => curve.point_from_line_coords(*point), } } @@ -100,7 +100,7 @@ impl Curve { /// Convert a vector on the curve into model coordinates pub fn vector_curve_to_model(&self, point: &Vector<1>) -> Vector<3> { match self { - Self::Circle(curve) => curve.vector_from_circle_coords(point), + Self::Circle(curve) => curve.vector_from_circle_coords(*point), Self::Line(curve) => curve.vector_from_line_coords(*point), } } From feaa65db0314e7ced9c14d2f38c2b992779c1922 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 12:47:01 +0200 Subject: [PATCH 05/12] Improve method name --- crates/fj-kernel/src/geometry/curves/mod.rs | 2 +- crates/fj-kernel/src/geometry/surfaces/swept.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/geometry/curves/mod.rs b/crates/fj-kernel/src/geometry/curves/mod.rs index 81dce383b..0115b6ce2 100644 --- a/crates/fj-kernel/src/geometry/curves/mod.rs +++ b/crates/fj-kernel/src/geometry/curves/mod.rs @@ -82,7 +82,7 @@ impl Curve { /// Callers are advised to be careful about the points they pass, as the /// point not being on the curve, intentional or not, will never result in /// an error. - pub fn point_model_to_curve(&self, point: &Point<3>) -> Point<1> { + pub fn point_to_curve_coords(&self, point: &Point<3>) -> Point<1> { match self { Self::Circle(curve) => curve.point_to_circle_coords(*point), Self::Line(curve) => curve.point_to_line_coords(*point), diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index 0f66159a5..a9707eb91 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -42,7 +42,7 @@ impl SweptCurve { &self, point: &Point<3>, ) -> Point<2> { - let u = self.curve.point_model_to_curve(point).t; + let u = self.curve.point_to_curve_coords(point).t; let v = { let line = Line { origin: self.curve.origin(), From c43f953ce6377399fc2308f678d88a49e6dfdefc Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 12:47:21 +0200 Subject: [PATCH 06/12] Improve method name --- crates/fj-kernel/src/geometry/curves/mod.rs | 2 +- crates/fj-kernel/src/geometry/surfaces/swept.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/geometry/curves/mod.rs b/crates/fj-kernel/src/geometry/curves/mod.rs index 0115b6ce2..98266662a 100644 --- a/crates/fj-kernel/src/geometry/curves/mod.rs +++ b/crates/fj-kernel/src/geometry/curves/mod.rs @@ -90,7 +90,7 @@ impl Curve { } /// Convert a point on the curve into model coordinates - pub fn point_curve_to_model(&self, point: &Point<1>) -> Point<3> { + pub fn point_from_curve_coords(&self, point: &Point<1>) -> Point<3> { match self { Self::Circle(curve) => curve.point_from_circle_coords(*point), Self::Line(curve) => curve.point_from_line_coords(*point), diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index a9707eb91..3771264e1 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -60,7 +60,7 @@ impl SweptCurve { &self, point: &Point<2>, ) -> Point<3> { - self.curve.point_curve_to_model(&point.to_t()) + self.path * point.v + self.curve.point_from_curve_coords(&point.to_t()) + self.path * point.v } /// Convert a vector in surface coordinates to model coordinates From 993425be88220bcb3dfa8a2514f2a1758fe130e6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 12:47:39 +0200 Subject: [PATCH 07/12] Improve method name --- crates/fj-kernel/src/geometry/curves/mod.rs | 2 +- crates/fj-kernel/src/geometry/surfaces/swept.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/geometry/curves/mod.rs b/crates/fj-kernel/src/geometry/curves/mod.rs index 98266662a..7f9c99507 100644 --- a/crates/fj-kernel/src/geometry/curves/mod.rs +++ b/crates/fj-kernel/src/geometry/curves/mod.rs @@ -98,7 +98,7 @@ impl Curve { } /// Convert a vector on the curve into model coordinates - pub fn vector_curve_to_model(&self, point: &Vector<1>) -> Vector<3> { + pub fn vector_from_curve_coords(&self, point: &Vector<1>) -> Vector<3> { match self { Self::Circle(curve) => curve.vector_from_circle_coords(*point), Self::Line(curve) => curve.vector_from_line_coords(*point), diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index 3771264e1..e00d37a36 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -68,7 +68,8 @@ impl SweptCurve { &self, vector: &Vector<2>, ) -> Vector<3> { - self.curve.vector_curve_to_model(&vector.to_t()) + self.path * vector.v + self.curve.vector_from_curve_coords(&vector.to_t()) + + self.path * vector.v } } From 8ce04c819023f5e3f25354d687823be6798137be Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 12:50:27 +0200 Subject: [PATCH 08/12] Make `Curve` conversion methods easier to call --- crates/fj-kernel/src/geometry/curves/mod.rs | 27 ++++++++++++------- .../fj-kernel/src/geometry/surfaces/swept.rs | 7 +++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/crates/fj-kernel/src/geometry/curves/mod.rs b/crates/fj-kernel/src/geometry/curves/mod.rs index 7f9c99507..9c7c34d51 100644 --- a/crates/fj-kernel/src/geometry/curves/mod.rs +++ b/crates/fj-kernel/src/geometry/curves/mod.rs @@ -82,26 +82,35 @@ impl Curve { /// Callers are advised to be careful about the points they pass, as the /// point not being on the curve, intentional or not, will never result in /// an error. - pub fn point_to_curve_coords(&self, point: &Point<3>) -> Point<1> { + pub fn point_to_curve_coords( + &self, + point: impl Into>, + ) -> Point<1> { match self { - Self::Circle(curve) => curve.point_to_circle_coords(*point), - Self::Line(curve) => curve.point_to_line_coords(*point), + Self::Circle(curve) => curve.point_to_circle_coords(point), + Self::Line(curve) => curve.point_to_line_coords(point), } } /// Convert a point on the curve into model coordinates - pub fn point_from_curve_coords(&self, point: &Point<1>) -> Point<3> { + pub fn point_from_curve_coords( + &self, + point: impl Into>, + ) -> Point<3> { match self { - Self::Circle(curve) => curve.point_from_circle_coords(*point), - Self::Line(curve) => curve.point_from_line_coords(*point), + Self::Circle(curve) => curve.point_from_circle_coords(point), + Self::Line(curve) => curve.point_from_line_coords(point), } } /// Convert a vector on the curve into model coordinates - pub fn vector_from_curve_coords(&self, point: &Vector<1>) -> Vector<3> { + pub fn vector_from_curve_coords( + &self, + point: impl Into>, + ) -> Vector<3> { match self { - Self::Circle(curve) => curve.vector_from_circle_coords(*point), - Self::Line(curve) => curve.vector_from_line_coords(*point), + Self::Circle(curve) => curve.vector_from_circle_coords(point), + Self::Line(curve) => curve.vector_from_line_coords(point), } } } diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index e00d37a36..45af8069d 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -42,7 +42,7 @@ impl SweptCurve { &self, point: &Point<3>, ) -> Point<2> { - let u = self.curve.point_to_curve_coords(point).t; + let u = self.curve.point_to_curve_coords(*point).t; let v = { let line = Line { origin: self.curve.origin(), @@ -60,7 +60,7 @@ impl SweptCurve { &self, point: &Point<2>, ) -> Point<3> { - self.curve.point_from_curve_coords(&point.to_t()) + self.path * point.v + self.curve.point_from_curve_coords([point.u]) + self.path * point.v } /// Convert a vector in surface coordinates to model coordinates @@ -68,8 +68,7 @@ impl SweptCurve { &self, vector: &Vector<2>, ) -> Vector<3> { - self.curve.vector_from_curve_coords(&vector.to_t()) - + self.path * vector.v + self.curve.vector_from_curve_coords([vector.u]) + self.path * vector.v } } From a2b41e2ddc2c0698a8814c3473b6bc22227158a0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 13:03:31 +0200 Subject: [PATCH 09/12] Make `SweptSurface` conv methods easier to call --- crates/fj-kernel/src/geometry/surfaces/mod.rs | 6 ++--- .../fj-kernel/src/geometry/surfaces/swept.rs | 22 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index ebcca1430..f0ef73966 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -65,7 +65,7 @@ impl Surface { ) -> geometry::Point<2> { let point_2d = match self { Self::SweptCurve(surface) => { - surface.convert_point_to_surface_coords(&point_3d) + surface.convert_point_to_surface_coords(point_3d) } }; @@ -79,7 +79,7 @@ impl Surface { ) -> Point<3> { match self { Self::SweptCurve(surface) => { - surface.convert_point_from_surface_coords(point) + surface.convert_point_from_surface_coords(*point) } } } @@ -91,7 +91,7 @@ impl Surface { ) -> Vector<3> { match self { Self::SweptCurve(surface) => { - surface.convert_vector_from_surface_coords(vector) + surface.convert_vector_from_surface_coords(*vector) } } } diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index 45af8069d..e8f08de8e 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -40,16 +40,18 @@ impl SweptCurve { /// Convert a point in model coordinates to surface coordinates pub fn convert_point_to_surface_coords( &self, - point: &Point<3>, + point: impl Into>, ) -> Point<2> { - let u = self.curve.point_to_curve_coords(*point).t; + let point = point.into(); + + let u = self.curve.point_to_curve_coords(point).t; let v = { let line = Line { origin: self.curve.origin(), direction: self.path, }; - line.point_to_line_coords(*point).t + line.point_to_line_coords(point).t }; Point::from([u, v]) @@ -58,16 +60,18 @@ impl SweptCurve { /// Convert a point in surface coordinates to model coordinates pub fn convert_point_from_surface_coords( &self, - point: &Point<2>, + point: impl Into>, ) -> Point<3> { + let point = point.into(); self.curve.point_from_curve_coords([point.u]) + self.path * point.v } /// Convert a vector in surface coordinates to model coordinates pub fn convert_vector_from_surface_coords( &self, - vector: &Vector<2>, + vector: impl Into>, ) -> Vector<3> { + let vector = vector.into(); self.curve.vector_from_curve_coords([vector.u]) + self.path * vector.v } } @@ -97,8 +101,8 @@ mod tests { verify(&swept, Point::from([2., 3.])); fn verify(swept: &SweptCurve, surface_point: Point<2>) { - let point = swept.convert_point_from_surface_coords(&surface_point); - let result = swept.convert_point_to_surface_coords(&point); + let point = swept.convert_point_from_surface_coords(surface_point); + let result = swept.convert_point_to_surface_coords(point); assert_eq!(result, surface_point); } @@ -115,7 +119,7 @@ mod tests { }; assert_eq!( - swept.convert_point_from_surface_coords(&Point::from([2., 4.])), + swept.convert_point_from_surface_coords([2., 4.]), Point::from([1., 4., 8.]), ); } @@ -131,7 +135,7 @@ mod tests { }; assert_eq!( - swept.convert_vector_from_surface_coords(&Vector::from([2., 4.])), + swept.convert_vector_from_surface_coords([2., 4.]), Vector::from([0., 4., 8.]), ); } From 9f9d8b1c59dca2d1d3ac0b5954c547ebed0d7a2d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 13:06:23 +0200 Subject: [PATCH 10/12] Simplify method names --- crates/fj-kernel/src/geometry/surfaces/mod.rs | 6 +++--- crates/fj-kernel/src/geometry/surfaces/swept.rs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index f0ef73966..4d28c8869 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -65,7 +65,7 @@ impl Surface { ) -> geometry::Point<2> { let point_2d = match self { Self::SweptCurve(surface) => { - surface.convert_point_to_surface_coords(point_3d) + surface.point_to_surface_coords(point_3d) } }; @@ -79,7 +79,7 @@ impl Surface { ) -> Point<3> { match self { Self::SweptCurve(surface) => { - surface.convert_point_from_surface_coords(*point) + surface.point_from_surface_coords(*point) } } } @@ -91,7 +91,7 @@ impl Surface { ) -> Vector<3> { match self { Self::SweptCurve(surface) => { - surface.convert_vector_from_surface_coords(*vector) + surface.vector_from_surface_coords(*vector) } } } diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index e8f08de8e..282747668 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -38,7 +38,7 @@ impl SweptCurve { } /// Convert a point in model coordinates to surface coordinates - pub fn convert_point_to_surface_coords( + pub fn point_to_surface_coords( &self, point: impl Into>, ) -> Point<2> { @@ -58,7 +58,7 @@ impl SweptCurve { } /// Convert a point in surface coordinates to model coordinates - pub fn convert_point_from_surface_coords( + pub fn point_from_surface_coords( &self, point: impl Into>, ) -> Point<3> { @@ -67,7 +67,7 @@ impl SweptCurve { } /// Convert a vector in surface coordinates to model coordinates - pub fn convert_vector_from_surface_coords( + pub fn vector_from_surface_coords( &self, vector: impl Into>, ) -> Vector<3> { @@ -101,8 +101,8 @@ mod tests { verify(&swept, Point::from([2., 3.])); fn verify(swept: &SweptCurve, surface_point: Point<2>) { - let point = swept.convert_point_from_surface_coords(surface_point); - let result = swept.convert_point_to_surface_coords(point); + let point = swept.point_from_surface_coords(surface_point); + let result = swept.point_to_surface_coords(point); assert_eq!(result, surface_point); } @@ -119,7 +119,7 @@ mod tests { }; assert_eq!( - swept.convert_point_from_surface_coords([2., 4.]), + swept.point_from_surface_coords([2., 4.]), Point::from([1., 4., 8.]), ); } @@ -135,7 +135,7 @@ mod tests { }; assert_eq!( - swept.convert_vector_from_surface_coords([2., 4.]), + swept.vector_from_surface_coords([2., 4.]), Vector::from([0., 4., 8.]), ); } From 9b4dd4ea165dc94aa31b12f657c5df2926011497 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 13:08:27 +0200 Subject: [PATCH 11/12] Make `Surface` conversion methods easier to call --- .../src/algorithms/triangulation/polygon.rs | 4 ++-- crates/fj-kernel/src/geometry/surfaces/mod.rs | 12 +++++++----- crates/fj-operations/src/sketch.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/triangulation/polygon.rs b/crates/fj-kernel/src/algorithms/triangulation/polygon.rs index 68fce75cb..0da638aa3 100644 --- a/crates/fj-kernel/src/algorithms/triangulation/polygon.rs +++ b/crates/fj-kernel/src/algorithms/triangulation/polygon.rs @@ -140,7 +140,7 @@ impl Polygon { }; let mut check = TriangleEdgeCheck::new( - self.surface.convert_point_from_surface_coords(&ray.origin), + self.surface.convert_point_from_surface_coords(ray.origin), ); let mut num_hits = 0; @@ -202,7 +202,7 @@ impl Polygon { let edge = Segment::from_points(edge.points().map(|point| { self.surface - .convert_point_from_surface_coords(&point) + .convert_point_from_surface_coords(point) })); check.hits.push(edge); } diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index 4d28c8869..bb3fb3f4d 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -61,8 +61,10 @@ impl Surface { /// Convert a point in model coordinates to surface coordinates pub fn convert_point_to_surface_coords( &self, - point_3d: Point<3>, + point_3d: impl Into>, ) -> geometry::Point<2> { + let point_3d = point_3d.into(); + let point_2d = match self { Self::SweptCurve(surface) => { surface.point_to_surface_coords(point_3d) @@ -75,11 +77,11 @@ impl Surface { /// Convert a point in surface coordinates to model coordinates pub fn convert_point_from_surface_coords( &self, - point: &Point<2>, + point: impl Into>, ) -> Point<3> { match self { Self::SweptCurve(surface) => { - surface.point_from_surface_coords(*point) + surface.point_from_surface_coords(point) } } } @@ -87,11 +89,11 @@ impl Surface { /// Convert a vector in surface coordinates to model coordinates pub fn convert_vector_from_surface_coords( &self, - vector: &Vector<2>, + vector: impl Into>, ) -> Vector<3> { match self { Self::SweptCurve(surface) => { - surface.vector_from_surface_coords(*vector) + surface.vector_from_surface_coords(vector) } } } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 4f8306196..38066e7e4 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -15,7 +15,7 @@ impl ToShape for fj::Sketch { .to_points() .into_iter() .map(Point::from) - .map(|point| surface.convert_point_from_surface_coords(&point)); + .map(|point| surface.convert_point_from_surface_coords(point)); Face::builder(surface, &mut shape) .with_exterior_polygon(points) From 791745bfffbe1cd3a9b5d0873ee50ba3704cae96 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 May 2022 13:09:32 +0200 Subject: [PATCH 12/12] Simplify method names --- crates/fj-kernel/src/algorithms/triangulation/mod.rs | 10 +++------- .../fj-kernel/src/algorithms/triangulation/polygon.rs | 5 ++--- crates/fj-kernel/src/geometry/surfaces/mod.rs | 6 +++--- crates/fj-operations/src/sketch.rs | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/triangulation/mod.rs b/crates/fj-kernel/src/algorithms/triangulation/mod.rs index 54b079612..600d41a64 100644 --- a/crates/fj-kernel/src/algorithms/triangulation/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulation/mod.rs @@ -32,7 +32,7 @@ pub fn triangulate( .map(|vertex| { // Can't panic, unless the approximation wrongfully // generates points that are not in the surface. - surface.convert_point_to_surface_coords(vertex) + surface.point_to_surface_coords(vertex) }) .collect(); let face_as_polygon = Polygon::new(surface) @@ -40,9 +40,7 @@ pub fn triangulate( |point| { // Can't panic, unless the approximation wrongfully // generates points that are not in the surface. - surface - .convert_point_to_surface_coords(point) - .native() + surface.point_to_surface_coords(point).native() }, )) .with_interiors(approx.interiors.into_iter().map( @@ -51,9 +49,7 @@ pub fn triangulate( // Can't panic, unless the approximation // wrongfully generates points that are not in // the surface. - surface - .convert_point_to_surface_coords(point) - .native() + surface.point_to_surface_coords(point).native() }) }, )); diff --git a/crates/fj-kernel/src/algorithms/triangulation/polygon.rs b/crates/fj-kernel/src/algorithms/triangulation/polygon.rs index 0da638aa3..5630b876f 100644 --- a/crates/fj-kernel/src/algorithms/triangulation/polygon.rs +++ b/crates/fj-kernel/src/algorithms/triangulation/polygon.rs @@ -140,7 +140,7 @@ impl Polygon { }; let mut check = TriangleEdgeCheck::new( - self.surface.convert_point_from_surface_coords(ray.origin), + self.surface.point_from_surface_coords(ray.origin), ); let mut num_hits = 0; @@ -201,8 +201,7 @@ impl Polygon { let edge = Segment::from_points(edge.points().map(|point| { - self.surface - .convert_point_from_surface_coords(point) + self.surface.point_from_surface_coords(point) })); check.hits.push(edge); } diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index bb3fb3f4d..c97a9c398 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -59,7 +59,7 @@ impl Surface { } /// Convert a point in model coordinates to surface coordinates - pub fn convert_point_to_surface_coords( + pub fn point_to_surface_coords( &self, point_3d: impl Into>, ) -> geometry::Point<2> { @@ -75,7 +75,7 @@ impl Surface { } /// Convert a point in surface coordinates to model coordinates - pub fn convert_point_from_surface_coords( + pub fn point_from_surface_coords( &self, point: impl Into>, ) -> Point<3> { @@ -87,7 +87,7 @@ impl Surface { } /// Convert a vector in surface coordinates to model coordinates - pub fn convert_vector_from_surface_coords( + pub fn vector_from_surface_coords( &self, vector: impl Into>, ) -> Vector<3> { diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 38066e7e4..60e2ef595 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -15,7 +15,7 @@ impl ToShape for fj::Sketch { .to_points() .into_iter() .map(Point::from) - .map(|point| surface.convert_point_from_surface_coords(point)); + .map(|point| surface.point_from_surface_coords(point)); Face::builder(surface, &mut shape) .with_exterior_polygon(points)