Skip to content

Commit

Permalink
Test from_unit_vector and avoid unnessessary normalizing (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamGallagher737 authored Nov 21, 2024
1 parent 465164f commit d88bfd3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ impl Angle {
#[cfg(any(feature = "std", feature = "libm"))]
pub fn from_unit_vector(x: f64, y: f64) -> Angle {
#[cfg(feature = "std")]
return Angle::new(y.atan2(x));
return Angle { value: y.atan2(x) };
#[cfg(feature = "libm")]
return Angle::new(libm::atan2(y, x));
return Angle {
value: libm::atan2(y, x),
};
}
}

Expand Down Expand Up @@ -314,5 +316,13 @@ mod tests {
fn prop_test_below_range(angle in ..PI) {
assert!(Angle::new(angle).radians() > angle);
}

#[test]
#[cfg(any(feature = "std", feature = "libm"))]
fn prop_test_from_unit_vector(x in -1000.0..1000.0, y in -1000.0..1000.0) {
let angle = Angle::from_unit_vector(x, y);
assert!(-PI <= angle.radians());
assert!(angle.radians() <= PI);
}
}
}

0 comments on commit d88bfd3

Please sign in to comment.