Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/spline_base.cc
| Show First 20 Lines • Show All 411 Lines • ▼ Show 20 Lines | Spline::LookupResult Spline::lookup_evaluated_length(const float length) const | ||||
| Span<float> lengths = this->evaluated_lengths(); | Span<float> lengths = this->evaluated_lengths(); | ||||
| const float *offset = std::lower_bound(lengths.begin(), lengths.end(), length); | const float *offset = std::lower_bound(lengths.begin(), lengths.end(), length); | ||||
| const int index = offset - lengths.begin(); | const int index = offset - lengths.begin(); | ||||
| const int next_index = (index == this->evaluated_points_size() - 1) ? 0 : index + 1; | const int next_index = (index == this->evaluated_points_size() - 1) ? 0 : index + 1; | ||||
| const float previous_length = (index == 0) ? 0.0f : lengths[index - 1]; | const float previous_length = (index == 0) ? 0.0f : lengths[index - 1]; | ||||
| const float factor = (length - previous_length) / (lengths[index] - previous_length); | const float length_in_segment = length - previous_length; | ||||
| const float segment_length = lengths[index] - previous_length; | |||||
| const float factor = segment_length == 0.0f ? 0.0f : length_in_segment / segment_length; | |||||
| return LookupResult{index, next_index, factor}; | return LookupResult{index, next_index, factor}; | ||||
| } | } | ||||
| Array<float> Spline::sample_uniform_index_factors(const int samples_size) const | Array<float> Spline::sample_uniform_index_factors(const int samples_size) const | ||||
| { | { | ||||
| const Span<float> lengths = this->evaluated_lengths(); | const Span<float> lengths = this->evaluated_lengths(); | ||||
| ▲ Show 20 Lines • Show All 100 Lines • Show Last 20 Lines | |||||