Merge pull request #1631

Keep Xfrm::rot_norm within 0..360 for tiny negative rotations
This commit is contained in:
Brandon Thomas
2026-11-02 04:53:50 -05:00
+10 -2
View File
@@ -153,8 +153,8 @@ impl Xfrm {
}
/// Rotation normalised to 0..360.
pub fn rot_norm(&self) -> f64 {
let r = self.rot % 360.0;
if r < 0.0 { r + 360.0 } else { r }
let r = self.rot.rem_euclid(360.0);
if r >= 360.0 { 0.0 } else { r }
}
}
@@ -266,6 +266,14 @@ mod tests {
assert!((p.x - 300.0).abs() < 1e-9 && (p.y - 200.0).abs() < 1e-9);
}
#[test]
fn rot_norm_stays_below_360() {
for rot in [-1e-15, -1e-13, -f64::EPSILON, -0.0, 360.0, 720.0, -360.0] {
let n = Xfrm { rot, ..Default::default() }.rot_norm();
assert!((0.0..360.0).contains(&n), "rot {rot} -> {n}");
}
}
#[test]
fn segment_distance() {
assert!((dist_to_segment(Point::new(5.0, 5.0), Point::new(0.0, 0.0), Point::new(10.0, 0.0)) - 5.0).abs() < 1e-9);