fix: Rectangle::is_within inconsistency
This commit is contained in:
parent
cd60385b1e
commit
d4a692d147
1 changed files with 7 additions and 6 deletions
|
|
@ -137,6 +137,7 @@ impl Rectangle<f32> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the given [`Point`] is contained in the [`Rectangle`].
|
/// Returns true if the given [`Point`] is contained in the [`Rectangle`].
|
||||||
|
/// Excludes the right and bottom edges.
|
||||||
pub fn contains(&self, point: Point) -> bool {
|
pub fn contains(&self, point: Point) -> bool {
|
||||||
self.x <= point.x
|
self.x <= point.x
|
||||||
&& point.x < self.x + self.width
|
&& point.x < self.x + self.width
|
||||||
|
|
@ -182,13 +183,13 @@ impl Rectangle<f32> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the current [`Rectangle`] is completely within the given
|
/// Returns true if the current [`Rectangle`] is within the given
|
||||||
/// `container`.
|
/// `container`. Includes the right and bottom edges.
|
||||||
pub fn is_within(&self, container: &Rectangle) -> bool {
|
pub fn is_within(&self, container: &Rectangle) -> bool {
|
||||||
container.contains(self.position())
|
self.x >= container.x
|
||||||
&& container.contains(
|
&& self.y >= container.y
|
||||||
self.position() + Vector::new(self.width, self.height),
|
&& self.x + self.width <= container.x + container.width
|
||||||
)
|
&& self.y + self.height <= container.y + container.height
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the intersection with the given [`Rectangle`].
|
/// Computes the intersection with the given [`Rectangle`].
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue