Bounce bolls off of walls in a proper angle
[kaka/rust-sdl-test.git] / src / common / geometry.rs
index e46f23e..ebf122a 100644 (file)
@@ -173,16 +173,21 @@ pub struct Radians(pub f64);
 
 impl Degrees {
     #[allow(dead_code)]
-    fn to_radians(&self) -> Radians {
+    pub fn to_radians(&self) -> Radians {
        Radians(self.0.to_radians())
     }
 }
 
 impl Radians {
     #[allow(dead_code)]
-    fn to_degrees(&self) -> Degrees {
+    pub fn to_degrees(&self) -> Degrees {
        Degrees(self.0.to_degrees())
     }
+
+    /// Returns the reflection of the incident when mirrored along this angle.
+    pub fn mirror(&self, incidence: Radians) -> Radians {
+       Radians((std::f64::consts::PI + self.0 * 2.0 - incidence.0) % std::f64::consts::TAU)
+    }
 }
 
 ////////// INTERSECTION ////////////////////////////////////////////////////////