X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fgeometry.rs;fp=src%2Fgeometry.rs;h=f5e2b0ec2f5398b32291b07d5b72cda64625bfce;hb=15cda3333ba8d5600b1afa9426a112dea99d4941;hp=7ddc3ec0e4c94850b6c0c8fc339500e596d1f134;hpb=856c3740c76feea6a82cc95b5e190b1ccd165621;p=kaka%2Frust-sdl-test.git diff --git a/src/geometry.rs b/src/geometry.rs index 7ddc3ec..f5e2b0e 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -42,6 +42,12 @@ impl Point { pub fn cross_product(&self, p: Self) -> f64 { return self.x * p.y - self.y * p.x; } + + /// Returns the perpendicular projection of this vector on a line with the specified angle. + pub fn project_onto(&self, angle: Angle) -> Point { + let dot_product = self.length() * (self.to_angle() - angle).to_radians().cos(); + Point::from(angle) * dot_product + } } macro_rules! impl_point_op { @@ -225,6 +231,10 @@ impl Angle { pub fn mirror(&self, incidence: Angle) -> Angle { Angle((std::f64::consts::PI + self.0 * 2.0 - incidence.0) % std::f64::consts::TAU) } + + pub fn reverse(&self) -> Angle { + Angle((self.0 + std::f64::consts::PI) % std::f64::consts::TAU) + } } impl PartialEq for Angle {