Merge pull request #2966 from DKolter/issue_2965

Fix Rectangle::is_within inconsistency
This commit is contained in:
Héctor 2025-05-30 01:08:37 +02:00 committed by GitHub
commit c86b04f5c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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`].