[Bf-blender-cvs] [0aabaa4583b] master: Cleanup: Use signed integers in the weld modifier
Hans Goudey
noreply at git.blender.org
Fri Dec 17 16:40:19 CET 2021
Commit: 0aabaa4583b33786ccd597d0af98f9e3e3249ffd
Author: Hans Goudey
Date: Fri Dec 17 11:04:13 2021 -0300
Branches: master
https://developer.blender.org/rB0aabaa4583b33786ccd597d0af98f9e3e3249ffd
Cleanup: Use signed integers in the weld modifier
The style guide mentions that unsigned integers shouldn't be used to
show that a value won't be negative. Many places don't follow this
properly yet. The modifier used to cast an array of `uint` to `int` in
order to pass it to `BLI_kdtree_3d_calc_duplicates_fast`. That is no
longer necessary.
Differential Revision: https://developer.blender.org/D13613
===================================================================
M source/blender/modifiers/intern/MOD_weld.c
===================================================================
diff --git a/source/blender/modifiers/intern/MOD_weld.c b/source/blender/modifiers/intern/MOD_weld.c
index f842bef3298..aa19e84b909 100644
--- a/source/blender/modifiers/intern/MOD_weld.c
+++ b/source/blender/modifiers/intern/MOD_weld.c
@@ -70,68 +70,68 @@
#include "MOD_ui_common.h"
/* Indicates when the element was not computed. */
-#define OUT_OF_CONTEXT (uint)(-1)
+#define OUT_OF_CONTEXT (int)(-1)
/* Indicates if the edge or face will be collapsed. */
-#define ELEM_COLLAPSED (uint)(-2)
+#define ELEM_COLLAPSED (int)(-2)
/* indicates whether an edge or vertex in groups_map will be merged. */
-#define ELEM_MERGED (uint)(-2)
+#define ELEM_MERGED (int)(-2)
/* Used to indicate a range in an array specifying a group. */
struct WeldGroup {
- uint len;
- uint ofs;
+ int len;
+ int ofs;
};
/* Edge groups that will be merged. Final vertices are also indicated. */
struct WeldGroupEdge {
struct WeldGroup group;
- uint v1;
- uint v2;
+ int v1;
+ int v2;
};
typedef struct WeldVert {
/* Indexes relative to the original Mesh. */
- uint vert_dest;
- uint vert_orig;
+ int vert_dest;
+ int vert_orig;
} WeldVert;
typedef struct WeldEdge {
union {
- uint flag;
+ int flag;
struct {
/* Indexes relative to the original Mesh. */
- uint edge_dest;
- uint edge_orig;
- uint vert_a;
- uint vert_b;
+ int edge_dest;
+ int edge_orig;
+ int vert_a;
+ int vert_b;
};
};
} WeldEdge;
typedef struct WeldLoop {
union {
- uint flag;
+ int flag;
struct {
/* Indexes relative to the original Mesh. */
- uint vert;
- uint edge;
- uint loop_orig;
- uint loop_skip_to;
+ int vert;
+ int edge;
+ int loop_orig;
+ int loop_skip_to;
};
};
} WeldLoop;
typedef struct WeldPoly {
union {
- uint flag;
+ int flag;
struct {
/* Indexes relative to the original Mesh. */
- uint poly_dst;
- uint poly_orig;
- uint loop_start;
- uint loop_end;
+ int poly_dst;
+ int poly_orig;
+ int loop_start;
+ int loop_end;
/* Final Polygon Size. */
- uint len;
+ int len;
/* Group of loops that will be affected. */
struct WeldGroup loops;
};
@@ -141,53 +141,53 @@ typedef struct WeldPoly {
typedef struct WeldMesh {
/* Group of vertices to be merged. */
struct WeldGroup *vert_groups;
- uint *vert_groups_buffer;
+ int *vert_groups_buffer;
/* Group of edges to be merged. */
struct WeldGroupEdge *edge_groups;
- uint *edge_groups_buffer;
+ int *edge_groups_buffer;
/* From the original index of the vertex, this indicates which group it is or is going to be
* merged. */
- uint *edge_groups_map;
+ int *edge_groups_map;
/* References all polygons and loops that will be affected. */
WeldLoop *wloop;
WeldPoly *wpoly;
WeldPoly *wpoly_new;
- uint wloop_len;
- uint wpoly_len;
- uint wpoly_new_len;
+ int wloop_len;
+ int wpoly_len;
+ int wpoly_new_len;
/* From the actual index of the element in the mesh, it indicates what is the index of the Weld
* element above. */
- uint *loop_map;
- uint *poly_map;
+ int *loop_map;
+ int *poly_map;
- uint vert_kill_len;
- uint edge_kill_len;
- uint loop_kill_len;
- uint poly_kill_len; /* Including the new polygons. */
+ int vert_kill_len;
+ int edge_kill_len;
+ int loop_kill_len;
+ int poly_kill_len; /* Including the new polygons. */
/* Size of the affected polygon with more sides. */
- uint max_poly_len;
+ int max_poly_len;
} WeldMesh;
typedef struct WeldLoopOfPolyIter {
- uint loop_start;
- uint loop_end;
+ int loop_start;
+ int loop_end;
const WeldLoop *wloop;
const MLoop *mloop;
- const uint *loop_map;
+ const int *loop_map;
/* Weld group. */
- uint *group;
+ int *group;
- uint l_curr;
- uint l_next;
+ int l_curr;
+ int l_next;
/* Return */
- uint group_len;
- uint v;
- uint e;
+ int group_len;
+ int v;
+ int e;
char type;
} WeldLoopOfPolyIter;
@@ -200,19 +200,19 @@ static bool weld_iter_loop_of_poly_begin(WeldLoopOfPolyIter *iter,
const WeldPoly *wp,
const WeldLoop *wloop,
const MLoop *mloop,
- const uint *loop_map,
- uint *group_buffer);
+ const int *loop_map,
+ int *group_buffer);
static bool weld_iter_loop_of_poly_next(WeldLoopOfPolyIter *iter);
static void weld_assert_edge_kill_len(const WeldEdge *wedge,
- const uint wedge_len,
- const uint supposed_kill_len)
+ const int wedge_len,
+ const int supposed_kill_len)
{
- uint kills = 0;
+ int kills = 0;
const WeldEdge *we = &wedge[0];
- for (uint i = wedge_len; i--; we++) {
- uint edge_dest = we->edge_dest;
+ for (int i = wedge_len; i--; we++) {
+ int edge_dest = we->edge_dest;
/* Magically includes collapsed edges. */
if (edge_dest != OUT_OF_CONTEXT) {
kills++;
@@ -223,22 +223,22 @@ static void weld_assert_edge_kill_len(const WeldEdge *wedge,
static void weld_assert_poly_and_loop_kill_len(const WeldPoly *wpoly,
const WeldPoly *wpoly_new,
- const uint wpoly_new_len,
+ const int wpoly_new_len,
const WeldLoop *wloop,
const MLoop *mloop,
- const uint *loop_map,
- const uint *poly_map,
+ const int *loop_map,
+ const int *poly_map,
const MPoly *mpoly,
- const uint mpoly_len,
- const uint mloop_len,
- const uint supposed_poly_kill_len,
- const uint supposed_loop_kill_len)
+ const int mpoly_len,
+ const int mloop_len,
+ const int supposed_poly_kill_len,
+ const int supposed_loop_kill_len)
{
- uint poly_kills = 0;
- uint loop_kills = mloop_len;
+ int poly_kills = 0;
+ int loop_kills = mloop_len;
const MPoly *mp = &mpoly[0];
- for (uint i = 0; i < mpoly_len; i++, mp++) {
- uint poly_ctx = poly_map[i];
+ for (int i = 0; i < mpoly_len; i++, mp++) {
+ int poly_ctx = poly_map[i];
if (poly_ctx != OUT_OF_CONTEXT) {
const WeldPoly *wp = &wpoly[poly_ctx];
WeldLoopOfPolyIter iter;
@@ -251,11 +251,11 @@ static void weld_assert_poly_and_loop_kill_len(const WeldPoly *wpoly,
poly_kills++;
continue;
}
- uint remain = wp->len;
- uint l = wp->loop_start;
+ int remain = wp->len;
+ int l = wp->loop_start;
while (remain) {
- uint l_next = l + 1;
- uint loop_ctx = loop_map[l];
+ int l_next = l + 1;
+ int loop_ctx = loop_map[l];
if (loop_ctx != OUT_OF_CONTEXT) {
const WeldLoop *wl = &wloop[loop_ctx];
if (wl->loop_skip_to != OUT_OF_CONTEXT) {
@@ -280,16 +280,16 @@ static void weld_assert_poly_and_loop_kill_len(const WeldPoly *wpoly,
}
const WeldPoly *wp = &wpoly_new[0];
- for (uint i = wpoly_new_len; i--; wp++) {
+ for (int i = wpoly_new_len; i--; wp++) {
if (wp->poly_dst != OUT_OF_CONTEXT) {
poly_kills++;
continue;
}
- uint remain = wp->len;
- uint l = wp->loop_start;
+ int remain = wp->len;
+ int l = wp->loop_start;
while (remain) {
- uint l_next = l + 1;
- uint loop_ctx = loop_map[l];
+ int l_next = l + 1;
+ int loop_ctx = loop_map[l];
if (loop_ctx != OUT_OF_CONTEXT) {
const WeldLoop *wl = &wloop[loop_ctx];
if (wl->loop_skip_to != OUT_OF_CONTEXT) {
@@ -315,24 +315,24 @@ static void weld_assert_poly_and_loop_kill_len(const WeldPoly *wpoly,
static void weld_assert_poly_no_vert_repetition(const WeldPoly *wp,
const WeldLoop *wloop,
const MLoop *mloop,
- const uint *loop_map)
+ const int *loop_map)
{
- const uint len = wp->len;
- uint *verts = BLI_array_alloca(verts, len);
+ const int len = wp->len;
+ int *verts = BLI_array_alloca(verts, len);
WeldLoopOfPolyIter iter;
if (!weld_iter_loop_of_poly_begin(&iter, wp, wloop, mloop, loop_map, NULL)) {
return;
}
else {
- uint i = 0;
+ int i = 0;
while (weld_iter_loop_of_poly_next(&iter)) {
verts[i++] = iter.v;
}
}
- for (uint i = 0; i < len; i++) {
- uint va = verts[i];
- for (uint j = i + 1; j < len; j++) {
- uint vb = verts[j];
+ for (int i = 0; i < len; i++) {
+ int va = verts[i];
+ for (int j = i + 1; j < len; j++) {
+ int vb = verts[j];
BLI_assert(va != vb);
}
}
@@ -344,14 +344,14 @@ static void weld_assert_poly_len(const WeldPoly *wp, const WeldLoop *wloop)
return;
}
- uint len = wp->len;
+ int len = wp->len;
const WeldLoop *wl = &wloop[wp->loops.ofs];
BLI_assert(wp->loop_start <= wl->loop_orig);
- uint end_wloop = wp->loops.ofs + wp->loops.len;
+ int end_wloop = wp->loops.ofs + wp->loops.len;
const WeldLoop *wl_end = &wloop[end_wloop - 1];
- uint min_len = 0;
+ int min_len = 0;
for (; wl <= wl_end; wl++) {
BLI_assert(wl->loop_skip_to == OUT_OF_CONTEXT); /* Not for this
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list