From 224d31ec6eb5dfa07f8f8ecd88ee48f317f7f8f7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:29:35 +0200 Subject: [PATCH 1/9] Make method name a bit clearer --- crates/fj-kernel/src/geometry/surfaces/mod.rs | 2 +- crates/fj-kernel/src/geometry/surfaces/swept.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index 0c88f1adc..f1e28f3b1 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.point_model_to_surface(&point_3d) + surface.convert_point_to_surface_coords(&point_3d) } }; diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index c8d2b3513..fe6dda4fa 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -40,7 +40,10 @@ impl SweptCurve { } /// Convert a point in model coordinates to surface coordinates - pub fn point_model_to_surface(&self, point: &Point<3>) -> Point<2> { + pub fn convert_point_to_surface_coords( + &self, + point: &Point<3>, + ) -> Point<2> { let u = self.curve.point_model_to_curve(point).t; let v = (point - self.curve.origin()) .scalar_projection_onto(&self.path) @@ -86,7 +89,7 @@ mod tests { fn verify(swept: &SweptCurve, surface_point: Point<2>) { let point = swept.point_surface_to_model(&surface_point); - let result = swept.point_model_to_surface(&point); + let result = swept.convert_point_to_surface_coords(&point); assert_eq!(result, surface_point); } From de13b49eff6b3dda34cb5d92efdb23bf33d4c3d2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:30:46 +0200 Subject: [PATCH 2/9] Make method name a bit clearer --- crates/fj-kernel/src/geometry/surfaces/mod.rs | 4 +++- crates/fj-kernel/src/geometry/surfaces/swept.rs | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index f1e28f3b1..8efd80b21 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -75,7 +75,9 @@ impl Surface { /// Convert a point in surface coordinates to model coordinates pub fn point_surface_to_model(&self, point: &Point<2>) -> Point<3> { match self { - Self::SweptCurve(surface) => surface.point_surface_to_model(point), + Self::SweptCurve(surface) => { + surface.convert_point_from_surface_coords(point) + } } } diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index fe6dda4fa..36a9b1885 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -53,7 +53,10 @@ impl SweptCurve { } /// Convert a point in surface coordinates to model coordinates - pub fn point_surface_to_model(&self, point: &Point<2>) -> Point<3> { + pub fn convert_point_from_surface_coords( + &self, + point: &Point<2>, + ) -> Point<3> { self.curve.point_curve_to_model(&point.to_t()) + self.path * point.v } @@ -88,7 +91,7 @@ mod tests { verify(&swept, Point::from([2., 3.])); fn verify(swept: &SweptCurve, surface_point: Point<2>) { - let point = swept.point_surface_to_model(&surface_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); @@ -106,7 +109,7 @@ mod tests { }; assert_eq!( - swept.point_surface_to_model(&Point::from([2., 4.])), + swept.convert_point_from_surface_coords(&Point::from([2., 4.])), Point::from([1., 4., 8.]), ); } From d08e03d5242e0b3508e16834e87ead25b97750a7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:31:34 +0200 Subject: [PATCH 3/9] Make method name a bit clearer --- crates/fj-kernel/src/geometry/surfaces/mod.rs | 2 +- crates/fj-kernel/src/geometry/surfaces/swept.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index 8efd80b21..8c770da24 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -85,7 +85,7 @@ impl Surface { pub fn vector_surface_to_model(&self, vector: &Vector<2>) -> Vector<3> { match self { Self::SweptCurve(surface) => { - surface.vector_surface_to_model(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 36a9b1885..15862eb1b 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -61,7 +61,10 @@ impl SweptCurve { } /// Convert a vector in surface coordinates to model coordinates - pub fn vector_surface_to_model(&self, vector: &Vector<2>) -> Vector<3> { + pub fn convert_vector_from_surface_coords( + &self, + vector: &Vector<2>, + ) -> Vector<3> { self.curve.vector_curve_to_model(&vector.to_t()) + self.path * vector.v } } @@ -125,7 +128,7 @@ mod tests { }; assert_eq!( - swept.vector_surface_to_model(&Vector::from([2., 4.])), + swept.convert_vector_from_surface_coords(&Vector::from([2., 4.])), Vector::from([0., 4., 8.]), ); } From 0e675f27373994187fe7c938e662140a806c0c06 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:32:19 +0200 Subject: [PATCH 4/9] Update method name Make it match the method it wraps. --- crates/fj-kernel/src/algorithms/triangulation/mod.rs | 10 +++++++--- crates/fj-kernel/src/geometry/surfaces/mod.rs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/triangulation/mod.rs b/crates/fj-kernel/src/algorithms/triangulation/mod.rs index aa207dc99..54b079612 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.point_model_to_surface(vertex) + surface.convert_point_to_surface_coords(vertex) }) .collect(); let face_as_polygon = Polygon::new(surface) @@ -40,7 +40,9 @@ pub fn triangulate( |point| { // Can't panic, unless the approximation wrongfully // generates points that are not in the surface. - surface.point_model_to_surface(point).native() + surface + .convert_point_to_surface_coords(point) + .native() }, )) .with_interiors(approx.interiors.into_iter().map( @@ -49,7 +51,9 @@ pub fn triangulate( // Can't panic, unless the approximation // wrongfully generates points that are not in // the surface. - surface.point_model_to_surface(point).native() + surface + .convert_point_to_surface_coords(point) + .native() }) }, )); diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index 8c770da24..0f74293da 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 point_model_to_surface( + pub fn convert_point_to_surface_coords( &self, point_3d: Point<3>, ) -> geometry::Point<2> { From e1e81c6a25ebabd1040507ffabbb654d8948e231 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:32:57 +0200 Subject: [PATCH 5/9] Update method name Make it match the method it wraps. --- crates/fj-kernel/src/algorithms/triangulation/polygon.rs | 5 +++-- crates/fj-kernel/src/geometry/surfaces/mod.rs | 5 ++++- crates/fj-operations/src/sketch.rs | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/triangulation/polygon.rs b/crates/fj-kernel/src/algorithms/triangulation/polygon.rs index 5ab3f37d3..68fce75cb 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.point_surface_to_model(&ray.origin), + self.surface.convert_point_from_surface_coords(&ray.origin), ); let mut num_hits = 0; @@ -201,7 +201,8 @@ impl Polygon { let edge = Segment::from_points(edge.points().map(|point| { - self.surface.point_surface_to_model(&point) + self.surface + .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 0f74293da..3113fd207 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -73,7 +73,10 @@ impl Surface { } /// Convert a point in surface coordinates to model coordinates - pub fn point_surface_to_model(&self, point: &Point<2>) -> Point<3> { + pub fn convert_point_from_surface_coords( + &self, + point: &Point<2>, + ) -> Point<3> { match self { Self::SweptCurve(surface) => { surface.convert_point_from_surface_coords(point) diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index b822bd99b..4f8306196 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.point_surface_to_model(&point)); + .map(|point| surface.convert_point_from_surface_coords(&point)); Face::builder(surface, &mut shape) .with_exterior_polygon(points) From 86277f01e32f70b5bbec5caf686d625ea2a2fb74 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:33:50 +0200 Subject: [PATCH 6/9] Update method name Make it match the method it wraps. --- crates/fj-kernel/src/geometry/surfaces/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index 3113fd207..ebcca1430 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -85,7 +85,10 @@ impl Surface { } /// Convert a vector in surface coordinates to model coordinates - pub fn vector_surface_to_model(&self, vector: &Vector<2>) -> Vector<3> { + pub fn convert_vector_from_surface_coords( + &self, + vector: &Vector<2>, + ) -> Vector<3> { match self { Self::SweptCurve(surface) => { surface.convert_vector_from_surface_coords(vector) From f0ca7476095b372609fb844eb37e6807a37f2150 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:39:04 +0200 Subject: [PATCH 7/9] Consolidate redundant code --- crates/fj-kernel/src/geometry/surfaces/swept.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index 15862eb1b..431434209 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -1,4 +1,4 @@ -use fj_math::{Point, Transform, Vector}; +use fj_math::{Line, Point, Transform, Vector}; use crate::geometry::Curve; @@ -16,8 +16,6 @@ impl SweptCurve { /// Construct a plane from 3 points #[cfg(test)] pub fn plane_from_points([a, b, c]: [Point<3>; 3]) -> Self { - use fj_math::Line; - let curve = Curve::Line(Line::from_points([a, b])); let path = c - a; @@ -45,9 +43,14 @@ impl SweptCurve { point: &Point<3>, ) -> Point<2> { let u = self.curve.point_model_to_curve(point).t; - let v = (point - self.curve.origin()) - .scalar_projection_onto(&self.path) - / self.path.magnitude(); + let v = { + let line = Line { + origin: self.curve.origin(), + direction: self.path, + }; + + line.convert_point_to_line_coords(point).t + }; Point::from([u, v]) } From 9baedb4f61ac67a1c7481d933b3b56353c66aa9b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:40:23 +0200 Subject: [PATCH 8/9] Update test names --- crates/fj-kernel/src/geometry/surfaces/swept.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index 431434209..3acbecd18 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -82,7 +82,7 @@ mod tests { use super::SweptCurve; #[test] - fn point_model_to_surface() { + fn convert_point_to_surface_coords() { let swept = SweptCurve { curve: Curve::Line(Line { origin: Point::from([1., 0., 0.]), @@ -105,7 +105,7 @@ mod tests { } #[test] - fn point_surface_to_model() { + fn convert_point_from_surface_coords() { let swept = SweptCurve { curve: Curve::Line(Line { origin: Point::from([1., 0., 0.]), @@ -121,7 +121,7 @@ mod tests { } #[test] - fn vector_surface_to_model() { + fn convert_vector_from_surface_coords() { let swept = SweptCurve { curve: Curve::Line(Line { origin: Point::from([1., 0., 0.]), From a4d7004cd2beeabffab96c9c8f6413b759b02159 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 May 2022 17:47:35 +0200 Subject: [PATCH 9/9] Adjust test data --- crates/fj-kernel/src/geometry/surfaces/swept.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/geometry/surfaces/swept.rs b/crates/fj-kernel/src/geometry/surfaces/swept.rs index 3acbecd18..ce9d5081e 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -88,7 +88,7 @@ mod tests { origin: Point::from([1., 0., 0.]), direction: Vector::from([0., 2., 0.]), }), - path: Vector::from([0., 0., 2.]), + path: Vector::from([0., 0., 3.]), }; verify(&swept, Point::from([-1., -1.]));