2016-10-21 17:02:25 -05:00
|
|
|
pub struct Point {
|
|
|
|
pub x: f32,
|
|
|
|
pub y: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Point {
|
|
|
|
fn distance_squared(&self) -> f32 {
|
2017-10-27 11:57:15 -05:00
|
|
|
#[cfg(cfail1)]
|
2016-10-21 17:02:25 -05:00
|
|
|
return self.x + self.y;
|
|
|
|
|
2017-10-27 11:57:15 -05:00
|
|
|
#[cfg(cfail2)]
|
2016-10-21 17:02:25 -05:00
|
|
|
return self.x * self.x + self.y * self.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn distance_from_origin(&self) -> f32 {
|
|
|
|
self.distance_squared().sqrt()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Point {
|
|
|
|
pub fn translate(&mut self, x: f32, y: f32) {
|
|
|
|
self.x += x;
|
|
|
|
self.y += y;
|
|
|
|
}
|
|
|
|
}
|