From c7b247a118e302a3afc6473797e53b6af28b69e2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 25 Sep 2022 18:30:50 +1000 Subject: Cleanup: replace static_casts with functional casts for numeric types --- .../nodes/node_geo_mesh_primitive_circle.cc | 2 +- .../geometry/nodes/node_geo_mesh_primitive_cone.cc | 29 ++++++++++------------ .../nodes/node_geo_mesh_primitive_uv_sphere.cc | 8 +++--- .../nodes/geometry/nodes/node_geo_volume_cube.cc | 3 +-- 4 files changed, 19 insertions(+), 23 deletions(-) (limited to 'source/blender/nodes/geometry') diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc index 801b3c78060..c69ea8635ca 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_circle.cc @@ -115,7 +115,7 @@ static Mesh *create_circle_mesh(const float radius, MutableSpan loops = mesh->loops_for_write(); /* Assign vertex coordinates. */ - const float angle_delta = 2.0f * (M_PI / static_cast(verts_num)); + const float angle_delta = 2.0f * (M_PI / float(verts_num)); for (const int i : IndexRange(verts_num)) { const float angle = i * angle_delta; copy_v3_v3(verts[i].co, float3(std::cos(angle) * radius, std::sin(angle) * radius, 0.0f)); diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc index 1f9ad9f6ea2..9f01989fc02 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc @@ -258,7 +258,7 @@ int ConeConfig::calculate_total_corners() static void calculate_cone_verts(const MutableSpan &verts, const ConeConfig &config) { Array circle(config.circle_segments); - const float angle_delta = 2.0f * (M_PI / static_cast(config.circle_segments)); + const float angle_delta = 2.0f * (M_PI / float(config.circle_segments)); float angle = 0.0f; for (const int i : IndexRange(config.circle_segments)) { circle[i].x = std::cos(angle); @@ -275,8 +275,7 @@ static void calculate_cone_verts(const MutableSpan &verts, const ConeConf /* Top fill including the outer edge of the fill. */ if (!config.top_is_point) { - const float top_fill_radius_delta = config.radius_top / - static_cast(config.fill_segments); + const float top_fill_radius_delta = config.radius_top / float(config.fill_segments); for (const int i : IndexRange(config.fill_segments)) { const float top_fill_radius = top_fill_radius_delta * (i + 1); for (const int j : IndexRange(config.circle_segments)) { @@ -289,8 +288,8 @@ static void calculate_cone_verts(const MutableSpan &verts, const ConeConf /* Rings along the side. */ const float side_radius_delta = (config.radius_bottom - config.radius_top) / - static_cast(config.side_segments); - const float height_delta = 2.0f * config.height / static_cast(config.side_segments); + float(config.side_segments); + const float height_delta = 2.0f * config.height / float(config.side_segments); for (const int i : IndexRange(config.side_segments - 1)) { const float ring_radius = config.radius_top + (side_radius_delta * (i + 1)); const float ring_height = config.height - (height_delta * (i + 1)); @@ -303,8 +302,7 @@ static void calculate_cone_verts(const MutableSpan &verts, const ConeConf /* Bottom fill including the outer edge of the fill. */ if (!config.bottom_is_point) { - const float bottom_fill_radius_delta = config.radius_bottom / - static_cast(config.fill_segments); + const float bottom_fill_radius_delta = config.radius_bottom / float(config.fill_segments); for (const int i : IndexRange(config.fill_segments)) { const float bottom_fill_radius = config.radius_bottom - (i * bottom_fill_radius_delta); for (const int j : IndexRange(config.circle_segments)) { @@ -544,7 +542,7 @@ static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config) Array circle(config.circle_segments); float angle = 0.0f; - const float angle_delta = 2.0f * M_PI / static_cast(config.circle_segments); + const float angle_delta = 2.0f * M_PI / float(config.circle_segments); for (const int i : IndexRange(config.circle_segments)) { circle[i].x = std::cos(angle) * 0.225f; circle[i].y = std::sin(angle) * 0.225f; @@ -556,9 +554,8 @@ static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config) /* Left circle of the UV representing the top fill or top cone tip. */ if (config.top_is_point || config.fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE) { const float2 center_left(0.25f, 0.25f); - const float radius_factor_delta = 1.0f / (config.top_is_point ? - static_cast(config.side_segments) : - static_cast(config.fill_segments)); + const float radius_factor_delta = 1.0f / (config.top_is_point ? float(config.side_segments) : + float(config.fill_segments)); const int left_circle_segment_count = config.top_is_point ? config.side_segments : config.fill_segments; @@ -595,8 +592,8 @@ static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config) if (!config.top_is_point && !config.bottom_is_point) { /* Mesh is a truncated cone or cylinder. The sides are unwrapped into a rectangle. */ const float bottom = (config.fill_type == GEO_NODE_MESH_CIRCLE_FILL_NONE) ? 0.0f : 0.5f; - const float x_delta = 1.0f / static_cast(config.circle_segments); - const float y_delta = (1.0f - bottom) / static_cast(config.side_segments); + const float x_delta = 1.0f / float(config.circle_segments); + const float y_delta = (1.0f - bottom) / float(config.side_segments); for (const int i : IndexRange(config.side_segments)) { for (const int j : IndexRange(config.circle_segments)) { @@ -612,8 +609,8 @@ static void calculate_cone_uvs(Mesh *mesh, const ConeConfig &config) if (config.bottom_is_point || config.fill_type != GEO_NODE_MESH_CIRCLE_FILL_NONE) { const float2 center_right(0.75f, 0.25f); const float radius_factor_delta = 1.0f / (config.bottom_is_point ? - static_cast(config.side_segments) : - static_cast(config.fill_segments)); + float(config.side_segments) : + float(config.fill_segments)); const int right_circle_segment_count = config.bottom_is_point ? config.side_segments : config.fill_segments; @@ -679,7 +676,7 @@ Mesh *create_cylinder_or_cone_mesh(const float radius_top, if (config.height == 0.0f) { return create_vertex_mesh(); } - const float z_delta = -2.0f * config.height / static_cast(config.side_segments); + const float z_delta = -2.0f * config.height / float(config.side_segments); const float3 start(0.0f, 0.0f, config.height); const float3 delta(0.0f, 0.0f, z_delta); return create_line_mesh(start, delta, config.tot_verts); diff --git a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc index d39e72b7f0a..1c8e7eec6c0 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc @@ -266,16 +266,16 @@ BLI_NOINLINE static void calculate_sphere_uvs(Mesh *mesh, const float segments, const float segments_inv = 1.0f / segments; for (const int i_segment : IndexRange(segments)) { - const float segment = static_cast(i_segment); + const float segment = float(i_segment); uvs[loop_index++] = float2((segment + 0.5f) * segments_inv, 0.0f); uvs[loop_index++] = float2(segment * segments_inv, dy); uvs[loop_index++] = float2((segment + 1.0f) * segments_inv, dy); } for (const int i_ring : IndexRange(1, rings - 2)) { - const float ring = static_cast(i_ring); + const float ring = float(i_ring); for (const int i_segment : IndexRange(segments)) { - const float segment = static_cast(i_segment); + const float segment = float(i_segment); uvs[loop_index++] = float2(segment * segments_inv, ring / rings); uvs[loop_index++] = float2(segment * segments_inv, (ring + 1.0f) / rings); uvs[loop_index++] = float2((segment + 1.0f) * segments_inv, (ring + 1.0f) / rings); @@ -284,7 +284,7 @@ BLI_NOINLINE static void calculate_sphere_uvs(Mesh *mesh, const float segments, } for (const int i_segment : IndexRange(segments)) { - const float segment = static_cast(i_segment); + const float segment = float(i_segment); uvs[loop_index++] = float2((segment + 0.5f) * segments_inv, 1.0f); uvs[loop_index++] = float2((segment + 1.0f) * segments_inv, 1.0f - dy); uvs[loop_index++] = float2(segment * segments_inv, 1.0f - dy); diff --git a/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc b/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc index c102b91acb1..274c243909d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc @@ -75,8 +75,7 @@ class Grid3DFieldContext : public FieldContext { int64_t points_num() const { - return static_cast(resolution_.x) * static_cast(resolution_.y) * - static_cast(resolution_.z); + return int64_t(resolution_.x) * int64_t(resolution_.y) * int64_t(resolution_.z); } GVArray get_varray_for_input(const FieldInput &field_input, -- cgit v1.2.3