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