diff options
author | Jacques Lucke <jacques@blender.org> | 2022-07-26 16:25:59 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-07-26 16:25:59 +0300 |
commit | 5945a90df99b919229c876c2fd294f035e24831a (patch) | |
tree | df62a734b869784fd68c4afc73b04fc45172181b /source/blender/blenkernel/intern/curve_poly.cc | |
parent | 72f77598a2453afa999046c8092d476a3f412aa1 (diff) |
Fix T98788: bad first curve tangent when first points have same position
Diffstat (limited to 'source/blender/blenkernel/intern/curve_poly.cc')
-rw-r--r-- | source/blender/blenkernel/intern/curve_poly.cc | 17 |
1 files changed, 15 insertions, 2 deletions
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) { |