diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-03-06 21:05:29 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-03-06 21:05:29 +0200 |
commit | 544c030b80d4d7b9a3b00711ff21b2592275a7e8 (patch) | |
tree | 2323fa63649fdaaec9e1cb5a278a81913969960c /src/geometry.rs | |
parent | 30df4064646fb429568474c0cdb2ee2ee08fd22e (diff) |
Bugs walking to the middle of the screen slowly
Diffstat (limited to 'src/geometry.rs')
-rw-r--r-- | src/geometry.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/geometry.rs b/src/geometry.rs index e9d534a..be903d7 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -1,3 +1,5 @@ +use std::ops::*; + #[derive(Debug, Clone, Copy, PartialEq)] pub struct Vec2d { pub x: f64, @@ -8,4 +10,40 @@ impl Vec2d { pub fn distance(&self, other: Vec2d) -> f64 { ((other.x-self.x).powi(2) + (other.y-self.y).powi(2)).sqrt() } + pub fn angle(&self) -> f64 { + self.y.atan2(self.x) + } +} + +impl Add for Vec2d { + type Output = Vec2d; + + fn add(self, other: Self) -> Self { + Vec2d { + x: self.x + other.x, + y: self.y + other.y + } + } +} + +impl Sub for Vec2d { + type Output = Vec2d; + + fn sub(self, other: Self) -> Self { + Vec2d { + x: self.x - other.x, + y: self.y - other.y + } + } +} + +impl Neg for Vec2d { + type Output = Vec2d; + + fn neg(self) -> Self { + Vec2d { + x: -self.x, + y: -self.y + } + } } |