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`].
|
||||
/// Excludes the right and bottom edges.
|
||||
pub fn contains(&self, point: Point) -> bool {
|
||||
self.x <= point.x
|
||||
&& point.x < self.x + self.width
|
||||
|
|
@ -182,13 +183,13 @@ impl Rectangle<f32> {
|
|||
)
|
||||
}
|
||||
|
||||
/// Returns true if the current [`Rectangle`] is completely within the given
|
||||
/// `container`.
|
||||
/// Returns true if the current [`Rectangle`] is within the given
|
||||
/// `container`. Includes the right and bottom edges.
|
||||
pub fn is_within(&self, container: &Rectangle) -> bool {
|
||||
container.contains(self.position())
|
||||
&& container.contains(
|
||||
self.position() + Vector::new(self.width, self.height),
|
||||
)
|
||||
self.x >= container.x
|
||||
&& self.y >= container.y
|
||||
&& self.x + self.width <= container.x + container.width
|
||||
&& self.y + self.height <= container.y + container.height
|
||||
}
|
||||
|
||||
/// Computes the intersection with the given [`Rectangle`].
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue