diff --git a/crates/fj-kernel/src/algorithms/approx/curves.rs b/crates/fj-kernel/src/algorithms/approx/curves.rs index 6e3d7e88c..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_curve_to_model(&Point::from([angle])); + let point = circle.point_from_circle_coords([angle]); out.push(point); } } 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 68fce75cb..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/curves/circle.rs b/crates/fj-kernel/src/geometry/curves/circle.rs index bb19f0d1d..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_model_to_curve(&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_curve_to_model(&self, point: &Point<1>) -> Point<3> { - self.center + self.vector_curve_to_model(&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_curve_to_model(&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_model_to_curve(&Point::from([2., 2., 3.])), + circle.point_to_circle_coords([2., 2., 3.]), Point::from([0.]), ); assert_eq!( - circle.point_model_to_curve(&Point::from([1., 3., 3.])), + circle.point_to_circle_coords([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([0., 2., 3.]), Point::from([PI]), ); assert_eq!( - circle.point_model_to_curve(&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 f2f59ef16..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_model_to_curve(&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_model_to_curve(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_curve_to_model(&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_curve_to_model(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_curve_to_model(&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_curve_to_model(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/mod.rs b/crates/fj-kernel/src/geometry/surfaces/mod.rs index ebcca1430..c97a9c398 100644 --- a/crates/fj-kernel/src/geometry/surfaces/mod.rs +++ b/crates/fj-kernel/src/geometry/surfaces/mod.rs @@ -59,13 +59,15 @@ 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: Point<3>, + point_3d: impl Into>, ) -> geometry::Point<2> { + let point_3d = point_3d.into(); + let point_2d = match self { Self::SweptCurve(surface) => { - surface.convert_point_to_surface_coords(&point_3d) + surface.point_to_surface_coords(point_3d) } }; @@ -73,25 +75,25 @@ 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: &Point<2>, + point: impl Into>, ) -> Point<3> { match self { Self::SweptCurve(surface) => { - surface.convert_point_from_surface_coords(point) + surface.point_from_surface_coords(point) } } } /// Convert a vector in surface coordinates to model coordinates - pub fn convert_vector_from_surface_coords( + pub fn vector_from_surface_coords( &self, - vector: &Vector<2>, + vector: impl Into>, ) -> 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 0f66159a5..282747668 100644 --- a/crates/fj-kernel/src/geometry/surfaces/swept.rs +++ b/crates/fj-kernel/src/geometry/surfaces/swept.rs @@ -38,37 +38,41 @@ 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: &Point<3>, + point: impl Into>, ) -> Point<2> { - let u = self.curve.point_model_to_curve(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]) } /// Convert a point in surface coordinates to model coordinates - pub fn convert_point_from_surface_coords( + pub fn point_from_surface_coords( &self, - point: &Point<2>, + point: impl Into>, ) -> Point<3> { - self.curve.point_curve_to_model(&point.to_t()) + self.path * point.v + 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( + pub fn vector_from_surface_coords( &self, - vector: &Vector<2>, + vector: impl Into>, ) -> Vector<3> { - self.curve.vector_curve_to_model(&vector.to_t()) + self.path * vector.v + 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.point_from_surface_coords(surface_point); + let result = swept.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.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.vector_from_surface_coords([2., 4.]), Vector::from([0., 4., 8.]), ); } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 4f8306196..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)