Cleanup: Use OffsetIndices class in more cases

The same logic from D17025 is used in other places in the curve code.
This patch uses the class for the evaluated point offsets and the Bezier
control point offsets. This helps to standardize the behavior and make
it easier to read.

Previously the Bezier control point offsets used a slightly different standard
where the first point was the first offset, just so they could have the same
size as the number of points. However two nodes used a helper function
to use the same `OffsetIndices` system, so switch to that there too.
That requires removing the subtraction by one to find the actual offset.

Also add const when accessing data arrays from curves, for consistency.

Differential Revision: https://developer.blender.org/D17038
This commit is contained in:
2023-01-19 13:48:20 -06:00
parent d3ea931647
commit 38a45e46bc
16 changed files with 323 additions and 310 deletions

View File

@@ -39,6 +39,18 @@ template<typename T> class OffsetIndices {
return size;
}
/** Return the total number of elements in the the referenced arrays. */
T total_size() const
{
return offsets_.last();
}
/** Return the number of ranges encoded by the offsets. */
T ranges_num() const
{
return offsets_.size() - 1;
}
IndexRange operator[](const int64_t index) const
{
BLI_assert(index >= 0);
@@ -56,6 +68,17 @@ template<typename T> class OffsetIndices {
const int64_t size = end - begin;
return IndexRange(begin, size);
}
/**
* Return a subset of the offsets desribing the specified range of source elements.
* This is a slice into the source ranges rather than the indexed elements described by the
* offset values.
*/
OffsetIndices slice(const IndexRange range) const
{
BLI_assert(offsets_.index_range().drop_back(1).contains(range.last()));
return OffsetIndices(offsets_.slice(range.start(), range.one_after_last()));
}
};
/**