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.
This commit is contained in:
parent
6e72e3fdb2
commit
797a1356ca
|
@ -250,6 +250,7 @@ class CurvesGeometry : public ::CurvesGeometry {
|
|||
* Call #evaluated_offsets() first to ensure that the evaluated offsets cache is current.
|
||||
*/
|
||||
IndexRange evaluated_points_for_curve(int index) const;
|
||||
IndexRange evaluated_points_for_curves(IndexRange curves) const;
|
||||
|
||||
/**
|
||||
* The index of the first evaluated point for every curve. The size of this span is one larger
|
||||
|
@ -258,6 +259,9 @@ class CurvesGeometry : public ::CurvesGeometry {
|
|||
*/
|
||||
Span<int> evaluated_offsets() const;
|
||||
|
||||
/** Makes sure the data described by #evaluated_offsets if necessary. */
|
||||
void ensure_evaluated_offsets() const;
|
||||
|
||||
Span<float3> evaluated_positions() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue