[Bf-blender-cvs] [c7b247a118e] master: Cleanup: replace static_casts with functional casts for numeric types

Campbell Barton noreply at git.blender.org
Sun Sep 25 12:18:04 CEST 2022


Commit: c7b247a118e302a3afc6473797e53b6af28b69e2
Author: Campbell Barton
Date:   Sun Sep 25 18:30:50 2022 +1000
Branches: master
https://developer.blender.org/rBc7b247a118e302a3afc6473797e53b6af28b69e2

Cleanup: replace static_casts with functional casts for numeric types

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

M	source/blender/blendthumb/src/blendthumb_extract.cc
M	source/blender/blenkernel/intern/attribute.cc
M	source/blender/blenkernel/intern/curve_bezier.cc
M	source/blender/blenkernel/intern/customdata.cc
M	source/blender/blenkernel/intern/image.cc
M	source/blender/blenkernel/intern/mesh_boolean_convert.cc
M	source/blender/blenkernel/intern/mesh_calc_edges.cc
M	source/blender/blenkernel/intern/subdiv_mesh.cc
M	source/blender/blenkernel/intern/type_conversions.cc
M	source/blender/blenkernel/intern/volume_render.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/blenlib/intern/noise.cc
M	source/blender/blenlib/intern/rand.cc
M	source/blender/blenlib/intern/string_search.cc
M	source/blender/blenlib/intern/uuid.cc
M	source/blender/blenlib/tests/BLI_delaunay_2d_test.cc
M	source/blender/blenlib/tests/BLI_mesh_intersect_test.cc
M	source/blender/blenlib/tests/BLI_span_test.cc
M	source/blender/bmesh/intern/bmesh_mesh_convert.cc
M	source/blender/bmesh/tools/bmesh_boolean.cc
M	source/blender/compositor/intern/COM_FullFrameExecutionModel.cc
M	source/blender/compositor/operations/COM_ReadBufferOperation.cc
M	source/blender/compositor/operations/COM_SMAAOperation.cc
M	source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cc
M	source/blender/compositor/realtime_compositor/intern/context.cc
M	source/blender/depsgraph/intern/builder/deg_builder_cache.cc
M	source/blender/depsgraph/intern/node/deg_node_component.cc
M	source/blender/depsgraph/intern/node/deg_node_factory.cc
M	source/blender/depsgraph/intern/node/deg_node_id.cc
M	source/blender/draw/engines/overlay/overlay_edit_uv.cc
M	source/blender/draw/intern/draw_cache_extract_mesh.cc
M	source/blender/draw/intern/draw_cache_impl_subdivision.cc
M	source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines.cc
M	source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_attributes.cc
M	source/blender/editors/curves/intern/curves_ops.cc
M	source/blender/editors/geometry/geometry_attributes.cc
M	source/blender/editors/interface/interface_context_path.cc
M	source/blender/editors/interface/interface_region_tooltip.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
M	source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc
M	source/blender/geometry/intern/mesh_primitive_cuboid.cc
M	source/blender/geometry/intern/mesh_to_volume.cc
M	source/blender/gpu/opengl/gl_vertex_buffer.cc
M	source/blender/io/usd/intern/usd_capi_export.cc
M	source/blender/io/usd/intern/usd_capi_import.cc
M	source/blender/io/usd/intern/usd_reader_camera.cc
M	source/blender/io/usd/intern/usd_reader_mesh.cc
M	source/blender/io/usd/intern/usd_reader_nurbs.cc
M	source/blender/io/usd/intern/usd_reader_volume.cc
M	source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
M	source/blender/io/wavefront_obj/importer/obj_import_file_reader.cc
M	source/blender/modifiers/intern/MOD_volume_displace.cc
M	source/blender/nodes/composite/nodes/node_composite_blur.cc
M	source/blender/nodes/composite/nodes/node_composite_curves.cc
M	source/blender/nodes/composite/nodes/node_composite_dilate.cc
M	source/blender/nodes/composite/nodes/node_composite_scene_time.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc
M	source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc

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

diff --git a/source/blender/blendthumb/src/blendthumb_extract.cc b/source/blender/blendthumb/src/blendthumb_extract.cc
index fff1242f2ce..1429f26f82c 100644
--- a/source/blender/blendthumb/src/blendthumb_extract.cc
+++ b/source/blender/blendthumb/src/blendthumb_extract.cc
@@ -137,8 +137,7 @@ static eThumbStatus blendthumb_extract_from_file_impl(FileReader *file,
 
         /* Verify that image dimensions and data size make sense. */
         size_t data_size = block_size - sizeof(shape);
-        const uint64_t expected_size = static_cast<uint64_t>(thumb->width) *
-                                       static_cast<uint64_t>(thumb->height) * 4;
+        const uint64_t expected_size = uint64_t(thumb->width) * uint64_t(thumb->height) * 4;
         if (thumb->width < 0 || thumb->height < 0 || data_size != expected_size) {
           return BT_INVALID_THUMB;
         }
diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc
index bd3e452b7f2..c69a7b4b2c7 100644
--- a/source/blender/blenkernel/intern/attribute.cc
+++ b/source/blender/blenkernel/intern/attribute.cc
@@ -354,7 +354,7 @@ CustomDataLayer *BKE_id_attribute_search(ID *id,
   get_domains(id, info);
 
   for (eAttrDomain domain = ATTR_DOMAIN_POINT; domain < ATTR_DOMAIN_NUM;
-       domain = static_cast<eAttrDomain>((static_cast<int>(domain)) + 1)) {
+       domain = static_cast<eAttrDomain>((int(domain)) + 1)) {
     if (!(domain_mask & ATTR_DOMAIN_AS_MASK(domain))) {
       continue;
     }
diff --git a/source/blender/blenkernel/intern/curve_bezier.cc b/source/blender/blenkernel/intern/curve_bezier.cc
index 59b09384698..3aa87be3787 100644
--- a/source/blender/blenkernel/intern/curve_bezier.cc
+++ b/source/blender/blenkernel/intern/curve_bezier.cc
@@ -210,7 +210,7 @@ void evaluate_segment(const float3 &point_0,
                       MutableSpan<float3> result)
 {
   BLI_assert(result.size() > 0);
-  const float inv_len = 1.0f / static_cast<float>(result.size());
+  const float inv_len = 1.0f / float(result.size());
   const float inv_len_squared = inv_len * inv_len;
   const float inv_len_cubed = inv_len_squared * inv_len;
 
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 86be7ba8e7c..c07b4c7964e 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -520,7 +520,7 @@ static void layerInterp_propInt(const void **sources,
     const float src = *static_cast<const int *>(sources[i]);
     result += src * weight;
   }
-  const int rounded_result = static_cast<int>(round(result));
+  const int rounded_result = int(round(result));
   *static_cast<int *>(dest) = rounded_result;
 }
 
diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index 64f6ceba32b..b06317fa511 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -867,8 +867,8 @@ void BKE_image_get_tile_uv(const Image *ima, const int tile_number, float r_uv[2
   }
   else {
     const int tile_index = tile_number - 1001;
-    r_uv[0] = static_cast<float>(tile_index % 10);
-    r_uv[1] = static_cast<float>(tile_index / 10);
+    r_uv[0] = float(tile_index % 10);
+    r_uv[1] = float(tile_index / 10);
   }
 }
 
diff --git a/source/blender/blenkernel/intern/mesh_boolean_convert.cc b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
index be6c27ee6f9..360c7da2ae2 100644
--- a/source/blender/blenkernel/intern/mesh_boolean_convert.cc
+++ b/source/blender/blenkernel/intern/mesh_boolean_convert.cc
@@ -114,7 +114,7 @@ class MeshesToIMeshInfo {
  * input `Mesh` that contained the `MVert` that it came from. */
 int MeshesToIMeshInfo::input_mesh_for_imesh_vert(int imesh_v) const
 {
-  int n = static_cast<int>(mesh_vert_offset.size());
+  int n = int(mesh_vert_offset.size());
   for (int i = 0; i < n - 1; ++i) {
     if (imesh_v < mesh_vert_offset[i + 1]) {
       return i;
@@ -127,7 +127,7 @@ int MeshesToIMeshInfo::input_mesh_for_imesh_vert(int imesh_v) const
  * return the index of the input `Mesh` that contained the `MVert` that it came from. */
 int MeshesToIMeshInfo::input_mesh_for_imesh_edge(int imesh_e) const
 {
-  int n = static_cast<int>(mesh_edge_offset.size());
+  int n = int(mesh_edge_offset.size());
   for (int i = 0; i < n - 1; ++i) {
     if (imesh_e < mesh_edge_offset[i + 1]) {
       return i;
@@ -140,7 +140,7 @@ int MeshesToIMeshInfo::input_mesh_for_imesh_edge(int imesh_e) const
  * input `Mesh` that contained the `MPoly` that it came from. */
 int MeshesToIMeshInfo::input_mesh_for_imesh_face(int imesh_f) const
 {
-  int n = static_cast<int>(mesh_poly_offset.size());
+  int n = int(mesh_poly_offset.size());
   for (int i = 0; i < n - 1; ++i) {
     if (imesh_f < mesh_poly_offset[i + 1]) {
       return i;
@@ -831,7 +831,7 @@ Mesh *direct_mesh_boolean(Span<const Mesh *> meshes,
         return mi;
       }
     }
-    return static_cast<int>(mim.mesh_poly_offset.size()) - 1;
+    return int(mim.mesh_poly_offset.size()) - 1;
   };
   IMesh m_out = boolean_mesh(m_in,
                              static_cast<BoolOpType>(boolean_mode),
diff --git a/source/blender/blenkernel/intern/mesh_calc_edges.cc b/source/blender/blenkernel/intern/mesh_calc_edges.cc
index 038133c33ae..5e6babdf7b4 100644
--- a/source/blender/blenkernel/intern/mesh_calc_edges.cc
+++ b/source/blender/blenkernel/intern/mesh_calc_edges.cc
@@ -35,8 +35,7 @@ struct OrderedEdge {
     }
   }
 
-  OrderedEdge(const uint v1, const uint v2)
-      : OrderedEdge(static_cast<int>(v1), static_cast<int>(v2))
+  OrderedEdge(const uint v1, const uint v2) : OrderedEdge(int(v1), int(v2))
   {
   }
 
@@ -217,7 +216,7 @@ void BKE_mesh_calc_edges(Mesh *mesh, bool keep_existing_edges, const bool select
    * Each edge is assigned to one of the hash maps based on the lower bits of a hash value. */
   const int parallel_maps = get_parallel_maps_count(mesh);
   BLI_assert(is_power_of_2_i(parallel_maps));
-  const uint32_t parallel_mask = static_cast<uint32_t>(parallel_maps) - 1;
+  const uint32_t parallel_mask = uint32_t(parallel_maps) - 1;
   Array<EdgeMap> edge_maps(parallel_maps);
   reserve_hash_maps(mesh, keep_existing_edges, edge_maps);
 
diff --git a/source/blender/blenkernel/intern/subdiv_mesh.cc b/source/blender/blenkernel/intern/subdiv_mesh.cc
index 6bc188fd1fc..d716a7228c0 100644
--- a/source/blender/blenkernel/intern/subdiv_mesh.cc
+++ b/source/blender/blenkernel/intern/subdiv_mesh.cc
@@ -267,14 +267,13 @@ static void vertex_interpolation_from_corner(const SubdivMeshContext *ctx,
     const int first_loop_index = loops_of_ptex.first_loop - coarse_mloop;
     const int last_loop_index = loops_of_ptex.last_loop - coarse_mloop;
     const int first_indices[2] = {
-        static_cast<int>(coarse_mloop[first_loop_index].v),
-        static_cast<int>(
-            coarse_mloop[coarse_poly->loopstart +
+        int(coarse_mloop[first_loop_index].v),
+        int(coarse_mloop[coarse_poly->loopstart +
                          (first_loop_index - coarse_poly->loopstart + 1) % coarse_poly->totloop]
                 .v)};
     const int last_indices[2] = {
-        static_cast<int>(coarse_mloop[first_loop_index].v),
-        static_cast<int>(coarse_mloop[last_loop_index].v),
+        int(coarse_mloop[first_loop_index].v),
+        int(coarse_mloop[last_loop_index].v),
     };
     CustomData_interp(vertex_data,
                       &vertex_interpolation->vertex_data_storage,
@@ -402,8 +401,8 @@ static void loop_interpolation_from_corner(const SubdivMeshContext *ctx,
                                   (first_loop_index - base_loop_index + 1) % coarse_poly->totloop;
     const int first_indices[2] = {first_loop_index, second_loop_index};
     const int last_indices[2] = {
-        static_cast<int>(loops_of_ptex.last_loop - coarse_mloop),
-        static_cast<int>(loops_of_ptex.first_loop - coarse_mloop),
+        int(loops_of_ptex.last_loop - coarse_mloop),
+        int(loops_of_ptex.first_loop - coarse_mloop),
     };
     CustomData_interp(
         loop_data, &loop_interpolation->loop_data_storage, first_indices, weights, nullptr, 2, 1);
diff --git a/source/blender/blenkernel/intern/type_conversions.cc b/source/blender/blenkernel/intern/type_conversions.cc
index a01f5d19088..852fe38c92f 100644
--- a/source/blender/blenkernel/intern/type_conversions.cc
+++ b/source/blender/blenkernel/intern/type_conversions.cc
@@ -163,7 +163,7 @@ static bool int8_to_bool(const int8_t &a)
 }
 static int int8_to_int(const int8_t &a)
 {
-  return static_cast<int>(a);
+  return int(a);
 }
 static float int8_to_float(const int8_t &a)
 {
@@ -192,7 +192,7 @@ static float bool_to_float(const bool &a)
 }
 static int8_t bool_to_int8(const bool &a)
 {
-  return static_cast<int8_t>(a);
+  return int8_t(a);
 }
 static int32_t bool_to_int(const bool &a)
 {
diff --git a/source/blender/blenkernel/intern/volume_render.cc b/source/blender/blenkernel/intern/volume_render.cc
index e7620be6401..700bd63c9d4 100644
--- a/source/blender/blenkernel/intern/volume_render.cc
+++ b/source/blender/blenkernel/intern/volume_render.cc
@@ -102,9 +102,8 @@ bool BKE_volume_grid_dense_floats(const Volume *volume,
   }
 
   const openvdb::Vec3i resolution = bbox.dim().asVec3i();
-  const int64_t num_voxels = static_cast<int64_t>(resolution[0]) *
-                             static_cast<int64_t>(resolution[1]) *
-                             static_cast<int64_t>(resolution[2]);
+  const int64_t num_voxels = int64_t(resolution[0]) * int64_t(resolution[1]) *
+                             int64_t(resolution[2]);
   const int channels = BKE_volume_grid_channels(volume_grid);
   const int elem_size = sizeof(float) * channels;
   float *voxels = static_cast<float *>(MEM_malloc_arrayN(num_voxels, elem_size, __func__));
diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc
index db6cb0824dc..6280fe1010f 100644
--- a/source/blender/blenlib/intern/delaunay_2d.cc
+++ b/source/blender/blenlib/intern/delaunay_2d.cc
@@ -520,10 +520,10 @@ template<typename T> void cdt_draw(const std::string &label, const CDTArrangemen
   double heigh

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list