# HG changeset patch # User Tuomo Valkonen # Date 1733508657 18000 # Node ID 1d865db9d3e4fff983c3c5ac2a346a5450fcb8ab # Parent 3d5c8ea1522ccdc7143a19f9684ff45ff591e175 Move rotate and reflect to alg_tools diff -r 3d5c8ea1522c -r 1d865db9d3e4 src/cylinder.rs --- 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) -> Loc { - 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) -> Loc { - [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);