From ef50b3c9f69e65c36dc1bd7dead36fbcd90e28ad Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Mon, 20 Nov 2023 10:42:57 +0100 Subject: [PATCH] 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` --- crates/bevy_transform/src/components/transform.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index 451579f6f3..95a5881858 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -396,6 +396,15 @@ impl Transform { point += self.translation; point } + + /// Returns `true` if, and only if, translation, rotation and scale all are + /// finite. If any of them contains a `NaN`, positive or negative infinity, + /// this will return `false`. + #[inline] + #[must_use] + pub fn is_finite(&self) -> bool { + self.translation.is_finite() && self.rotation.is_finite() && self.scale.is_finite() + } } impl Default for Transform {