Bounce bolls off of walls in a proper angle
[kaka/rust-sdl-test.git] / src / common / geometry.rs
index 5a115fd..ebf122a 100644 (file)
@@ -76,6 +76,8 @@ point_op!(+, Add(add), AddAssign(add_assign), rhs = (T, T) => rhs.0, rhs.1);
 point_op!(-, Sub(sub), SubAssign(sub_assign), rhs = (T, T) => rhs.0, rhs.1);
 point_op!(*, Mul(mul), MulAssign(mul_assign), rhs = (T, T) => rhs.0, rhs.1);
 point_op!(/, Div(div), DivAssign(div_assign), rhs = (T, T) => rhs.0, rhs.1);
+point_op!(*, Mul(mul), MulAssign(mul_assign), rhs = Dimension<T> => rhs.width, rhs.height);
+point_op!(/, Div(div), DivAssign(div_assign), rhs = Dimension<T> => rhs.width, rhs.height);
 
 ////////// multiply point with scalar //////////////////////////////////////////
 impl<T: Mul<Output = T> + Copy> Mul<T> for Point<T> {
@@ -171,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 ////////////////////////////////////////////////////////