From 96390b09b9438fd8644a53c97f6c5d3d3b15f9b7 Mon Sep 17 00:00:00 2001 From: Nicolas <> Date: Fri, 15 Apr 2022 07:56:37 +0200 Subject: [PATCH] Fix angle function --- src/animation/rotation.rs | 8 ++++---- src/vec.rs | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/animation/rotation.rs b/src/animation/rotation.rs index db64ddc..b8a19d4 100644 --- a/src/animation/rotation.rs +++ b/src/animation/rotation.rs @@ -35,12 +35,12 @@ mod test { fn sample() { let anim = RotationAnimation::new(Vector::new(30.0, 10.0)); - let sample_1 = anim.sample(0.2, Vector::new(5.0, 16.0)); + let sample_1 = anim.sample(0.3, Vector::new(16.0, 3.0)); let sample_2 = anim.sample(0.7, Vector::new(22.0, 2.0)); let sample_3 = anim.sample(0.5, Vector::new(4.0, 7.0)); - assert!(2.4 < sample_1 && sample_1 < 2.5); - assert!(0.7 < sample_2 && sample_2 < 0.8); - assert!(-2.3 < sample_3 && sample_3 < -2.2); + assert!(0.6 < sample_1 && sample_1 < 0.7); + assert!(-3.1 < sample_2 && sample_2 < -3.0); + assert!(4.7 < sample_3 && sample_3 < 4.8); } } \ No newline at end of file diff --git a/src/vec.rs b/src/vec.rs index a8e8e25..040eeef 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -24,7 +24,7 @@ impl Vector { /// Returns the angle. pub fn angle(self) -> f32 { - self.x.atan2(self.y) + self.y.atan2(self.x) } /// Returns the value of the smaller axis. @@ -86,6 +86,13 @@ mod test { assert!(6.7 < vec.length() && vec.length() < 6.8); } + #[test] + fn angle() { + let vec = Vector::new(3.0, 6.0); + + assert!(1.1 < vec.angle() && vec.angle() < 1.2); + } + #[test] fn smaller() { assert_eq!(4.0, Vector::new(7.0, 4.0).smaller());