2019-07-20 19:12:31 +02:00
|
|
|
use crate::Point;
|
|
|
|
|
|
2019-08-31 04:31:13 +02:00
|
|
|
/// A rectangle.
|
2019-09-03 13:56:43 +02:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
pub struct Rectangle<T = f32> {
|
2019-07-20 19:12:31 +02:00
|
|
|
/// X coordinate of the top-left corner.
|
2019-09-03 13:56:43 +02:00
|
|
|
pub x: T,
|
2019-07-20 19:12:31 +02:00
|
|
|
|
|
|
|
|
/// Y coordinate of the top-left corner.
|
2019-09-03 13:56:43 +02:00
|
|
|
pub y: T,
|
2019-07-20 19:12:31 +02:00
|
|
|
|
|
|
|
|
/// Width of the rectangle.
|
2019-09-03 13:56:43 +02:00
|
|
|
pub width: T,
|
2019-07-20 19:12:31 +02:00
|
|
|
|
|
|
|
|
/// Height of the rectangle.
|
2019-09-03 13:56:43 +02:00
|
|
|
pub height: T,
|
2019-07-20 19:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-03 13:56:43 +02:00
|
|
|
impl Rectangle<f32> {
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|