1 extern crate fpnum; |
1 extern crate fpnum; |
2 |
2 |
3 use fpnum::distance; |
3 use fpnum::distance; |
4 use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; |
4 use std::ops::{ |
|
5 Add, AddAssign, |
|
6 Div, DivAssign, |
|
7 Mul, MulAssign, |
|
8 Sub, SubAssign, |
|
9 RangeInclusive |
|
10 }; |
5 |
11 |
6 #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
12 #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
7 pub struct Point { |
13 pub struct Point { |
8 pub x: i32, |
14 pub x: i32, |
9 pub y: i32, |
15 pub y: i32, |
285 self.bottom() - margin, |
291 self.bottom() - margin, |
286 ) |
292 ) |
287 } |
293 } |
288 |
294 |
289 #[inline] |
295 #[inline] |
|
296 pub fn x_range(&self) -> RangeInclusive<i32> { |
|
297 self.x..=self.x + self.width as i32 |
|
298 } |
|
299 |
|
300 #[inline] |
|
301 pub fn y_range(&self) -> RangeInclusive<i32> { |
|
302 self.y..=self.y + self.height as i32 |
|
303 } |
|
304 |
|
305 /* requires #[feature(range_contains)] |
|
306 #[inline] |
|
307 pub fn contains(&self, point: Point) -> bool { |
|
308 x_range().contains(point.x) && y_range.contains(point.y) |
|
309 }*/ |
|
310 |
|
311 #[inline] |
290 pub fn contains_inside(&self, point: Point) -> bool { |
312 pub fn contains_inside(&self, point: Point) -> bool { |
291 point.x > self.left() |
313 point.x > self.left() |
292 && point.x < self.right() |
314 && point.x < self.right() |
293 && point.y > self.top() |
315 && point.y > self.top() |
294 && point.y < self.bottom() |
316 && point.y < self.bottom() |
|
317 } |
|
318 |
|
319 #[inline] |
|
320 pub fn intersects(&self, other: &Rect) -> bool { |
|
321 self.left() <= self.right() |
|
322 && self.right() >= other.left() |
|
323 && self.top() <= other.bottom() |
|
324 && self.bottom() >= other.top() |
295 } |
325 } |
296 } |
326 } |
297 |
327 |
298 #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
328 #[derive(PartialEq, Eq, Clone, Copy, Debug)] |
299 pub struct Line { |
329 pub struct Line { |