[Bf-blender-cvs] [5945a90df99] master: Fix T98788: bad first curve tangent when first points have same position

Jacques Lucke noreply at git.blender.org
Tue Jul 26 15:26:07 CEST 2022


Commit: 5945a90df99b919229c876c2fd294f035e24831a
Author: Jacques Lucke
Date:   Tue Jul 26 15:25:59 2022 +0200
Branches: master
https://developer.blender.org/rB5945a90df99b919229c876c2fd294f035e24831a

Fix T98788: bad first curve tangent when first points have same position

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

M	source/blender/blenkernel/intern/curve_poly.cc

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

diff --git a/source/blender/blenkernel/intern/curve_poly.cc b/source/blender/blenkernel/intern/curve_poly.cc
index 7ab92068d81..2b2cf9adeee 100644
--- a/source/blender/blenkernel/intern/curve_poly.cc
+++ b/source/blender/blenkernel/intern/curve_poly.cc
@@ -65,8 +65,21 @@ void calculate_tangents(const Span<float3> positions,
     tangents.last() = direction_bisect(second_to_last, last, first, used_fallback);
   }
   else {
-    tangents.first() = math::normalize(positions[1] - positions.first());
-    tangents.last() = math::normalize(positions.last() - positions[positions.size() - 2]);
+    const float epsilon = 1e-6f;
+    if (math::almost_equal_relative(positions[0], positions[1], epsilon)) {
+      tangents.first() = {0.0f, 0.0f, 0.0f};
+      used_fallback = true;
+    }
+    else {
+      tangents.first() = math::normalize(positions[1] - positions[0]);
+    }
+    if (math::almost_equal_relative(positions.last(0), positions.last(1), epsilon)) {
+      tangents.last() = {0.0f, 0.0f, 0.0f};
+      used_fallback = true;
+    }
+    else {
+      tangents.last() = math::normalize(positions.last(0) - positions.last(1));
+    }
   }
 
   if (!used_fallback) {



More information about the Bf-blender-cvs mailing list