Browse Source

emath: add any_nan to Vec2, Pos2 and Rect

pull/241/head
Emil Ernerfeldt 4 years ago
parent
commit
5621a46b4b
  1. 6
      emath/src/pos2.rs
  2. 7
      emath/src/rect.rs
  3. 5
      emath/src/vec2.rs

6
emath/src/pos2.rs

@ -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))

7
emath/src/rect.rs

@ -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):

5
emath/src/vec2.rs

@ -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…
Cancel
Save