[Bf-blender-cvs] [55387197a7d] master: Cleanup: use function style casts for C++

Campbell Barton noreply at git.blender.org
Mon Oct 3 02:20:32 CEST 2022


Commit: 55387197a7da2a9c19e1f267f689d21793ef6162
Author: Campbell Barton
Date:   Mon Oct 3 10:24:06 2022 +1100
Branches: master
https://developer.blender.org/rB55387197a7da2a9c19e1f267f689d21793ef6162

Cleanup: use function style casts for C++

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

M	source/blender/blenkernel/intern/mball_tessellate.cc
M	source/blender/draw/intern/draw_manager_data.cc
M	source/blender/editors/mesh/editmesh_select.cc
M	source/blender/modifiers/intern/MOD_normal_edit.cc

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

diff --git a/source/blender/blenkernel/intern/mball_tessellate.cc b/source/blender/blenkernel/intern/mball_tessellate.cc
index 5df924c1bbf..8b602519374 100644
--- a/source/blender/blenkernel/intern/mball_tessellate.cc
+++ b/source/blender/blenkernel/intern/mball_tessellate.cc
@@ -281,7 +281,7 @@ static void build_bvh_spatial(
 
 #define HASHBIT (5)
 /** Hash table size (32768). */
-#define HASHSIZE (size_t)(1 << (3 * HASHBIT))
+#define HASHSIZE size_t(1 << (3 * HASHBIT))
 
 #define HASH(i, j, k) ((((((i)&31) << 5) | ((j)&31)) << 5) | ((k)&31))
 
@@ -677,11 +677,11 @@ static CORNER *setcorner(PROCESS *process, int i, int j, int k)
   c = static_cast<CORNER *>(BLI_memarena_alloc(process->pgn_elements, sizeof(CORNER)));
 
   c->i = i;
-  c->co[0] = ((float)i - 0.5f) * process->size;
+  c->co[0] = (float(i) - 0.5f) * process->size;
   c->j = j;
-  c->co[1] = ((float)j - 0.5f) * process->size;
+  c->co[1] = (float(j) - 0.5f) * process->size;
   c->k = k;
-  c->co[2] = ((float)k - 0.5f) * process->size;
+  c->co[2] = (float(k) - 0.5f) * process->size;
 
   c->value = metaball(process, c->co[0], c->co[1], c->co[2]);
 
@@ -985,7 +985,7 @@ static int vertid(PROCESS *process, const CORNER *c1, const CORNER *c2)
 #endif
 
   addtovertices(process, v, no); /* save vertex */
-  vid = (int)process->curvertex - 1;
+  vid = int(process->curvertex) - 1;
   setedge(process, c1->i, c1->j, c1->k, c2->i, c2->j, c2->k, vid);
 
   return vid;
@@ -1060,9 +1060,9 @@ static void add_cube(PROCESS *process, int i, int j, int k)
 
 static void next_lattice(int r[3], const float pos[3], const float size)
 {
-  r[0] = (int)ceil((pos[0] / size) + 0.5f);
-  r[1] = (int)ceil((pos[1] / size) + 0.5f);
-  r[2] = (int)ceil((pos[2] / size) + 0.5f);
+  r[0] = int(ceil((pos[0] / size) + 0.5f));
+  r[1] = int(ceil((pos[1] / size) + 0.5f));
+  r[2] = int(ceil((pos[2] / size) + 0.5f));
 }
 static void prev_lattice(int r[3], const float pos[3], const float size)
 {
@@ -1073,9 +1073,9 @@ static void prev_lattice(int r[3], const float pos[3], const float size)
 }
 static void closest_latice(int r[3], const float pos[3], const float size)
 {
-  r[0] = (int)floorf(pos[0] / size + 1.0f);
-  r[1] = (int)floorf(pos[1] / size + 1.0f);
-  r[2] = (int)floorf(pos[2] / size + 1.0f);
+  r[0] = int(floorf(pos[0] / size + 1.0f));
+  r[1] = int(floorf(pos[1] / size + 1.0f));
+  r[2] = int(floorf(pos[2] / size + 1.0f));
 }
 
 /**
@@ -1452,7 +1452,7 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
 
   Mesh *mesh = (Mesh *)BKE_id_new_nomain(ID_ME, ((ID *)ob->data)->name + 2);
 
-  mesh->totvert = (int)process.curvertex;
+  mesh->totvert = int(process.curvertex);
   MVert *mvert = static_cast<MVert *>(
       CustomData_add_layer(&mesh->vdata, CD_MVERT, CD_CONSTRUCT, NULL, mesh->totvert));
   for (int i = 0; i < mesh->totvert; i++) {
@@ -1460,7 +1460,7 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
   }
   MEM_freeN(process.co);
 
-  mesh->totpoly = (int)process.curindex;
+  mesh->totpoly = int(process.curindex);
   MPoly *mpoly = static_cast<MPoly *>(
       CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_CONSTRUCT, NULL, mesh->totpoly));
   MLoop *mloop = static_cast<MLoop *>(
@@ -1475,11 +1475,11 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
     mpoly[i].totloop = count;
     mpoly[i].flag = ME_SMOOTH;
 
-    mloop[loop_offset].v = (uint32_t)indices[0];
-    mloop[loop_offset + 1].v = (uint32_t)indices[1];
-    mloop[loop_offset + 2].v = (uint32_t)indices[2];
+    mloop[loop_offset].v = uint32_t(indices[0]);
+    mloop[loop_offset + 1].v = uint32_t(indices[1]);
+    mloop[loop_offset + 2].v = uint32_t(indices[2]);
     if (count == 4) {
-      mloop[loop_offset + 3].v = (uint32_t)indices[3];
+      mloop[loop_offset + 3].v = uint32_t(indices[3]);
     }
 
     loop_offset += count;
diff --git a/source/blender/draw/intern/draw_manager_data.cc b/source/blender/draw/intern/draw_manager_data.cc
index 0382ebbd396..f1cc9fb5927 100644
--- a/source/blender/draw/intern/draw_manager_data.cc
+++ b/source/blender/draw/intern/draw_manager_data.cc
@@ -70,7 +70,7 @@ static void draw_call_sort(DRWCommand *array, DRWCommand *array_tmp, int array_l
    * So at least sort fast! */
   uchar idx[128] = {0};
   /* Shift by 6 positions knowing each GPUBatch is > 64 bytes */
-#define KEY(a) ((((size_t)((a).draw.batch)) >> 6) % ARRAY_SIZE(idx))
+#define KEY(a) ((size_t((a).draw.batch) >> 6) % ARRAY_SIZE(idx))
   BLI_assert(array_len <= ARRAY_SIZE(idx));
 
   for (int i = 0; i < array_len; i++) {
@@ -699,7 +699,7 @@ static void drw_call_obinfos_init(DRWObjectInfos *ob_infos, Object *ob)
                      /* TODO(fclem): this is rather costly to do at runtime. Maybe we can
                       * put it in ob->runtime and make depsgraph ensure it is up to date. */
                      BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0);
-  ob_infos->ob_random = random * (1.0f / (float)0xFFFFFFFF);
+  ob_infos->ob_random = random * (1.0f / float(0xFFFFFFFF));
   /* Object State. */
   ob_infos->ob_flag = 1.0f; /* Required to have a correct sign */
   ob_infos->ob_flag += (ob->base_flag & BASE_SELECTED) ? (1 << 1) : 0;
@@ -819,7 +819,7 @@ static DRWResourceHandle drw_resource_handle(DRWShadingGroup *shgroup,
 
 static void command_type_set(uint64_t *command_type_bits, int index, eDRWCommandType type)
 {
-  command_type_bits[index / 16] |= ((uint64_t)type) << ((index % 16) * 4);
+  command_type_bits[index / 16] |= uint64_t(type) << ((index % 16) * 4);
 }
 
 eDRWCommandType command_type_get(const uint64_t *command_type_bits, int index)
diff --git a/source/blender/editors/mesh/editmesh_select.cc b/source/blender/editors/mesh/editmesh_select.cc
index d5392c7984d..7c72cb2cae2 100644
--- a/source/blender/editors/mesh/editmesh_select.cc
+++ b/source/blender/editors/mesh/editmesh_select.cc
@@ -1678,8 +1678,8 @@ static bool mouse_mesh_loop(
   float mvalf[2];
 
   em_setup_viewcontext(C, &vc);
-  mvalf[0] = (float)(vc.mval[0] = mval[0]);
-  mvalf[1] = (float)(vc.mval[1] = mval[1]);
+  mvalf[0] = float(vc.mval[0] = mval[0]);
+  mvalf[1] = float(vc.mval[1] = mval[1]);
 
   BMEditMesh *em_original = vc.em;
   const short selectmode = em_original->selectmode;
@@ -3702,8 +3702,8 @@ static int edbm_select_linked_pick_exec(bContext *C, wmOperator *op)
     const Scene *scene = CTX_data_scene(C);
     ViewLayer *view_layer = CTX_data_view_layer(C);
     /* Intentionally wrap negative values so the lookup fails. */
-    const uint object_index = (uint)RNA_int_get(op->ptr, "object_index");
-    const uint index = (uint)RNA_int_get(op->ptr, "index");
+    const uint object_index = uint(RNA_int_get(op->ptr, "object_index"));
+    const uint index = uint(RNA_int_get(op->ptr, "index"));
     ele = EDBM_elem_from_index_any_multi(scene, view_layer, object_index, index, &obedit);
   }
 
diff --git a/source/blender/modifiers/intern/MOD_normal_edit.cc b/source/blender/modifiers/intern/MOD_normal_edit.cc
index 91d8688ce2d..1ee4b559e68 100644
--- a/source/blender/modifiers/intern/MOD_normal_edit.cc
+++ b/source/blender/modifiers/intern/MOD_normal_edit.cc
@@ -134,7 +134,7 @@ static void mix_normals(const float mix_factor,
   int i;
 
   if (dvert) {
-    facs = static_cast<float *>(MEM_malloc_arrayN((size_t)loops_num, sizeof(*facs), __func__));
+    facs = static_cast<float *>(MEM_malloc_arrayN(size_t(loops_num), sizeof(*facs), __func__));
     BKE_defvert_extract_vgroup_to_loopweights(
         dvert, defgrp_index, verts_num, mloop, loops_num, use_invert_vgroup, facs);
   }
@@ -164,7 +164,7 @@ static void mix_normals(const float mix_factor,
         *no_new,
         *no_old,
         *no_new,
-        (mix_limit < (float)M_PI) ? min_ff(fac, mix_limit / angle_v3v3(*no_new, *no_old)) : fac);
+        (mix_limit < float(M_PI)) ? min_ff(fac, mix_limit / angle_v3v3(*no_new, *no_old)) : fac);
   }
 
   MEM_SAFE_FREE(facs);
@@ -236,12 +236,12 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd,
   int i;
 
   float(*cos)[3] = static_cast<float(*)[3]>(
-      MEM_malloc_arrayN((size_t)verts_num, sizeof(*cos), __func__));
+      MEM_malloc_arrayN(size_t(verts_num), sizeof(*cos), __func__));
   float(*nos)[3] = static_cast<float(*)[3]>(
-      MEM_malloc_arrayN((size_t)loops_num, sizeof(*nos), __func__));
+      MEM_malloc_arrayN(size_t(loops_num), sizeof(*nos), __func__));
   float size[3];
 
-  BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)verts_num, __func__);
+  BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(verts_num), __func__);
 
   generate_vert_coordinates(mesh, ob, ob_target, enmd->offset, verts_num, cos, size);
 
@@ -375,7 +375,7 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd,
   const bool use_parallel_normals = (enmd->flag & MOD_NORMALEDIT_USE_DIRECTION_PARALLEL) != 0;
 
   float(*nos)[3] = static_cast<float(*)[3]>(
-      MEM_malloc_arrayN((size_t)loops_num, sizeof(*nos), __func__));
+      MEM_malloc_arrayN(size_t(loops_num), sizeof(*nos), __func__));
 
   float target_co[3];
   int i;
@@ -399,10 +399,10 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd,
   }
   else {
     float(*cos)[3] = static_cast<float(*)[3]>(
-        MEM_malloc_arrayN((size_t)verts_num, sizeof(*cos), __func__));
+        MEM_malloc_arrayN(size_t(verts_num), sizeof(*cos), __func__));
     generate_vert_coordinates(mesh, ob, ob_target, nullptr, verts_num, cos, nullptr);
 
-    BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)verts_num, __func__);
+    BLI_bitmap *done_verts = BLI_BITMAP_NEW(size_t(verts_num), __func__);
     const MLoop *ml;
     float(*no)[3];
 
@@ -489,7 +489,7 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
   const bool use_invert_vgroup = ((enmd->flag & MOD_NORMALEDIT_INVERT_VGROUP) != 0);
   const bool use_current_clnors = !((enmd->mix_mode == MOD_NORMALEDIT_MIX_COPY) &&
                                     (enmd->mix_factor == 1.0f) && (enmd->defgrp_name[0] == '\0') &&
-                                    (enmd->mix_limit == (float)M_PI));
+                                    (enmd->mix_limit == float(M_PI)));
 
   /* Do not run that modifier at all if autosmooth

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list