diff --git a/extern/mantaflow/helper/util/vectorbase.h b/extern/mantaflow/helper/util/vectorbase.h index b05f90939d4..fbdfd8a4851 100644 --- a/extern/mantaflow/helper/util/vectorbase.h +++ b/extern/mantaflow/helper/util/vectorbase.h @@ -402,10 +402,10 @@ inline const Vector3D &projectNormalTo(const Vector3D &v, const Vector3D inline S norm(const Vector3D &v) { - S l = v.x * v.x + v.y * v.y + v.z * v.z; - if (l <= VECTOR_EPSILON * VECTOR_EPSILON) + S l = std::hypot(v.x, v.y, v.z); + if (l <= VECTOR_EPSILON) return (0.); - return (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON) ? 1. : sqrt(l); + return (fabs(l - 1.) < VECTOR_EPSILON) ? 1. : l; } //! Compute squared magnitude @@ -465,11 +465,11 @@ template inline Vector3D abs(const Vector3D &v) //! Returns a normalized vector template inline Vector3D getNormalized(const Vector3D &v) { - S l = v.x * v.x + v.y * v.y + v.z * v.z; - if (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON) + S l = std::hypot(v.x, v.y, v.z); + if (fabs(l - 1.) < VECTOR_EPSILON) return v; /* normalized "enough"... */ - else if (l > VECTOR_EPSILON * VECTOR_EPSILON) { - S fac = 1. / sqrt(l); + else if (l > VECTOR_EPSILON) { + S fac = 1. / l; return Vector3D(v.x * fac, v.y * fac, v.z * fac); } else @@ -481,13 +481,13 @@ template inline Vector3D getNormalized(const Vector3D &v) template inline S normalize(Vector3D &v) { S norm; - S l = v.x * v.x + v.y * v.y + v.z * v.z; - if (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON) { + S l = std::hypot(v.x, v.y, v.z); + if (fabs(l - 1.) < VECTOR_EPSILON) { norm = 1.; } - else if (l > VECTOR_EPSILON * VECTOR_EPSILON) { - norm = sqrt(l); - v *= 1. / norm; + else if (l > VECTOR_EPSILON) { + norm = l; + v *= 1. / l; } else { v = Vector3D::Zero;