[Bf-blender-cvs] [37ee7f20e76] newboolean: Update integer type usage

Jacques Lucke noreply at git.blender.org
Mon Jul 20 13:38:17 CEST 2020


Commit: 37ee7f20e7692b2ca2968a183f33a160028fef92
Author: Jacques Lucke
Date:   Mon Jul 20 13:35:58 2020 +0200
Branches: newboolean
https://developer.blender.org/rB37ee7f20e7692b2ca2968a183f33a160028fef92

Update integer type usage

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

M	source/blender/blenlib/BLI_mesh_intersect.hh
M	source/blender/blenlib/BLI_mpq2.hh
M	source/blender/blenlib/BLI_mpq3.hh
M	source/blender/blenlib/intern/boolean.cc
M	source/blender/blenlib/intern/delaunay_2d.cc
M	source/blender/blenlib/intern/math_vec.cc
M	source/blender/blenlib/intern/mesh_intersect.cc
M	source/blender/bmesh/tools/bmesh_boolean.cc
M	tests/gtests/blenlib/BLI_delaunay_2d_test.cc
M	tests/gtests/blenlib/BLI_mesh_intersect_test.cc

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

diff --git a/source/blender/blenlib/BLI_mesh_intersect.hh b/source/blender/blenlib/BLI_mesh_intersect.hh
index 72ea71a0879..1b3a7d81181 100644
--- a/source/blender/blenlib/BLI_mesh_intersect.hh
+++ b/source/blender/blenlib/BLI_mesh_intersect.hh
@@ -37,7 +37,6 @@
 namespace blender::meshintersect {
 
 constexpr int NO_INDEX = -1;
-constexpr uint NO_INDEX_U = UINT_MAX;
 
 /* Vertex coordinates are stored both as double3 and mpq3, which should agree.
  * Most calculations are done in exact arithmetic, using the mpq3 version,
@@ -73,7 +72,7 @@ struct Vert {
   bool operator==(const Vert &other) const;
 
   /* Hash on the co_exact field. */
-  uint32_t hash() const;
+  uint64_t hash() const;
 };
 
 /* Use Vertp for Verts everywhere: can modify the pointer
@@ -98,7 +97,7 @@ struct Plane {
   bool operator==(const Plane &other) const;
 
   /* Hash onthe exact fields. */
-  uint32_t hash() const;
+  uint64_t hash() const;
 
   void make_canonical();
 };
@@ -123,7 +122,7 @@ struct Face {
   int id = NO_INDEX;
   int orig = NO_INDEX;
 
-  using FacePos = uint;
+  using FacePos = int;
 
   Face() = default;
   Face(Span<Vertp> verts, int id, int orig, Span<int> edge_origs);
@@ -156,12 +155,12 @@ struct Face {
     return (p + vert.size() - 1) % vert.size();
   }
 
-  const Vertp &operator[](uint index) const
+  const Vertp &operator[](int index) const
   {
     return vert[index];
   }
 
-  uint size() const
+  int size() const
   {
     return vert.size();
   }
@@ -211,8 +210,8 @@ class MArena {
    */
   void reserve(int vert_num_hint, int face_num_hint);
 
-  uint tot_allocated_verts() const;
-  uint tot_allocated_faces() const;
+  int tot_allocated_verts() const;
+  int tot_allocated_faces() const;
 
   /* These add routines find and return an existing Vert with the same
    * co_exact, if it exists (the orig argument is ignored in this case),
@@ -241,8 +240,8 @@ class MArena {
 
 class Mesh {
   Array<Facep> face_;
-  Array<Vertp> vert_;              /* Only valid if vert_populated_. */
-  Map<Vertp, uint> vert_to_index_; /* Only valid if vert_populated_. */
+  Array<Vertp> vert_;             /* Only valid if vert_populated_. */
+  Map<Vertp, int> vert_to_index_; /* Only valid if vert_populated_. */
   bool vert_populated_ = false;
 
  public:
@@ -252,17 +251,17 @@ class Mesh {
   }
 
   void set_faces(Span<Facep> faces);
-  Facep face(uint index) const
+  Facep face(int index) const
   {
     return face_[index];
   }
 
-  uint face_size() const
+  int face_size() const
   {
     return face_.size();
   }
 
-  uint vert_size() const
+  int vert_size() const
   {
     return vert_.size();
   }
@@ -283,16 +282,16 @@ class Mesh {
    * estimate on the maximum number of verts.
    */
   void populate_vert();
-  void populate_vert(uint max_verts);
+  void populate_vert(int max_verts);
 
-  Vertp vert(uint index) const
+  Vertp vert(int index) const
   {
     BLI_assert(vert_populated_);
     return vert_[index];
   }
 
-  /* Returns index in vert_ where v is, or NO_INDEX_U. */
-  uint lookup_vert(Vertp v) const;
+  /* Returns index in vert_ where v is, or NO_INDEX. */
+  int lookup_vert(Vertp v) const;
 
   IndexRange vert_index_range() const
   {
@@ -320,7 +319,7 @@ class Mesh {
    * vertices at the positions in face_pos_erase that are true.
    * Use arena to allocate the new face in.
    */
-  void erase_face_positions(uint f_index, Span<bool> face_pos_erase, MArena *arena);
+  void erase_face_positions(int f_index, Span<bool> face_pos_erase, MArena *arena);
 };
 
 std::ostream &operator<<(std::ostream &os, const Mesh &mesh);
diff --git a/source/blender/blenlib/BLI_mpq2.hh b/source/blender/blenlib/BLI_mpq2.hh
index e585c1d5a0a..771115ca041 100644
--- a/source/blender/blenlib/BLI_mpq2.hh
+++ b/source/blender/blenlib/BLI_mpq2.hh
@@ -169,7 +169,7 @@ struct mpq2 {
   static int incircle(const mpq2 &a, const mpq2 &b, const mpq2 &c, const mpq2 &d);
 
   /* There is a sensible use for hashing on exact arithmetic types. */
-  uint32_t hash() const;
+  uint64_t hash() const;
 };
 
 }  // namespace blender
diff --git a/source/blender/blenlib/BLI_mpq3.hh b/source/blender/blenlib/BLI_mpq3.hh
index 41ebe24053d..9f507ed44b0 100644
--- a/source/blender/blenlib/BLI_mpq3.hh
+++ b/source/blender/blenlib/BLI_mpq3.hh
@@ -262,10 +262,10 @@ struct mpq3 {
   static int orient3d(const mpq3 &a, const mpq3 &b, const mpq3 &c, const mpq3 &d);
 
   /* There is a sensible use for hashing on exact arithmetic types. */
-  uint32_t hash() const;
+  uint64_t hash() const;
 };
 
-uint32_t hash_mpq_class(const mpq_class &value);
+uint64_t hash_mpq_class(const mpq_class &value);
 
 }  // namespace blender
 
diff --git a/source/blender/blenlib/intern/boolean.cc b/source/blender/blenlib/intern/boolean.cc
index 6916bb67c57..1e56a9560ed 100644
--- a/source/blender/blenlib/intern/boolean.cc
+++ b/source/blender/blenlib/intern/boolean.cc
@@ -78,11 +78,11 @@ class Edge {
     return v_[0]->id == other.v_[0]->id && v_[1]->id == other.v_[1]->id;
   }
 
-  uint32_t hash() const
+  uint64_t hash() const
   {
-    constexpr uint32_t h1 = 33;
-    uint32_t v0hash = DefaultHash<int>{}(v_[0]->id);
-    uint32_t v1hash = DefaultHash<int>{}(v_[1]->id);
+    constexpr uint64_t h1 = 33;
+    uint64_t v0hash = DefaultHash<int>{}(v_[0]->id);
+    uint64_t v1hash = DefaultHash<int>{}(v_[1]->id);
     return v0hash ^ (v1hash * h1);
   }
 };
@@ -101,7 +101,7 @@ static std::ostream &operator<<(std::ostream &os, const Edge &e)
 
 static std::ostream &operator<<(std::ostream &os, const Span<int> &a)
 {
-  for (uint i = 0; i < a.size(); ++i) {
+  for (int i : a.index_range()) {
     os << a[i];
     if (i != a.size() - 1) {
       os << " ";
@@ -112,7 +112,7 @@ static std::ostream &operator<<(std::ostream &os, const Span<int> &a)
 
 static std::ostream &operator<<(std::ostream &os, const Span<uint> &a)
 {
-  for (uint i = 0; i < a.size(); ++i) {
+  for (int i : a.index_range()) {
     os << a[i];
     if (i != a.size() - 1) {
       os << " ";
@@ -136,7 +136,7 @@ static std::ostream &operator<<(std::ostream &os, const Array<int> &iarr)
 /* Holds information about topology of a Mesh that is all triangles. */
 class TriMeshTopology {
   /* Triangles that contain a given Edge (either order). */
-  Map<Edge, Vector<uint> *> edge_tri_;
+  Map<Edge, Vector<int> *> edge_tri_;
   /* Edges incident on each vertex. */
   Map<Vertp, Vector<Edge>> vert_edges_;
 
@@ -147,8 +147,8 @@ class TriMeshTopology {
   ~TriMeshTopology();
 
   /* If e is manifold, return index of the other triangle (not t) that has it. Else return
-   * NO_INDEX_U. */
-  uint other_tri_if_manifold(Edge e, int t) const
+   * NO_INDEX. */
+  int other_tri_if_manifold(Edge e, int t) const
   {
     if (edge_tri_.contains(e)) {
       auto *p = edge_tri_.lookup(e);
@@ -156,11 +156,11 @@ class TriMeshTopology {
         return ((*p)[0] == t) ? (*p)[1] : (*p)[0];
       }
     }
-    return NO_INDEX_U;
+    return NO_INDEX;
   }
 
   /* Which triangles share edge e (in either orientation)? */
-  const Vector<uint> *edge_tris(Edge e) const
+  const Vector<int> *edge_tris(Edge e) const
   {
     return edge_tri_.lookup_default(e, nullptr);
   }
@@ -183,11 +183,11 @@ TriMeshTopology::TriMeshTopology(const Mesh &tm)
   /* If everything were manifold, F+V-E=2 and E=3F/2.
    * So an likely overestimate, allowing for non-manifoldness, is E=2F and V=F.
    */
-  const uint estimate_num_edges = 2 * tm.face_size();
-  const uint estimate_num_verts = tm.face_size();
+  const int estimate_num_edges = 2 * tm.face_size();
+  const int estimate_num_verts = tm.face_size();
   edge_tri_.reserve(estimate_num_edges);
   vert_edges_.reserve(estimate_num_verts);
-  for (uint t : tm.face_index_range()) {
+  for (int t : tm.face_index_range()) {
     const Face &tri = *tm.face(t);
     BLI_assert(tri.is_tri());
     for (int i = 0; i < 3; ++i) {
@@ -201,8 +201,8 @@ TriMeshTopology::TriMeshTopology(const Mesh &tm)
         BLI_assert(edges != nullptr);
       }
       edges->append_non_duplicates(e);
-      auto createf = [t](Vector<uint> **pvec) { *pvec = new Vector<uint>{t}; };
-      auto modifyf = [t](Vector<uint> **pvec) { (*pvec)->append_non_duplicates(t); };
+      auto createf = [t](Vector<int> **pvec) { *pvec = new Vector<int>{t}; };
+      auto modifyf = [t](Vector<int> **pvec) { (*pvec)->append_non_duplicates(t); };
       this->edge_tri_.add_or_modify(Edge(v, vnext), createf, modifyf);
     }
   }
@@ -228,13 +228,14 @@ TriMeshTopology::TriMeshTopology(const Mesh &tm)
 
 TriMeshTopology::~TriMeshTopology()
 {
-  auto deletef = [](const Edge &UNUSED(e), const Vector<uint> *vec) { delete vec; };
-  edge_tri_.foreach_item(deletef);
+  for (const Vector<int> *vec : edge_tri_.values()) {
+    delete vec;
+  }
 }
 
 /* A Patch is a maximal set of triangles that share manifold edges only. */
 class Patch {
-  Vector<uint> tri_; /* Indices of triangles in the Patch. */
+  Vector<int> tri_; /* Indices of triangles in the Patch. */
 
  public:
   Patch() = default;
@@ -244,17 +245,17 @@ class Patch {
     tri_.append(t);
   }
 
-  const Vector<uint> &tri() const
+  const Vector<int> &tri() const
   {
     return tri_;
   }
 
-  uint tot_tri() const
+  int tot_tri() const
   {
     return tri_.size();
   }
 
-  uint tri(uint i) const
+  int tri(int i) const
   {
     return tri_[i];
   }
@@ -264,25 +265,25 @@ class Patch {
     return IndexRange(tri_.size());
   }
 
-  Span<uint> tris() const
+  Span<int> tris() const
   {
-    return Span<uint>(tri_);
+    return Span<int>(tri_);
   }
 
-  uint cell_above{NO_INDEX_U};
-  uint cell_below{NO_INDEX_U};
+  int cell_above{NO_INDEX};
+  int cell_below{NO_INDEX};
 };
 
 static std::ostream &operator<<(std::ostream &os, const Patch &patch)
 {
   os << "Patch " << patch.tri();
-  if (patch.cell_above != NO_INDEX_U) {
+  if (patch.cell_above != NO_INDEX) {
     os << " cell_above=" << patch.cell_above;
   }
   else {
     os << " cell_above not set";
   }
-  if (patch.cell_below != NO_INDEX_U) {
+  if (patch.cell_below != NO_INDEX) {
     os << " cell_below=" << patch.cell_below;
   }
   else {
@@ -295,51 +296,51 @@ class PatchesInfo {
   /* All of the Patches for a Mesh. */
   Vector<Patch> patch_;
   /* Patch index for corresponding trian

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list