diff options
author | Hans Goudey <h.goudey@me.com> | 2022-07-04 19:50:33 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-07-04 19:51:10 +0300 |
commit | dccdc6213ec6ff3c3ff681090f56648ec4023034 (patch) | |
tree | 4ed21ee7c9554b7a1b3ef69edb2f45b16d63c1c8 /source | |
parent | 8fb8a6529fa64d6e17042cdf469d9920eb939660 (diff) |
Curves: Expose function to calculate vector handles
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_curves.hh | 13 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve_bezier.cc | 4 |
2 files changed, 15 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh index b1f096b1c39..cc0c607f9bb 100644 --- a/source/blender/blenkernel/BKE_curves.hh +++ b/source/blender/blenkernel/BKE_curves.hh @@ -516,6 +516,14 @@ void calculate_evaluated_offsets(Span<int8_t> handle_types_left, MutableSpan<int> evaluated_offsets); /** + * Calculate the automatically defined positions for a vector handle (#BEZIER_HANDLE_VECTOR). While + * this can be calculated automatically with #calculate_auto_handles, when more context is + * available, it can be preferable for performance reasons to calculate it for a single segment + * when necessary. + */ +float3 calculate_vector_handle(const float3 &point, const float3 &next_point); + +/** * Recalculate all auto (#BEZIER_HANDLE_AUTO) and vector (#BEZIER_HANDLE_VECTOR) handles with * positions automatically derived from the neighboring control points, and update aligned * (#BEZIER_HANDLE_ALIGN) handles to line up with neighboring non-aligned handles. The choices @@ -819,6 +827,11 @@ inline bool point_is_sharp(const Span<int8_t> handle_types_left, ELEM(handle_types_right[index], BEZIER_HANDLE_VECTOR, BEZIER_HANDLE_FREE); } +inline float3 calculate_vector_handle(const float3 &point, const float3 &next_point) +{ + return math::interpolate(point, next_point, 1.0f / 3.0f); +} + /** \} */ } // namespace curves::bezier diff --git a/source/blender/blenkernel/intern/curve_bezier.cc b/source/blender/blenkernel/intern/curve_bezier.cc index 5ba17f1761b..1d6ee4938b5 100644 --- a/source/blender/blenkernel/intern/curve_bezier.cc +++ b/source/blender/blenkernel/intern/curve_bezier.cc @@ -106,11 +106,11 @@ static void calculate_point_handles(const HandleType type_left, } if (type_left == BEZIER_HANDLE_VECTOR) { - left = math::interpolate(position, prev_position, 1.0f / 3.0f); + left = calculate_vector_handle(position, prev_position); } if (type_right == BEZIER_HANDLE_VECTOR) { - right = math::interpolate(position, next_position, 1.0f / 3.0f); + right = calculate_vector_handle(position, next_position); } /* When one of the handles is "aligned" handle, it must be aligned with the other, i.e. point in |