Add finite check for normalize() in vector classes

This commit is contained in:
Silc Lizard (Tokage) Renew
2026-02-18 17:28:27 +09:00
parent a3e84cc2af
commit db90de4dbd
11 changed files with 69 additions and 20 deletions
+12 -2
View File
@@ -50,8 +50,18 @@ real_t Vector2::length_squared() const {
}
void Vector2::normalize() {
real_t l = x * x + y * y;
if (l != 0) {
if (!is_finite()) {
#ifdef MATH_CHECKS
WARN_PRINT("Vector2 cannot be normalized, the elements must be finite. Making (0, 0) as a fallback.");
#endif // MATH_CHECKS
zero();
return;
}
real_t l = length_squared();
if (l == 0) {
zero();
} else {
l = Math::sqrt(l);
x /= l;
y /= l;