Fix: Curve resample duplicates last point for cyclic splines

The last point of the output was at the same location as the
first point of a cyclic spline. The fix is simple, just account for
the cyclic when choosing the sample edge length, and don't
hard code the last sample.
This commit is contained in:
Hans Goudey 2021-05-09 01:33:34 -05:00
parent 7029cc2f8a
commit f694321db0
1 changed files with 5 additions and 2 deletions

View File

@ -286,7 +286,7 @@ Array<float> Spline::sample_uniform_index_factors(const int samples_size) const
}
const float total_length = this->length();
const float sample_length = total_length / (samples_size - 1);
const float sample_length = total_length / (samples_size - (is_cyclic_ ? 0 : 1));
/* Store the length at the previous evaluated point in a variable so it can
* start out at zero (the lengths array doesn't contain 0 for the first point). */
@ -305,7 +305,10 @@ Array<float> Spline::sample_uniform_index_factors(const int samples_size) const
prev_length = length;
}
samples.last() = lengths.size();
if (!is_cyclic_) {
/* In rare cases this can prevent overflow of the stored index. */
samples.last() = lengths.size();
}
return samples;
}