diff options
author | Hans Goudey <h.goudey@me.com> | 2022-03-25 04:58:01 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-03-25 04:58:01 +0300 |
commit | 797a1356caadc8df4b81d065d68dcc2ae4ce8f4b (patch) | |
tree | d08967d3b9d50ac5319c8341ab06d81141c82aef /source/blender/blenkernel/intern | |
parent | 6e72e3fdb295fdfd3e252bd48be96e2d832e43f2 (diff) |
Curves: Tweak evaluated offset functions
Add a function to retrieve the points for an index range of curves,
and move "ensuring" the offsets to a separate function, since it's
often nicer to call that if you don't need the result span immediately.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/curves_geometry.cc | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index a069176c6f3..e31a983e0bb 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -469,16 +469,25 @@ IndexRange CurvesGeometry::evaluated_points_for_curve(int index) const return offsets_to_range(this->runtime->evaluated_offsets_cache.as_span(), index); } -Span<int> CurvesGeometry::evaluated_offsets() const +IndexRange CurvesGeometry::evaluated_points_for_curves(const IndexRange curves) const +{ + BLI_assert(!this->runtime->offsets_cache_dirty); + BLI_assert(this->curve_size > 0); + const int offset = this->runtime->evaluated_offsets_cache[curves.start()]; + const int offset_next = this->runtime->evaluated_offsets_cache[curves.one_after_last()]; + return {offset, offset_next - offset}; +} + +void CurvesGeometry::ensure_evaluated_offsets() const { if (!this->runtime->offsets_cache_dirty) { - return this->runtime->evaluated_offsets_cache; + return; } /* A double checked lock. */ std::scoped_lock lock{this->runtime->offsets_cache_mutex}; if (!this->runtime->offsets_cache_dirty) { - return this->runtime->evaluated_offsets_cache; + return; } threading::isolate_task([&]() { @@ -496,6 +505,11 @@ Span<int> CurvesGeometry::evaluated_offsets() const }); this->runtime->offsets_cache_dirty = false; +} + +Span<int> CurvesGeometry::evaluated_offsets() const +{ + this->ensure_evaluated_offsets(); return this->runtime->evaluated_offsets_cache; } |