blob: 9f2a1350c6898e397adb7b948603308dce8ef916 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
use crate::Point;
/// A rectangle.
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct Rectangle {
/// X coordinate of the top-left corner.
pub x: f32,
/// Y coordinate of the top-left corner.
pub y: f32,
/// Width of the rectangle.
pub width: f32,
/// Height of the rectangle.
pub height: f32,
}
impl Rectangle {
/// Returns true if the given [`Point`] is contained in the [`Rectangle`].
///
/// [`Point`]: struct.Point.html
/// [`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
}
}
|