Skip to content

Commit ef50b3c

Browse files
authored
Add Transform::is_finite (#10592)
# Objective - Sometimes it's very useful to know if a `Transform` contains any `NaN` or infinite values. It's a bit boiler-plate heavy to check translation, rotation and scale individually. ## Solution - Add a new method `is_finite` that returns true if, and only if translation, rotation and scale all are finite. - It's a natural extension of `Quat::is_finite`, and `Vec3::is_finite`, which return true if, and only if all their components' `is_finite()` returns true. --- ## Changelog - Added `Transform::is_finite`
1 parent 78c255f commit ef50b3c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

crates/bevy_transform/src/components/transform.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,15 @@ impl Transform {
396396
point += self.translation;
397397
point
398398
}
399+
400+
/// Returns `true` if, and only if, translation, rotation and scale all are
401+
/// finite. If any of them contains a `NaN`, positive or negative infinity,
402+
/// this will return `false`.
403+
#[inline]
404+
#[must_use]
405+
pub fn is_finite(&self) -> bool {
406+
self.translation.is_finite() && self.rotation.is_finite() && self.scale.is_finite()
407+
}
399408
}
400409

401410
impl Default for Transform {

0 commit comments

Comments
 (0)