Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-05-05 00:28:22 +0300
committerHans Goudey <h.goudey@me.com>2021-05-05 00:28:22 +0300
commit7ab7ae80c5a32be2cf4003f818e09fa3f1759fc4 (patch)
tree3ef4fa0e2fc983dccd61814f54646a672797da5b /source/blender/blenkernel/intern/spline_bezier.cc
parent441160930b3e8163a381807fc76f39a18836a014 (diff)
Fix: Incorrect cyclic interpolation for nodes bezier spline
The special case for the interpolation to the last point was being used for every point in the last segment, because of the rounding. Instead, make the function slightly more complicated to properly handle the correct interolation in the cyclic and non-cyclic cases.
Diffstat (limited to 'source/blender/blenkernel/intern/spline_bezier.cc')
-rw-r--r--source/blender/blenkernel/intern/spline_bezier.cc19
1 files changed, 13 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc
index 4981f441190..c52f71002d7 100644
--- a/source/blender/blenkernel/intern/spline_bezier.cc
+++ b/source/blender/blenkernel/intern/spline_bezier.cc
@@ -423,15 +423,22 @@ BezierSpline::InterpolationData BezierSpline::interpolation_data_from_index_fact
const float index_factor) const
{
const int points_len = this->size();
- const int index = std::floor(index_factor);
- if (index == points_len) {
- BLI_assert(is_cyclic_);
+
+ if (is_cyclic_) {
+ if (index_factor < points_len) {
+ const int index = std::floor(index_factor);
+ const int next_index = (index < points_len - 1) ? index + 1 : 0;
+ return InterpolationData{index, next_index, index_factor - index};
+ }
return InterpolationData{points_len - 1, 0, 1.0f};
}
- if (index == points_len - 1) {
- return InterpolationData{points_len - 2, points_len - 1, 1.0f};
+
+ if (index_factor < points_len - 1) {
+ const int index = std::floor(index_factor);
+ const int next_index = index + 1;
+ return InterpolationData{index, next_index, index_factor - index};
}
- return InterpolationData{index, index + 1, index_factor - index};
+ return InterpolationData{points_len - 2, points_len - 1, 1.0f};
}
/* Use a spline argument to avoid adding this to the header. */