Files
workinf_Blender_Wasm/blender-5.2.0/extern/mantaflow/patches/fix-computation-errors.patch
2026-08-12 04:47:48 -04:00

54 lines
1.9 KiB
Diff

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<S> &projectNormalTo(const Vector3D<S> &v, const Vector3D<S
//! (clamps to 0 and 1 with VECTOR_EPSILON)
template<class S> inline S norm(const Vector3D<S> &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<class S> inline Vector3D<S> abs(const Vector3D<S> &v)
//! Returns a normalized vector
template<class S> inline Vector3D<S> getNormalized(const Vector3D<S> &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<S>(v.x * fac, v.y * fac, v.z * fac);
}
else
@@ -481,13 +481,13 @@ template<class S> inline Vector3D<S> getNormalized(const Vector3D<S> &v)
template<class S> inline S normalize(Vector3D<S> &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<S>::Zero;