File tree Expand file tree Collapse file tree 17 files changed +174
-0
lines changed Expand file tree Collapse file tree 17 files changed +174
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,13 @@ impl Mat2 {
150150 // }
151151 // }
152152
153+ /// Returns `true` if, and only if, all elements are finite.
154+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
155+ #[ inline]
156+ pub fn is_finite ( & self ) -> bool {
157+ self . x_axis . is_finite ( ) && self . y_axis . is_finite ( )
158+ }
159+
153160 /// Returns the transpose of `self`.
154161 #[ inline]
155162 pub fn transpose ( & self ) -> Self {
Original file line number Diff line number Diff line change @@ -255,6 +255,13 @@ impl Mat3 {
255255 // }
256256 // }
257257
258+ /// Returns `true` if, and only if, all elements are finite.
259+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
260+ #[ inline]
261+ pub fn is_finite ( & self ) -> bool {
262+ self . x_axis . is_finite ( ) && self . y_axis . is_finite ( ) && self . z_axis . is_finite ( )
263+ }
264+
258265 /// Returns the transpose of `self`.
259266 #[ inline]
260267 pub fn transpose ( & self ) -> Self {
Original file line number Diff line number Diff line change @@ -344,6 +344,16 @@ impl Mat4 {
344344 // }
345345 // }
346346
347+ /// Returns `true` if, and only if, all elements are finite.
348+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
349+ #[ inline]
350+ pub fn is_finite ( & self ) -> bool {
351+ self . x_axis . is_finite ( )
352+ && self . y_axis . is_finite ( )
353+ && self . z_axis . is_finite ( )
354+ && self . w_axis . is_finite ( )
355+ }
356+
347357 /// Returns the transpose of `self`.
348358 #[ inline]
349359 pub fn transpose ( & self ) -> Self {
Original file line number Diff line number Diff line change @@ -287,6 +287,13 @@ impl Quat {
287287 Self ( self . 0 . mul ( inv_len) )
288288 }
289289
290+ /// Returns `true` if, and only if, all elements are finite.
291+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
292+ #[ inline]
293+ pub fn is_finite ( & self ) -> bool {
294+ self . x . is_finite ( ) && self . y . is_finite ( ) && self . z . is_finite ( ) && self . w . is_finite ( )
295+ }
296+
290297 /// Returns whether `self` of length `1.0` or not.
291298 ///
292299 /// Uses a precision threshold of `1e-6`.
Original file line number Diff line number Diff line change @@ -193,6 +193,13 @@ impl TransformRT {
193193 }
194194 }
195195
196+ /// Returns `true` if, and only if, all elements are finite.
197+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
198+ #[ inline]
199+ pub fn is_finite ( & self ) -> bool {
200+ self . rotation . is_finite ( ) && self . translation . is_finite ( )
201+ }
202+
196203 #[ inline]
197204 pub fn inverse ( & self ) -> Self {
198205 let rotation = self . rotation . conjugate ( ) ;
Original file line number Diff line number Diff line change @@ -75,6 +75,13 @@ impl Vec2 {
7575 is_normalized ! ( self )
7676 }
7777
78+ /// Returns `true` if, and only if, all elements are finite.
79+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
80+ #[ inline]
81+ pub fn is_finite ( & self ) -> bool {
82+ self . x . is_finite ( ) && self . y . is_finite ( )
83+ }
84+
7885 /// Returns true if the absolute difference of all elements between `self`
7986 /// and `other` is less than or equal to `max_abs_diff`.
8087 ///
Original file line number Diff line number Diff line change @@ -393,6 +393,13 @@ impl Vec3 {
393393 self + ( ( other - self ) * s)
394394 }
395395
396+ /// Returns `true` if, and only if, all elements are finite.
397+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
398+ #[ inline]
399+ pub fn is_finite ( & self ) -> bool {
400+ self . x . is_finite ( ) && self . y . is_finite ( ) && self . z . is_finite ( )
401+ }
402+
396403 /// Returns whether `self` of length `1.0` or not.
397404 ///
398405 /// Uses a precision threshold of `1e-6`.
Original file line number Diff line number Diff line change @@ -668,6 +668,13 @@ impl Vec3A {
668668 is_normalized ! ( self )
669669 }
670670
671+ /// Returns `true` if, and only if, all elements are finite.
672+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
673+ #[ inline]
674+ pub fn is_finite ( & self ) -> bool {
675+ self . x . is_finite ( ) && self . y . is_finite ( ) && self . z . is_finite ( )
676+ }
677+
671678 /// Returns true if the absolute difference of all elements between `self`
672679 /// and `other` is less than or equal to `max_abs_diff`.
673680 ///
Original file line number Diff line number Diff line change @@ -713,6 +713,13 @@ impl Vec4 {
713713 self + ( ( other - self ) * s)
714714 }
715715
716+ /// Returns `true` if, and only if, all elements are finite.
717+ /// If any element is either `NaN`, positive or negative infinity, this will return `false`.
718+ #[ inline]
719+ pub fn is_finite ( & self ) -> bool {
720+ self . x . is_finite ( ) && self . y . is_finite ( ) && self . z . is_finite ( ) && self . w . is_finite ( )
721+ }
722+
716723 /// Returns whether `self` is length `1.0` or not.
717724 ///
718725 /// Uses a precision threshold of `1e-6`.
Original file line number Diff line number Diff line change @@ -198,3 +198,14 @@ fn test_product() {
198198 let two = Mat2 :: identity ( ) + Mat2 :: identity ( ) ;
199199 assert_eq ! ( vec![ two, two] . iter( ) . product:: <Mat2 >( ) , two * two) ;
200200}
201+
202+ #[ test]
203+ fn test_mat2_is_finite ( ) {
204+ use std:: f32:: INFINITY ;
205+ use std:: f32:: NAN ;
206+ use std:: f32:: NEG_INFINITY ;
207+ assert ! ( Mat2 :: identity( ) . is_finite( ) ) ;
208+ assert ! ( !( Mat2 :: identity( ) * INFINITY ) . is_finite( ) ) ;
209+ assert ! ( !( Mat2 :: identity( ) * NEG_INFINITY ) . is_finite( ) ) ;
210+ assert ! ( !( Mat2 :: identity( ) * NAN ) . is_finite( ) ) ;
211+ }
You can’t perform that action at this time.
0 commit comments