diff --git a/emath/src/pos2.rs b/emath/src/pos2.rs index 7afcb3aa..7fde33cb 100644 --- a/emath/src/pos2.rs +++ b/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)) diff --git a/emath/src/rect.rs b/emath/src/rect.rs index 9a8af43c..d8849c65 100644 --- a/emath/src/rect.rs +++ b/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): diff --git a/emath/src/vec2.rs b/emath/src/vec2.rs index 4a59904c..73450c24 100644 --- a/emath/src/vec2.rs +++ b/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))