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/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 0c88f1adc..ebcca1430 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -59,13 +59,13 @@ 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> { let point_2d = match self { Self::SweptCurve(surface) => { - surface.point_model_to_surface(&point_3d) + surface.convert_point_to_surface_coords(&point_3d) } }; @@ -73,17 +73,25 @@ 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.point_surface_to_model(point), + Self::SweptCurve(surface) => { + surface.convert_point_from_surface_coords(point) + } } } /// 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.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 c8d2b3513..ce9d5081e 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; @@ -40,22 +38,36 @@ 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) - / 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]) } /// 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 } /// 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 } } @@ -70,13 +82,13 @@ 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.]), direction: Vector::from([0., 2., 0.]), }), - path: Vector::from([0., 0., 2.]), + path: Vector::from([0., 0., 3.]), }; verify(&swept, Point::from([-1., -1.])); @@ -85,15 +97,15 @@ 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 result = swept.point_model_to_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); } } #[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.]), @@ -103,13 +115,13 @@ 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.]), ); } #[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.]), @@ -119,7 +131,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.]), ); } 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)