2017-09-22 08:46:00 +00:00
|
|
|
/// A rectangle defined by its top-left corner and dimensions
|
2020-01-22 04:22:22 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Default)]
|
2017-09-22 08:46:00 +00:00
|
|
|
pub struct Rectangle {
|
2018-10-30 12:56:30 +00:00
|
|
|
/// horizontal position of the top-left corner of the rectangle, in surface coordinates
|
2017-09-22 08:46:00 +00:00
|
|
|
pub x: i32,
|
2018-10-30 12:56:30 +00:00
|
|
|
/// vertical position of the top-left corner of the rectangle, in surface coordinates
|
2017-09-22 08:46:00 +00:00
|
|
|
pub y: i32,
|
|
|
|
/// width of the rectangle
|
|
|
|
pub width: i32,
|
|
|
|
/// height of the rectangle
|
|
|
|
pub height: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Rectangle {
|
2018-10-30 12:56:30 +00:00
|
|
|
/// Checks whether given point is inside a rectangle
|
2017-09-22 08:46:00 +00:00
|
|
|
pub fn contains(&self, point: (i32, i32)) -> bool {
|
|
|
|
let (x, y) = point;
|
2017-09-22 12:53:39 +00:00
|
|
|
(x >= self.x) && (x < self.x + self.width) && (y >= self.y) && (y < self.y + self.height)
|
2017-09-22 08:46:00 +00:00
|
|
|
}
|
2017-09-22 12:53:39 +00:00
|
|
|
}
|