Cleanup: replace C-style casts with functional casts for numeric types
This commit is contained in:
@@ -43,13 +43,13 @@ static const fn::MultiFunction *get_multi_function(const bNode &bnode)
|
||||
{
|
||||
static auto exec_preset = fn::CustomMF_presets::AllSpanOrSingle();
|
||||
static fn::CustomMF_SI_SO<float, int> round_fn{
|
||||
"Round", [](float a) { return (int)round(a); }, exec_preset};
|
||||
"Round", [](float a) { return int(round(a)); }, exec_preset};
|
||||
static fn::CustomMF_SI_SO<float, int> floor_fn{
|
||||
"Floor", [](float a) { return (int)floor(a); }, exec_preset};
|
||||
"Floor", [](float a) { return int(floor(a)); }, exec_preset};
|
||||
static fn::CustomMF_SI_SO<float, int> ceil_fn{
|
||||
"Ceiling", [](float a) { return (int)ceil(a); }, exec_preset};
|
||||
"Ceiling", [](float a) { return int(ceil(a)); }, exec_preset};
|
||||
static fn::CustomMF_SI_SO<float, int> trunc_fn{
|
||||
"Truncate", [](float a) { return (int)trunc(a); }, exec_preset};
|
||||
"Truncate", [](float a) { return int(trunc(a)); }, exec_preset};
|
||||
|
||||
switch (static_cast<FloatToIntRoundingMode>(bnode.custom1)) {
|
||||
case FN_NODE_FLOAT_TO_INT_ROUND:
|
||||
|
||||
@@ -56,7 +56,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
|
||||
# if 0 /* Disabled because it only works for meshes, not predictable enough. */
|
||||
/* Copy custom data on vertices, like vertex groups etc. */
|
||||
if (mesh && original_index < mesh->totvert) {
|
||||
CustomData_copy_data(&mesh->vdata, &result->vdata, (int)original_index, (int)i, 1);
|
||||
CustomData_copy_data(&mesh->vdata, &result->vdata, int(original_index), int(i), 1);
|
||||
}
|
||||
# endif
|
||||
/* Copy the position of the original point. */
|
||||
@@ -81,7 +81,7 @@ static Mesh *hull_from_bullet(const Mesh *mesh, Span<float3> coords)
|
||||
int v_to;
|
||||
plConvexHullGetLoop(hull, i, &v_from, &v_to);
|
||||
|
||||
mloop_src[i].v = (uint)v_from;
|
||||
mloop_src[i].v = uint(v_from);
|
||||
/* Add edges for ascending order loops only. */
|
||||
if (v_from < v_to) {
|
||||
MEdge &edge = edges[edge_index];
|
||||
|
||||
@@ -85,7 +85,7 @@ static Mesh *cdt_to_mesh(const meshintersect::CDT_result<double> &result)
|
||||
MutableSpan<MLoop> loops = mesh->loops_for_write();
|
||||
|
||||
for (const int i : IndexRange(result.vert.size())) {
|
||||
copy_v3_v3(verts[i].co, float3((float)result.vert[i].x, (float)result.vert[i].y, 0.0f));
|
||||
copy_v3_v3(verts[i].co, float3(float(result.vert[i].x), float(result.vert[i].y), 0.0f));
|
||||
}
|
||||
for (const int i : IndexRange(result.edge.size())) {
|
||||
edges[i].v1 = result.edge[i].first;
|
||||
|
||||
@@ -97,7 +97,7 @@ class HandleTypeFieldInput final : public bke::CurvesFieldInput {
|
||||
|
||||
uint64_t hash() const override
|
||||
{
|
||||
return get_default_hash_2((int)mode_, (int)type_);
|
||||
return get_default_hash_2(int(mode_), int(type_));
|
||||
}
|
||||
|
||||
bool is_equal_to(const fn::FieldNode &other) const override
|
||||
|
||||
@@ -144,7 +144,7 @@ static Curves *create_point_circle_curve(
|
||||
|
||||
/* Get the radius from the center-point to p1. */
|
||||
const float r = math::distance(p1, center);
|
||||
const float theta_step = ((2 * M_PI) / (float)resolution);
|
||||
const float theta_step = ((2 * M_PI) / float(resolution));
|
||||
for (const int i : IndexRange(resolution)) {
|
||||
|
||||
/* Formula for a circle around a point and 2 unit vectors perpendicular
|
||||
|
||||
@@ -43,9 +43,9 @@ static Curves *create_spiral_curve(const float rotations,
|
||||
const bool direction)
|
||||
{
|
||||
const int totalpoints = std::max(int(resolution * rotations), 1);
|
||||
const float delta_radius = (end_radius - start_radius) / (float)totalpoints;
|
||||
const float delta_height = height / (float)totalpoints;
|
||||
const float delta_theta = (M_PI * 2 * rotations) / (float)totalpoints *
|
||||
const float delta_radius = (end_radius - start_radius) / float(totalpoints);
|
||||
const float delta_height = height / float(totalpoints);
|
||||
const float delta_theta = (M_PI * 2 * rotations) / float(totalpoints) *
|
||||
(direction ? 1.0f : -1.0f);
|
||||
|
||||
Curves *curves_id = bke::curves_new_nomain_single(totalpoints + 1, CURVE_TYPE_POLY);
|
||||
|
||||
@@ -99,7 +99,7 @@ class PositionsVDBWrapper {
|
||||
|
||||
void add(const openvdb::Vec3R &pos)
|
||||
{
|
||||
vector_.append(float3((float)pos[0], (float)pos[1], (float)pos[2]) + offset_fix_);
|
||||
vector_.append(float3(float(pos[0]), float(pos[1]), float(pos[2])) + offset_fix_);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -117,9 +117,9 @@ static void point_scatter_density_random(const openvdb::FloatGrid &grid,
|
||||
Vector<float3> &r_positions)
|
||||
{
|
||||
/* Offset points by half a voxel so that grid points are aligned with world grid points. */
|
||||
const float3 offset_fix = {0.5f * (float)grid.voxelSize().x(),
|
||||
0.5f * (float)grid.voxelSize().y(),
|
||||
0.5f * (float)grid.voxelSize().z()};
|
||||
const float3 offset_fix = {0.5f * float(grid.voxelSize().x()),
|
||||
0.5f * float(grid.voxelSize().y()),
|
||||
0.5f * float(grid.voxelSize().z())};
|
||||
/* Setup and call into OpenVDB's point scatter API. */
|
||||
PositionsVDBWrapper vdb_position_wrapper = PositionsVDBWrapper(r_positions, offset_fix);
|
||||
RNGType random_generator(seed);
|
||||
@@ -133,9 +133,9 @@ static void point_scatter_density_grid(const openvdb::FloatGrid &grid,
|
||||
Vector<float3> &r_positions)
|
||||
{
|
||||
const openvdb::Vec3d half_voxel(0.5, 0.5, 0.5);
|
||||
const openvdb::Vec3d voxel_spacing((double)spacing.x / grid.voxelSize().x(),
|
||||
(double)spacing.y / grid.voxelSize().y(),
|
||||
(double)spacing.z / grid.voxelSize().z());
|
||||
const openvdb::Vec3d voxel_spacing(double(spacing.x) / grid.voxelSize().x(),
|
||||
double(spacing.y) / grid.voxelSize().y(),
|
||||
double(spacing.z) / grid.voxelSize().z());
|
||||
|
||||
/* Abort if spacing is zero. */
|
||||
const double min_spacing = std::min(voxel_spacing.x(),
|
||||
@@ -170,7 +170,7 @@ static void point_scatter_density_grid(const openvdb::FloatGrid &grid,
|
||||
/* Transform with grid matrix and add point. */
|
||||
const openvdb::Vec3d idx_pos(x, y, z);
|
||||
const openvdb::Vec3d local_pos = grid.indexToWorld(idx_pos + half_voxel);
|
||||
r_positions.append({(float)local_pos.x(), (float)local_pos.y(), (float)local_pos.z()});
|
||||
r_positions.append({float(local_pos.x()), float(local_pos.y()), float(local_pos.z())});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,9 +122,9 @@ class ImageFieldsFunction : public fn::MultiFunction {
|
||||
|
||||
static float frac(const float x, int *ix)
|
||||
{
|
||||
const int i = (int)x - ((x < 0.0f) ? 1 : 0);
|
||||
const int i = int(x) - ((x < 0.0f) ? 1 : 0);
|
||||
*ix = i;
|
||||
return x - (float)i;
|
||||
return x - float(i);
|
||||
}
|
||||
|
||||
static float4 image_cubic_texture_lookup(const ImBuf *ibuf,
|
||||
@@ -135,8 +135,8 @@ class ImageFieldsFunction : public fn::MultiFunction {
|
||||
const int width = ibuf->x;
|
||||
const int height = ibuf->y;
|
||||
int pix, piy, nix, niy;
|
||||
const float tx = frac(px * (float)width - 0.5f, &pix);
|
||||
const float ty = frac(py * (float)height - 0.5f, &piy);
|
||||
const float tx = frac(px * float(width) - 0.5f, &pix);
|
||||
const float ty = frac(py * float(height) - 0.5f, &piy);
|
||||
int ppix, ppiy, nnix, nniy;
|
||||
|
||||
switch (extension) {
|
||||
@@ -215,8 +215,8 @@ class ImageFieldsFunction : public fn::MultiFunction {
|
||||
const int width = ibuf->x;
|
||||
const int height = ibuf->y;
|
||||
int pix, piy, nix, niy;
|
||||
const float nfx = frac(px * (float)width - 0.5f, &pix);
|
||||
const float nfy = frac(py * (float)height - 0.5f, &piy);
|
||||
const float nfx = frac(px * float(width) - 0.5f, &pix);
|
||||
const float nfy = frac(py * float(height) - 0.5f, &piy);
|
||||
|
||||
switch (extension) {
|
||||
case SHD_IMAGE_EXTENSION_CLIP: {
|
||||
@@ -257,8 +257,8 @@ class ImageFieldsFunction : public fn::MultiFunction {
|
||||
const int width = ibuf->x;
|
||||
const int height = ibuf->y;
|
||||
int ix, iy;
|
||||
const float tx = frac(px * (float)width, &ix);
|
||||
const float ty = frac(py * (float)height, &iy);
|
||||
const float tx = frac(px * float(width), &ix);
|
||||
const float ty = frac(py * float(height), &iy);
|
||||
|
||||
switch (extension) {
|
||||
case SHD_IMAGE_EXTENSION_REPEAT: {
|
||||
|
||||
@@ -18,7 +18,7 @@ static void node_exec(GeoNodeExecParams params)
|
||||
{
|
||||
const Scene *scene = DEG_get_input_scene(params.depsgraph());
|
||||
const float scene_ctime = BKE_scene_ctime_get(scene);
|
||||
const double frame_rate = (((double)scene->r.frs_sec) / (double)scene->r.frs_sec_base);
|
||||
const double frame_rate = (double(scene->r.frs_sec) / double(scene->r.frs_sec_base));
|
||||
params.set_output("Seconds", float(scene_ctime / frame_rate));
|
||||
params.set_output("Frame", scene_ctime);
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ static void node_geo_exec(GeoNodeExecParams params)
|
||||
mesh = create_line_mesh(start, float3(0), count);
|
||||
}
|
||||
else {
|
||||
const float3 delta = total_delta / (float)(count - 1);
|
||||
const float3 delta = total_delta / float(count - 1);
|
||||
mesh = create_line_mesh(start, delta, count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ struct ParticleList {
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return (size_t)positions.size();
|
||||
return size_t(positions.size());
|
||||
}
|
||||
|
||||
void getPos(size_t n, openvdb::Vec3R &xyz) const
|
||||
|
||||
@@ -35,8 +35,8 @@ FieldInfoLog::FieldInfoLog(const GField &field) : type(field.cpp_type())
|
||||
|
||||
std::sort(
|
||||
field_inputs.begin(), field_inputs.end(), [](const FieldInput &a, const FieldInput &b) {
|
||||
const int index_a = (int)a.category();
|
||||
const int index_b = (int)b.category();
|
||||
const int index_a = int(a.category());
|
||||
const int index_b = int(b.category());
|
||||
if (index_a == index_b) {
|
||||
return a.socket_inspection_name().size() < b.socket_inspection_name().size();
|
||||
}
|
||||
|
||||
@@ -59,14 +59,14 @@ struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree,
|
||||
}
|
||||
case SOCK_INT: {
|
||||
bNodeSocketValueInt *dval = (bNodeSocketValueInt *)sock->default_value;
|
||||
dval->value = (int)stemp->val1;
|
||||
dval->min = (int)stemp->min;
|
||||
dval->max = (int)stemp->max;
|
||||
dval->value = int(stemp->val1);
|
||||
dval->min = int(stemp->min);
|
||||
dval->max = int(stemp->max);
|
||||
break;
|
||||
}
|
||||
case SOCK_BOOLEAN: {
|
||||
bNodeSocketValueBoolean *dval = (bNodeSocketValueBoolean *)sock->default_value;
|
||||
dval->value = (int)stemp->val1;
|
||||
dval->value = int(stemp->val1);
|
||||
break;
|
||||
}
|
||||
case SOCK_VECTOR: {
|
||||
|
||||
@@ -300,7 +300,7 @@ static bool ntree_shader_expand_socket_default(bNodeTree *localtree,
|
||||
BLI_assert(value_socket != nullptr);
|
||||
src_int = static_cast<bNodeSocketValueInt *>(socket->default_value);
|
||||
dst_float = static_cast<bNodeSocketValueFloat *>(value_socket->default_value);
|
||||
dst_float->value = (float)(src_int->value);
|
||||
dst_float->value = float(src_int->value);
|
||||
break;
|
||||
case SOCK_FLOAT:
|
||||
value_node = nodeAddStaticNode(nullptr, localtree, SH_NODE_VALUE);
|
||||
|
||||
@@ -44,7 +44,7 @@ static void node_declare(NodeDeclarationBuilder &b)
|
||||
.subtype(PROP_FACTOR);
|
||||
b.add_input<decl::Float>(N_("IOR")).default_value(1.55f).min(0.0f).max(1000.0f);
|
||||
b.add_input<decl::Float>(N_("Offset"))
|
||||
.default_value(2.0f * ((float)M_PI) / 180.0f)
|
||||
.default_value(2.0f * float(M_PI) / 180.0f)
|
||||
.min(-M_PI_2)
|
||||
.max(M_PI_2)
|
||||
.subtype(PROP_ANGLE);
|
||||
|
||||
@@ -147,7 +147,7 @@ class BrickFunction : public fn::MultiFunction {
|
||||
n = (n + 1013) & 0x7fffffff;
|
||||
n = (n >> 13) ^ n;
|
||||
const uint nn = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
|
||||
return 0.5f * ((float)nn / 1073741824.0f);
|
||||
return 0.5f * (float(nn) / 1073741824.0f);
|
||||
}
|
||||
|
||||
static float smoothstepf(const float f)
|
||||
@@ -169,14 +169,14 @@ class BrickFunction : public fn::MultiFunction {
|
||||
{
|
||||
float offset = 0.0f;
|
||||
|
||||
const int rownum = (int)floorf(p.y / row_height);
|
||||
const int rownum = int(floorf(p.y / row_height));
|
||||
|
||||
if (offset_frequency && squash_frequency) {
|
||||
brick_width *= (rownum % squash_frequency) ? 1.0f : squash_amount;
|
||||
offset = (rownum % offset_frequency) ? 0.0f : (brick_width * offset_amount);
|
||||
}
|
||||
|
||||
const int bricknum = (int)floorf((p.x + offset) / brick_width);
|
||||
const int bricknum = int(floorf((p.x + offset) / brick_width));
|
||||
|
||||
const float x = (p.x + offset) - brick_width * bricknum;
|
||||
const float y = p.y - row_height * rownum;
|
||||
|
||||
@@ -77,9 +77,9 @@ class NodeTexChecker : public fn::MultiFunction {
|
||||
/* Avoid precision issues on unit coordinates. */
|
||||
const float3 p = (vector[i] * scale[i] + 0.000001f) * 0.999999f;
|
||||
|
||||
const int xi = abs((int)(floorf(p.x)));
|
||||
const int yi = abs((int)(floorf(p.y)));
|
||||
const int zi = abs((int)(floorf(p.z)));
|
||||
const int xi = abs(int(floorf(p.x)));
|
||||
const int yi = abs(int(floorf(p.y)));
|
||||
const int zi = abs(int(floorf(p.z)));
|
||||
|
||||
r_fac[i] = ((xi % 2 == yi % 2) == (zi % 2)) ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
@@ -189,12 +189,12 @@ static int node_shader_gpu_tex_sky(GPUMaterial *mat,
|
||||
/* Pass sky_state->configs[3][9] as 3*(vec4+vec4)+vec3 */
|
||||
float config_x07[8], config_y07[8], config_z07[8], config_xyz8[3];
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
config_x07[i] = (float)sky_state->configs[0][i];
|
||||
config_y07[i] = (float)sky_state->configs[1][i];
|
||||
config_z07[i] = (float)sky_state->configs[2][i];
|
||||
config_x07[i] = float(sky_state->configs[0][i]);
|
||||
config_y07[i] = float(sky_state->configs[1][i]);
|
||||
config_z07[i] = float(sky_state->configs[2][i]);
|
||||
}
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
config_xyz8[i] = (float)sky_state->configs[i][8];
|
||||
config_xyz8[i] = float(sky_state->configs[i][8]);
|
||||
}
|
||||
float radiance[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
@@ -177,7 +177,7 @@ class WhiteNoiseFunction : public fn::MultiFunction {
|
||||
static void sh_node_noise_build_multi_function(NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
const bNode &node = builder.node();
|
||||
builder.construct_and_set_matching_fn<WhiteNoiseFunction>((int)node.custom1);
|
||||
builder.construct_and_set_matching_fn<WhiteNoiseFunction>(int(node.custom1));
|
||||
}
|
||||
|
||||
} // namespace blender::nodes::node_shader_tex_white_noise_cc
|
||||
|
||||
Reference in New Issue
Block a user