diff options
author | Jacques Lucke <jacques@blender.org> | 2021-08-20 12:41:24 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-08-20 12:48:31 +0300 |
commit | 2b6f0cc8367c04df8147cf231b11de4b4b8b41d5 (patch) | |
tree | ab741299fc59447f48e8f4bd939914eec8c68597 | |
parent | e95b197e987d3ed5d9efb6b228a7bdb56e1bd7bc (diff) |
BLI: add utility methods to IndexMask
-rw-r--r-- | source/blender/blenlib/BLI_index_mask.hh | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/source/blender/blenlib/BLI_index_mask.hh b/source/blender/blenlib/BLI_index_mask.hh index f04c0e9c80a..7a3169520ca 100644 --- a/source/blender/blenlib/BLI_index_mask.hh +++ b/source/blender/blenlib/BLI_index_mask.hh @@ -58,11 +58,7 @@ class IndexMask { */ IndexMask(Span<int64_t> indices) : indices_(indices) { -#ifdef DEBUG - for (int64_t i = 1; i < indices.size(); i++) { - BLI_assert(indices[i - 1] < indices[i]); - } -#endif + BLI_assert(IndexMask::indices_are_valid_index_mask(indices)); } /** @@ -94,6 +90,22 @@ class IndexMask { { } + /** Checks that the indices are non-negative and in ascending order. */ + static bool indices_are_valid_index_mask(Span<int64_t> indices) + { + if (!indices.is_empty()) { + if (indices.first() < 0) { + return false; + } + } + for (int64_t i = 1; i < indices.size(); i++) { + if (indices[i - 1] >= indices[i]) { + return false; + } + } + return true; + } + operator Span<int64_t>() const { return indices_; @@ -204,6 +216,11 @@ class IndexMask { { return indices_.size(); } + + bool is_empty() const + { + return indices_.is_empty(); + } }; } // namespace blender |