Fix: Spline length calculation fails with no evaluated points

The case that checked whether there were evaluated edges was incorrect,
since two points are needed for an edge. Then also avoid running the
accumulation for an empty span.
This commit is contained in:
2021-09-19 19:00:50 -05:00
parent c9e835fec1
commit f973e0b75a

View File

@@ -142,7 +142,8 @@ void Spline::reverse()
int Spline::evaluated_edges_size() const
{
const int eval_size = this->evaluated_points_size();
if (eval_size == 1) {
if (eval_size < 2) {
/* Two points are required for an edge. */
return 0;
}
@@ -205,9 +206,10 @@ Span<float> Spline::evaluated_lengths() const
const int total = evaluated_edges_size();
evaluated_lengths_cache_.resize(total);
Span<float3> positions = this->evaluated_positions();
accumulate_lengths(positions, is_cyclic_, evaluated_lengths_cache_);
if (total != 0) {
Span<float3> positions = this->evaluated_positions();
accumulate_lengths(positions, is_cyclic_, evaluated_lengths_cache_);
}
length_cache_dirty_ = false;
return evaluated_lengths_cache_;