X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fgeometry.rs;h=f5e2b0ec2f5398b32291b07d5b72cda64625bfce;hb=15cda3333ba8d5600b1afa9426a112dea99d4941;hp=2d5a70cda916a7d521e9acbd2c2f934bc43cdbe1;hpb=bb3eb700e040846ca793832da4adc133218f2954;p=kaka%2Frust-sdl-test.git diff --git a/src/geometry.rs b/src/geometry.rs index 2d5a70c..f5e2b0e 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -38,6 +38,16 @@ impl Point { y: self.y as i32, } } + + 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 { @@ -221,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 {