[Bf-blender-cvs] [c0833989210] master: BLI: fix math operation

Jacques Lucke noreply at git.blender.org
Mon Jan 11 14:59:14 CET 2021


Commit: c0833989210714bc6974b77f40e59edc47d0cc68
Author: Jacques Lucke
Date:   Mon Jan 11 14:58:29 2021 +0100
Branches: master
https://developer.blender.org/rBc0833989210714bc6974b77f40e59edc47d0cc68

BLI: fix math operation

That fixes a stupid mistake of mine that was copied a couple of times.

===================================================================

M	source/blender/blenlib/BLI_double2.hh
M	source/blender/blenlib/BLI_double3.hh
M	source/blender/blenlib/BLI_float2.hh
M	source/blender/blenlib/BLI_float3.hh
M	source/blender/blenlib/BLI_mpq2.hh

===================================================================

diff --git a/source/blender/blenlib/BLI_double2.hh b/source/blender/blenlib/BLI_double2.hh
index 621ac4d01fc..0abff01ab2f 100644
--- a/source/blender/blenlib/BLI_double2.hh
+++ b/source/blender/blenlib/BLI_double2.hh
@@ -120,7 +120,8 @@ struct double2 {
 
   static double distance_squared(const double2 &a, const double2 &b)
   {
-    return double2::dot(a, b);
+    double2 diff = a - b;
+    return double2::dot(diff, diff);
   }
 
   struct isect_result {
diff --git a/source/blender/blenlib/BLI_double3.hh b/source/blender/blenlib/BLI_double3.hh
index 5b6204935d7..ab258c9121b 100644
--- a/source/blender/blenlib/BLI_double3.hh
+++ b/source/blender/blenlib/BLI_double3.hh
@@ -218,7 +218,8 @@ struct double3 {
 
   static double distance_squared(const double3 &a, const double3 &b)
   {
-    return double3::dot(a, b);
+    double3 diff = a - b;
+    return double3::dot(diff, diff);
   }
 
   static double3 interpolate(const double3 &a, const double3 &b, double t)
diff --git a/source/blender/blenlib/BLI_float2.hh b/source/blender/blenlib/BLI_float2.hh
index d41c4d262d3..2a5320e4c35 100644
--- a/source/blender/blenlib/BLI_float2.hh
+++ b/source/blender/blenlib/BLI_float2.hh
@@ -141,7 +141,8 @@ struct float2 {
 
   static float distance_squared(const float2 &a, const float2 &b)
   {
-    return float2::dot(a, b);
+    float2 diff = a - b;
+    return float2::dot(diff, diff);
   }
 
   struct isect_result {
diff --git a/source/blender/blenlib/BLI_float3.hh b/source/blender/blenlib/BLI_float3.hh
index 17b3f56453c..9a8870963bf 100644
--- a/source/blender/blenlib/BLI_float3.hh
+++ b/source/blender/blenlib/BLI_float3.hh
@@ -236,7 +236,8 @@ struct float3 {
 
   static float distance_squared(const float3 &a, const float3 &b)
   {
-    return float3::dot(a, b);
+    float3 diff = a - b;
+    return float3::dot(diff, diff);
   }
 
   static float3 interpolate(const float3 &a, const float3 &b, float t)
diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh
index 40e227019ce..18bc8821d9c 100644
--- a/source/blender/blenlib/BLI_mpq2.hh
+++ b/source/blender/blenlib/BLI_mpq2.hh
@@ -156,7 +156,8 @@ struct mpq2 {
 
   static mpq_class distance_squared(const mpq2 &a, const mpq2 &b)
   {
-    return dot(a, b);
+    mpq2 diff = a - b;
+    return dot(diff, diff);
   }
 
   struct isect_result {



More information about the Bf-blender-cvs mailing list