[Bf-blender-cvs] [6bea434c419] master: Cleanup: Move bmesh_query_uv.c to C++

Hans Goudey noreply at git.blender.org
Fri Aug 26 20:57:46 CEST 2022


Commit: 6bea434c41951686949bcb9abfcabc23ab7fad9f
Author: Hans Goudey
Date:   Fri Aug 26 13:56:43 2022 -0500
Branches: master
https://developer.blender.org/rB6bea434c41951686949bcb9abfcabc23ab7fad9f

Cleanup: Move bmesh_query_uv.c to C++

Helpful for D14365.

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

M	source/blender/bmesh/CMakeLists.txt
R070	source/blender/bmesh/intern/bmesh_query_uv.c	source/blender/bmesh/intern/bmesh_query_uv.cc

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

diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt
index 0d1eeab8eec..0efa5f73ae4 100644
--- a/source/blender/bmesh/CMakeLists.txt
+++ b/source/blender/bmesh/CMakeLists.txt
@@ -111,7 +111,7 @@ set(SRC
   intern/bmesh_query.c
   intern/bmesh_query.h
   intern/bmesh_query_inline.h
-  intern/bmesh_query_uv.c
+  intern/bmesh_query_uv.cc
   intern/bmesh_query_uv.h
   intern/bmesh_structure.c
   intern/bmesh_structure.h
diff --git a/source/blender/bmesh/intern/bmesh_query_uv.c b/source/blender/bmesh/intern/bmesh_query_uv.cc
similarity index 70%
rename from source/blender/bmesh/intern/bmesh_query_uv.c
rename to source/blender/bmesh/intern/bmesh_query_uv.cc
index 1225543cd06..5a725407c6b 100644
--- a/source/blender/bmesh/intern/bmesh_query_uv.c
+++ b/source/blender/bmesh/intern/bmesh_query_uv.cc
@@ -6,9 +6,10 @@
 
 #include "MEM_guardedalloc.h"
 
-#include "BLI_alloca.h"
+#include "BLI_array.hh"
 #include "BLI_linklist.h"
 #include "BLI_math.h"
+#include "BLI_math_vec_types.hh"
 #include "BLI_utildefines_stack.h"
 
 #include "BKE_customdata.h"
@@ -80,7 +81,7 @@ void BM_face_uv_calc_center_median(const BMFace *f, const int cd_loop_uv_offset,
   zero_v2(r_cent);
   l_iter = l_first = BM_FACE_FIRST_LOOP(f);
   do {
-    const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
+    const MLoopUV *luv = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
     add_v2_v2(r_cent, luv->uv);
   } while ((l_iter = l_iter->next) != l_first);
 
@@ -89,16 +90,16 @@ void BM_face_uv_calc_center_median(const BMFace *f, const int cd_loop_uv_offset,
 
 float BM_face_uv_calc_cross(const BMFace *f, const int cd_loop_uv_offset)
 {
-  float(*uvs)[2] = BLI_array_alloca(uvs, f->len);
+  blender::Array<blender::float2, BM_DEFAULT_NGON_STACK_SIZE> uvs(f->len);
   const BMLoop *l_iter;
   const BMLoop *l_first;
   int i = 0;
   l_iter = l_first = BM_FACE_FIRST_LOOP(f);
   do {
-    const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
-    copy_v2_v2(uvs[i++], luv->uv);
+    const MLoopUV *luv = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
+    uvs[i++] = luv->uv;
   } while ((l_iter = l_iter->next) != l_first);
-  return cross_poly_v2(uvs, f->len);
+  return cross_poly_v2(reinterpret_cast<const float(*)[2]>(uvs.data()), f->len);
 }
 
 void BM_face_uv_minmax(const BMFace *f, float min[2], float max[2], const int cd_loop_uv_offset)
@@ -107,7 +108,7 @@ void BM_face_uv_minmax(const BMFace *f, float min[2], float max[2], const int cd
   const BMLoop *l_first;
   l_iter = l_first = BM_FACE_FIRST_LOOP(f);
   do {
-    const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
+    const MLoopUV *luv = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
     minmax_v2v2_v2(min, max, luv->uv);
   } while ((l_iter = l_iter->next) != l_first);
 }
@@ -118,7 +119,7 @@ void BM_face_uv_transform(BMFace *f, const float matrix[2][2], const int cd_loop
   BMLoop *l_first;
   l_iter = l_first = BM_FACE_FIRST_LOOP(f);
   do {
-    MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
+    MLoopUV *luv = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset);
     mul_m2_v2(matrix, luv->uv);
   } while ((l_iter = l_iter->next) != l_first);
 }
@@ -126,12 +127,12 @@ void BM_face_uv_transform(BMFace *f, const float matrix[2][2], const int cd_loop
 bool BM_loop_uv_share_edge_check(BMLoop *l_a, BMLoop *l_b, const int cd_loop_uv_offset)
 {
   BLI_assert(l_a->e == l_b->e);
-  MLoopUV *luv_a_curr = BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset);
-  MLoopUV *luv_a_next = BM_ELEM_CD_GET_VOID_P(l_a->next, cd_loop_uv_offset);
-  MLoopUV *luv_b_curr = BM_ELEM_CD_GET_VOID_P(l_b, cd_loop_uv_offset);
-  MLoopUV *luv_b_next = BM_ELEM_CD_GET_VOID_P(l_b->next, cd_loop_uv_offset);
+  MLoopUV *luv_a_curr = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset);
+  MLoopUV *luv_a_next = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_a->next, cd_loop_uv_offset);
+  MLoopUV *luv_b_curr = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_b, cd_loop_uv_offset);
+  MLoopUV *luv_b_next = (MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_b->next, cd_loop_uv_offset);
   if (l_a->v != l_b->v) {
-    SWAP(MLoopUV *, luv_b_curr, luv_b_next);
+    std::swap(luv_b_curr, luv_b_next);
   }
   return (equals_v2v2(luv_a_curr->uv, luv_b_curr->uv) &&
           equals_v2v2(luv_a_next->uv, luv_b_next->uv));
@@ -140,8 +141,8 @@ bool BM_loop_uv_share_edge_check(BMLoop *l_a, BMLoop *l_b, const int cd_loop_uv_
 bool BM_loop_uv_share_vert_check(BMLoop *l_a, BMLoop *l_b, const int cd_loop_uv_offset)
 {
   BLI_assert(l_a->v == l_b->v);
-  const MLoopUV *luv_a = BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset);
-  const MLoopUV *luv_b = BM_ELEM_CD_GET_VOID_P(l_b, cd_loop_uv_offset);
+  const MLoopUV *luv_a = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_a, cd_loop_uv_offset);
+  const MLoopUV *luv_b = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_b, cd_loop_uv_offset);
   if (!equals_v2v2(luv_a->uv, luv_b->uv)) {
     return false;
   }
@@ -160,8 +161,10 @@ bool BM_edge_uv_share_vert_check(BMEdge *e, BMLoop *l_a, BMLoop *l_b, const int
   const BMLoop *l_other_b = BM_loop_other_vert_loop_by_edge(l_b, e);
 
   {
-    const MLoopUV *luv_other_a = BM_ELEM_CD_GET_VOID_P(l_other_a, cd_loop_uv_offset);
-    const MLoopUV *luv_other_b = BM_ELEM_CD_GET_VOID_P(l_other_b, cd_loop_uv_offset);
+    const MLoopUV *luv_other_a = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_other_a,
+                                                                        cd_loop_uv_offset);
+    const MLoopUV *luv_other_b = (const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_other_b,
+                                                                        cd_loop_uv_offset);
     if (!equals_v2v2(luv_other_a->uv, luv_other_b->uv)) {
       return false;
     }
@@ -172,7 +175,7 @@ bool BM_edge_uv_share_vert_check(BMEdge *e, BMLoop *l_a, BMLoop *l_b, const int
 
 bool BM_face_uv_point_inside_test(const BMFace *f, const float co[2], const int cd_loop_uv_offset)
 {
-  float(*projverts)[2] = BLI_array_alloca(projverts, f->len);
+  blender::Array<blender::float2, BM_DEFAULT_NGON_STACK_SIZE> projverts(f->len);
 
   BMLoop *l_iter;
   int i;
@@ -180,8 +183,9 @@ bool BM_face_uv_point_inside_test(const BMFace *f, const float co[2], const int
   BLI_assert(BM_face_is_normal_valid(f));
 
   for (i = 0, l_iter = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l_iter = l_iter->next) {
-    copy_v2_v2(projverts[i], BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset));
+    projverts[i] = ((const MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset))->uv;
   }
 
-  return isect_point_poly_v2(co, projverts, f->len, false);
+  return isect_point_poly_v2(
+      co, reinterpret_cast<const float(*)[2]>(projverts.data()), f->len, false);
 }



More information about the Bf-blender-cvs mailing list