Move rotate and reflect to alg_tools

Fri, 06 Dec 2024 13:10:57 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 06 Dec 2024 13:10:57 -0500
changeset 40
1d865db9d3e4
parent 39
3d5c8ea1522c
child 41
56d609b70a3b

Move rotate and reflect to alg_tools

src/cylinder.rs file | annotate | diff | comparison | revisions
--- a/src/cylinder.rs	Fri Dec 06 11:38:12 2024 -0500
+++ b/src/cylinder.rs	Fri Dec 06 13:10:57 2024 -0500
@@ -46,21 +46,6 @@
     pub angle : Angle
 }
 
-/// Rotate input vector by angle φ.
-#[inline]
-fn rotate(φ : f64, Loc([x, y]) : Loc<f64, 2>) -> Loc<f64, 2> {
-    let sin_φ = φ.sin();
-    let cos_φ = φ.cos();
-    [cos_φ * x - sin_φ * y, sin_φ * x + cos_φ * y].into()
-}
-
-/// Mirror y coordinate of input vector.
-#[inline]
-fn ymirror(Loc([x, y]) : Loc<f64, 2>) -> Loc<f64, 2> {
-    [x, -y].into()
-}
-
-
 impl CapPoint {
     #[inline]
     /// Convert to cylindrical coordinates given z coordinate
@@ -119,10 +104,10 @@
         if top {
             // The angle is such that down would be rotated to self.angle, counterclockwise
             // The new tangent is R[down +  t] - R[down] = Rt.
-            rotate(self.angle+f64::PI/2.0, t)
+            t.rotate(self.angle+f64::PI/2.0)
         } else {
             // The angle is such that up would be rotated to self.angle, clockwise
-            rotate(self.angle+f64::PI/2.0, ymirror(t))
+            t.reflect_y().rotate(self.angle+f64::PI/2.0)
         }
     }
 
@@ -131,10 +116,10 @@
     fn tangent_to_side(&self, top : bool, t : Tangent) -> Tangent {
         if top {
             // The angle is such that self.angle would be rotated to down, clockwise
-            rotate(-self.angle-f64::PI/2.0, t)
+            t.rotate(-self.angle-f64::PI/2.0)
         } else {
             // The angle is such that self.angle would be rotated to up, counterclockwise
-            ymirror(rotate(-self.angle-f64::PI/2.0, t))
+            t.rotate(-self.angle-f64::PI/2.0).reflect_y()
         }
     }
 }
@@ -981,7 +966,7 @@
         for φ in angles {
             let p = CYL.on_top(φ, CYL.radius / 2.0);
             let q_target = CYL.on_side(φ, CYL.height / 2.0);
-            let t = rotate(φ, [CYL.radius, 0.0].into());
+            let t = Loc([CYL.radius, 0.0]).rotate(φ);
             let t_target = Loc([0.0, -CYL.radius / 2.0]);
             let (q, t_left) = CYL.partial_exp(p.point, t);
             check_point_eq!(q, q_target.point);
@@ -995,7 +980,7 @@
         for φ in angles {
             let p = CYL.on_top(φ + π/2.0, CYL.radius);
             let q_target = CYL.on_side(φ, CYL.height / 2.0);
-            let t = 2.0 * rotate(φ, Loc([CYL.radius, -CYL.radius]));
+            let t = 2.0 * Loc([CYL.radius, -CYL.radius]).rotate(φ);
             let t_target = Loc([-CYL.radius, -CYL.radius]);
             let (q, t_left) = CYL.partial_exp(p.point, t);
             check_point_eq!(q, q_target.point);
@@ -1014,7 +999,7 @@
 
         for φ in angles {
             let pt = CYL.on_top(φ, CYL.radius);
-            let t = rotate(φ, Loc([0.1, 0.3]));
+            let t = Loc([0.1, 0.3]).rotate(φ);
             let b = pt.clone().exp(&t);
             let a = pt.exp(&(-t));
             check_point_eq!(a.exp(&(2.0*t)).point, b.point);

mercurial