emath: add any_nan to Vec2, Pos2 and Rect
This commit is contained in:
parent
4e852727c0
commit
5621a46b4b
3 changed files with 18 additions and 0 deletions
|
@ -122,10 +122,16 @@ impl Pos2 {
|
|||
pos2(self.x.ceil(), self.y.ceil())
|
||||
}
|
||||
|
||||
/// True if all members are also finite.
|
||||
pub fn is_finite(self) -> bool {
|
||||
self.x.is_finite() && self.y.is_finite()
|
||||
}
|
||||
|
||||
/// True if any member is NaN.
|
||||
pub fn any_nan(self) -> bool {
|
||||
self.x.is_nan() || self.y.is_nan()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn min(self, other: Self) -> Self {
|
||||
pos2(self.x.min(other.x), self.y.min(other.y))
|
||||
|
|
|
@ -163,6 +163,7 @@ impl Rect {
|
|||
Rect::from_min_size(self.min + amnt, self.size())
|
||||
}
|
||||
|
||||
/// The intersection of two `Rect`, i.e. the area covered by both.
|
||||
#[must_use]
|
||||
pub fn intersect(self, other: Rect) -> Self {
|
||||
Self {
|
||||
|
@ -290,9 +291,15 @@ impl Rect {
|
|||
self.max.x < self.min.x || self.max.y < self.min.y
|
||||
}
|
||||
|
||||
/// True if all members are also finite.
|
||||
pub fn is_finite(&self) -> bool {
|
||||
self.min.is_finite() && self.max.is_finite()
|
||||
}
|
||||
|
||||
/// True if any member is NaN.
|
||||
pub fn any_nan(self) -> bool {
|
||||
self.min.any_nan() || self.max.any_nan()
|
||||
}
|
||||
}
|
||||
|
||||
/// ## Convenience functions (assumes origin is towards left top):
|
||||
|
|
|
@ -155,6 +155,11 @@ impl Vec2 {
|
|||
self.x.is_finite() && self.y.is_finite()
|
||||
}
|
||||
|
||||
/// True if any member is NaN.
|
||||
pub fn any_nan(self) -> bool {
|
||||
self.x.is_nan() || self.y.is_nan()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn min(self, other: Self) -> Self {
|
||||
vec2(self.x.min(other.x), self.y.min(other.y))
|
||||
|
|
Loading…
Reference in a new issue