2019-07-20 19:12:31 +02:00
|
|
|
use crate::Point;
|
|
|
|
|
|
2019-08-31 04:31:13 +02:00
|
|
|
/// A rectangle.
|
|
|
|
|
#[derive(Debug, PartialEq, Copy, Clone)]
|
|
|
|
|
pub struct Rectangle {
|
2019-07-20 19:12:31 +02:00
|
|
|
/// X coordinate of the top-left corner.
|
2019-08-31 04:31:13 +02:00
|
|
|
pub x: f32,
|
2019-07-20 19:12:31 +02:00
|
|
|
|
|
|
|
|
/// Y coordinate of the top-left corner.
|
2019-08-31 04:31:13 +02:00
|
|
|
pub y: f32,
|
2019-07-20 19:12:31 +02:00
|
|
|
|
|
|
|
|
/// Width of the rectangle.
|
2019-08-31 04:31:13 +02:00
|
|
|
pub width: f32,
|
2019-07-20 19:12:31 +02:00
|
|
|
|
|
|
|
|
/// Height of the rectangle.
|
2019-08-31 04:31:13 +02:00
|
|
|
pub height: f32,
|
2019-07-20 19:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-31 04:31:13 +02:00
|
|
|
impl Rectangle {
|
2019-07-20 19:12:31 +02:00
|
|
|
/// Returns true if the given [`Point`] is contained in the [`Rectangle`].
|
|
|
|
|
///
|
2019-08-31 04:31:13 +02:00
|
|
|
/// [`Point`]: struct.Point.html
|
2019-07-20 19:12:31 +02:00
|
|
|
/// [`Rectangle`]: struct.Rectangle.html
|
|
|
|
|
pub fn contains(&self, point: Point) -> bool {
|
|
|
|
|
self.x <= point.x
|
|
|
|
|
&& point.x <= self.x + self.width
|
|
|
|
|
&& self.y <= point.y
|
|
|
|
|
&& point.y <= self.y + self.height
|
|
|
|
|
}
|
|
|
|
|
}
|