[Bf-blender-cvs] [2b6f0cc8367] master: BLI: add utility methods to IndexMask

Jacques Lucke noreply at git.blender.org
Fri Aug 20 11:51:25 CEST 2021


Commit: 2b6f0cc8367c04df8147cf231b11de4b4b8b41d5
Author: Jacques Lucke
Date:   Fri Aug 20 11:41:24 2021 +0200
Branches: master
https://developer.blender.org/rB2b6f0cc8367c04df8147cf231b11de4b4b8b41d5

BLI: add utility methods to IndexMask

===================================================================

M	source/blender/blenlib/BLI_index_mask.hh

===================================================================

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



More information about the Bf-blender-cvs mailing list