Cleanup: use function style casts

This commit is contained in:
Campbell Barton 2023-01-23 17:31:46 +11:00
parent ab0be6ec24
commit eca4b991d8
11 changed files with 141 additions and 141 deletions

View File

@ -1053,7 +1053,7 @@ void BKE_defvert_extract_vgroup_to_edgeweights(const MDeformVert *dvert,
if (dvert && defgroup != -1) {
int i = edges_num;
float *tmp_weights = static_cast<float *>(
MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__));
MEM_mallocN(sizeof(*tmp_weights) * size_t(verts_num), __func__));
BKE_defvert_extract_vgroup_to_vertweights(
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
@ -1082,7 +1082,7 @@ void BKE_defvert_extract_vgroup_to_loopweights(const MDeformVert *dvert,
if (dvert && defgroup != -1) {
int i = loops_num;
float *tmp_weights = static_cast<float *>(
MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__));
MEM_mallocN(sizeof(*tmp_weights) * size_t(verts_num), __func__));
BKE_defvert_extract_vgroup_to_vertweights(
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
@ -1113,7 +1113,7 @@ void BKE_defvert_extract_vgroup_to_polyweights(const MDeformVert *dvert,
if (dvert && defgroup != -1) {
int i = polys_num;
float *tmp_weights = static_cast<float *>(
MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__));
MEM_mallocN(sizeof(*tmp_weights) * size_t(verts_num), __func__));
BKE_defvert_extract_vgroup_to_vertweights(
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);

View File

@ -768,12 +768,12 @@ static void surfaceGenerateGrid(DynamicPaintSurface *surface)
volume = td[0] * td[1] * td[2];
/* determine final grid size by trying to fit average 10.000 points per grid cell */
dim_factor = (float)pow((double)volume / ((double)sData->total_points / 10000.0),
1.0 / (double)axis);
dim_factor = (float)pow(double(volume) / (double(sData->total_points) / 10000.0),
1.0 / double(axis));
/* define final grid size using dim_factor, use min 3 for active axes */
for (i = 0; i < 3; i++) {
grid->dim[i] = (int)floor(td[i] / dim_factor);
grid->dim[i] = int(floor(td[i] / dim_factor));
CLAMP(grid->dim[i], (dim[i] >= min_dim) ? 3 : 1, 100);
}
grid_cells = grid->dim[0] * grid->dim[1] * grid->dim[2];
@ -2101,7 +2101,7 @@ static void dynamicPaint_frameUpdate(
/* loop through surfaces */
for (; surface; surface = surface->next) {
int current_frame = (int)scene->r.cfra;
int current_frame = int(scene->r.cfra);
bool no_surface_data;
/* free bake data if not required anymore */
@ -2123,7 +2123,7 @@ static void dynamicPaint_frameUpdate(
CLAMP(current_frame, surface->start_frame, surface->end_frame);
if (no_surface_data || current_frame != surface->current_frame ||
(int)scene->r.cfra == surface->start_frame) {
int(scene->r.cfra) == surface->start_frame) {
PointCache *cache = surface->pointcache;
PTCacheID pid;
surface->current_frame = current_frame;
@ -2132,21 +2132,21 @@ static void dynamicPaint_frameUpdate(
BKE_ptcache_id_from_dynamicpaint(&pid, ob, surface);
pid.cache->startframe = surface->start_frame;
pid.cache->endframe = surface->end_frame;
BKE_ptcache_id_time(&pid, scene, (float)scene->r.cfra, nullptr, nullptr, nullptr);
BKE_ptcache_id_time(&pid, scene, float(scene->r.cfra), nullptr, nullptr, nullptr);
/* reset non-baked cache at first frame */
if ((int)scene->r.cfra == surface->start_frame && !(cache->flag & PTCACHE_BAKED)) {
if (int(scene->r.cfra) == surface->start_frame && !(cache->flag & PTCACHE_BAKED)) {
cache->flag |= PTCACHE_REDO_NEEDED;
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
cache->flag &= ~PTCACHE_REDO_NEEDED;
}
/* try to read from cache */
bool can_simulate = ((int)scene->r.cfra == current_frame) &&
bool can_simulate = (int(scene->r.cfra) == current_frame) &&
!(cache->flag & PTCACHE_BAKED);
if (BKE_ptcache_read(&pid, (float)scene->r.cfra, can_simulate)) {
BKE_ptcache_validate(cache, (int)scene->r.cfra);
if (BKE_ptcache_read(&pid, float(scene->r.cfra), can_simulate)) {
BKE_ptcache_validate(cache, int(scene->r.cfra));
}
/* if read failed and we're on surface range do recalculate */
else if (can_simulate) {
@ -2238,24 +2238,24 @@ static void dynamic_paint_create_uv_surface_direct_cb(void *__restrict userdata,
tPoint->pixel_index = index;
/* Actual pixel center, used when collision is found */
point[0][0] = ((float)tx + 0.5f) / w;
point[0][1] = ((float)ty + 0.5f) / h;
point[0][0] = (float(tx) + 0.5f) / w;
point[0][1] = (float(ty) + 0.5f) / h;
/*
* A pixel middle sample isn't enough to find very narrow polygons
* So using 4 samples of each corner too
*/
point[1][0] = ((float)tx) / w;
point[1][1] = ((float)ty) / h;
point[1][0] = (float(tx)) / w;
point[1][1] = (float(ty)) / h;
point[2][0] = ((float)tx + 1) / w;
point[2][1] = ((float)ty) / h;
point[2][0] = (float(tx) + 1) / w;
point[2][1] = (float(ty)) / h;
point[3][0] = ((float)tx) / w;
point[3][1] = ((float)ty + 1) / h;
point[3][0] = (float(tx)) / w;
point[3][1] = (float(ty) + 1) / h;
point[4][0] = ((float)tx + 1) / w;
point[4][1] = ((float)ty + 1) / h;
point[4][0] = (float(tx) + 1) / w;
point[4][1] = (float(ty) + 1) / h;
/* Loop through samples, starting from middle point */
for (int sample = 0; sample < 5; sample++) {
@ -2337,8 +2337,8 @@ static void dynamic_paint_create_uv_surface_neighbor_cb(void *__restrict userdat
const int v_min = (ty > 0) ? -1 : 0;
const int v_max = (ty < (h - 1)) ? 1 : 0;
point[0] = ((float)tx + 0.5f) / w;
point[1] = ((float)ty + 0.5f) / h;
point[0] = (float(tx) + 0.5f) / w;
point[1] = (float(ty) + 0.5f) / h;
/* search through defined area for neighbor, checking grid directions first */
for (int ni = 0; ni < 8; ni++) {
@ -2505,8 +2505,8 @@ static int dynamic_paint_find_neighbor_pixel(const DynamicPaintCreateUVSurfaceDa
float pixel[2];
pixel[0] = ((float)(px + neighX[n_index]) + 0.5f) / (float)w;
pixel[1] = ((float)(py + neighY[n_index]) + 0.5f) / (float)h;
pixel[0] = (float(px + neighX[n_index]) + 0.5f) / float(w);
pixel[1] = (float(py + neighY[n_index]) + 0.5f) / float(h);
/* Do a small recursive search for the best island edge. */
dynamic_paint_find_island_border(data, &bdata, cPoint->tri_index, pixel, -1, 5);
@ -2646,7 +2646,7 @@ static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceDa
int w = bdata->w, h = bdata->h, px = bdata->px, py = bdata->py;
const int final_pixel[2] = {(int)floorf(tgt_pixel[0] * w), (int)floorf(tgt_pixel[1] * h)};
const int final_pixel[2] = {int(floorf(tgt_pixel[0] * w)), int(floorf(tgt_pixel[1] * h))};
/* If current pixel uv is outside of texture */
if (final_pixel[0] < 0 || final_pixel[0] >= w || final_pixel[1] < 0 || final_pixel[1] >= h) {
@ -3124,7 +3124,7 @@ int dynamicPaint_createUVSurface(Scene *scene,
sData->total_points = 0;
}
else {
sData->total_points = (int)active_points;
sData->total_points = int(active_points);
sData->format_data = f_data;
for (int index = 0, cursor = 0; index < (w * h); index++) {
@ -3960,7 +3960,7 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(void *__restrict userdata,
const int index = grid->t_index[grid->s_pos[c_index] + id];
const int samples = bData->s_num[index];
int ss;
float total_sample = (float)samples;
float total_sample = float(samples);
float brushStrength = 0.0f; /* brush influence factor */
float depth = 0.0f; /* brush intersection depth */
float velocity_val = 0.0f;
@ -4322,7 +4322,7 @@ static bool dynamicPaint_paintMesh(Depsgraph *depsgraph,
}
if (brush->flags & MOD_DPAINT_PROX_PROJECT && brush->collision != MOD_DPAINT_COL_VOLUME) {
mul_v3_fl(avg_brushNor, 1.0f / (float)numOfVerts);
mul_v3_fl(avg_brushNor, 1.0f / float(numOfVerts));
/* instead of null vector use positive z */
if (UNLIKELY(normalize_v3(avg_brushNor) == 0.0f)) {
avg_brushNor[2] = 1.0f;
@ -4878,7 +4878,7 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, cons
int numOfNeighs = adj_data->n_num[index];
for (int i = 0; i < numOfNeighs; i++) {
bData->average_dist += (double)bNeighs[adj_data->n_index[index] + i].dist;
bData->average_dist += double(bNeighs[adj_data->n_index[index] + i].dist);
}
}
bData->average_dist /= adj_data->total_targets;
@ -4959,11 +4959,11 @@ static void surface_determineForceTargetPoints(const PaintSurfaceData *sData,
/* and multiply depending on how deeply force intersects surface */
temp = fabsf(force_intersect);
CLAMP(temp, 0.0f, 1.0f);
mul_v2_fl(closest_d, acosf(temp) / (float)M_PI_2);
mul_v2_fl(closest_d, acosf(temp) / float(M_PI_2));
}
else {
/* if only single neighbor, still linearize force intersection effect */
closest_d[0] = 1.0f - acosf(closest_d[0]) / (float)M_PI_2;
closest_d[0] = 1.0f - acosf(closest_d[0]) / float(M_PI_2);
}
}
@ -4986,9 +4986,9 @@ static void dynamicPaint_doSmudge(DynamicPaintSurface *surface,
CLAMP_MIN(max_velocity, vel);
}
int steps = (int)ceil((double)max_velocity / bData->average_dist * (double)timescale);
int steps = int(ceil(double(max_velocity) / bData->average_dist * double(timescale)));
CLAMP(steps, 0, 12);
float eff_scale = brush->smudge_strength / (float)steps * timescale;
float eff_scale = brush->smudge_strength / float(steps) * timescale;
for (int step = 0; step < steps; step++) {
for (int index = 0; index < sData->total_points; index++) {
@ -5188,9 +5188,9 @@ static int dynamicPaint_prepareEffectStep(Depsgraph *depsgraph,
}
fastest_effect = max_fff(spread_speed, shrink_speed, average_force);
avg_dist = bData->average_dist * (double)CANVAS_REL_SIZE / (double)getSurfaceDimension(sData);
avg_dist = bData->average_dist * double(CANVAS_REL_SIZE) / double(getSurfaceDimension(sData));
steps = (int)ceilf(1.5f * EFF_MOVEMENT_PER_FRAME * fastest_effect / avg_dist * timescale);
steps = int(ceilf(1.5f * EFF_MOVEMENT_PER_FRAME * fastest_effect / avg_dist * timescale));
CLAMP(steps, 1, 20);
return steps;
@ -5369,7 +5369,7 @@ static void dynamic_paint_effect_drip_cb(void *__restrict userdata,
float dir_factor, a_factor;
const float speed_scale = eff_scale * force[index * 4 + 3] / bNeighs[n_idx].dist;
const uint n_trgt = (uint)n_target[n_idx];
const uint n_trgt = uint(n_target[n_idx]);
/* Sort of spin-lock, but only for given ePoint.
* Since the odds a same ePoint is modified at the same time by several threads is very low,
@ -5740,14 +5740,14 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal
int numOfNeighs = sData->adj_data->n_num[index];
for (int i = 0; i < numOfNeighs; i++) {
average_dist += (double)bNeighs[sData->adj_data->n_index[index] + i].dist;
average_dist += double(bNeighs[sData->adj_data->n_index[index] + i].dist);
}
}
average_dist *= (double)wave_scale / sData->adj_data->total_targets;
average_dist *= double(wave_scale) / sData->adj_data->total_targets;
/* determine number of required steps */
steps = (int)ceil((double)(WAVE_TIME_FAC * timescale * surface->wave_timescale) /
(average_dist / (double)wave_speed / 3));
steps = (int)ceil(double(WAVE_TIME_FAC * timescale * surface->wave_timescale) /
(average_dist / double(wave_speed) / 3));
CLAMP(steps, 1, 20);
timescale /= steps;
@ -6346,7 +6346,7 @@ static int dynamicPaint_doStep(Depsgraph *depsgraph,
/* Prepare effects and get number of required steps */
steps = dynamicPaint_prepareEffectStep(depsgraph, surface, scene, ob, &force, timescale);
for (s = 0; s < steps; s++) {
dynamicPaint_doEffectStep(surface, force, prevPoint, timescale, (float)steps);
dynamicPaint_doEffectStep(surface, force, prevPoint, timescale, float(steps));
}
/* Free temporary effect data */
@ -6386,7 +6386,7 @@ int dynamicPaint_calculateFrame(
timescale = 1.0f / (surface->substeps + 1);
for (st = 1; st <= surface->substeps; st++) {
float subframe = ((float)st) / (surface->substeps + 1);
float subframe = (float(st)) / (surface->substeps + 1);
if (!dynamicPaint_doStep(depsgraph, scene, cObject, surface, timescale, subframe)) {
return 0;
}

View File

@ -441,28 +441,28 @@ static void manta_set_domain_from_mesh(FluidDomainSettings *fds,
scale = res / size[0];
fds->scale = size[0] / fabsf(ob->scale[0]);
fds->base_res[0] = res;
fds->base_res[1] = max_ii((int)(size[1] * scale + 0.5f), 4);
fds->base_res[2] = max_ii((int)(size[2] * scale + 0.5f), 4);
fds->base_res[1] = max_ii(int(size[1] * scale + 0.5f), 4);
fds->base_res[2] = max_ii(int(size[2] * scale + 0.5f), 4);
}
else if (size[1] >= MAX2(size[0], size[2])) {
scale = res / size[1];
fds->scale = size[1] / fabsf(ob->scale[1]);
fds->base_res[0] = max_ii((int)(size[0] * scale + 0.5f), 4);
fds->base_res[0] = max_ii(int(size[0] * scale + 0.5f), 4);
fds->base_res[1] = res;
fds->base_res[2] = max_ii((int)(size[2] * scale + 0.5f), 4);
fds->base_res[2] = max_ii(int(size[2] * scale + 0.5f), 4);
}
else {
scale = res / size[2];
fds->scale = size[2] / fabsf(ob->scale[2]);
fds->base_res[0] = max_ii((int)(size[0] * scale + 0.5f), 4);
fds->base_res[1] = max_ii((int)(size[1] * scale + 0.5f), 4);
fds->base_res[0] = max_ii(int(size[0] * scale + 0.5f), 4);
fds->base_res[1] = max_ii(int(size[1] * scale + 0.5f), 4);
fds->base_res[2] = res;
}
/* Set cell size. */
fds->cell_size[0] /= (float)fds->base_res[0];
fds->cell_size[1] /= (float)fds->base_res[1];
fds->cell_size[2] /= (float)fds->base_res[2];
fds->cell_size[0] /= float(fds->base_res[0]);
fds->cell_size[1] /= float(fds->base_res[1]);
fds->cell_size[2] /= float(fds->base_res[2]);
}
static void update_final_gravity(FluidDomainSettings *fds, Scene *scene)
@ -479,7 +479,7 @@ static void update_final_gravity(FluidDomainSettings *fds, Scene *scene)
static bool fluid_modifier_init(
FluidModifierData *fmd, Depsgraph *depsgraph, Object *ob, Scene *scene, Mesh *me)
{
int scene_framenr = (int)DEG_get_ctime(depsgraph);
int scene_framenr = int(DEG_get_ctime(depsgraph));
if ((fmd->type & MOD_FLUID_TYPE_DOMAIN) && fmd->domain && !fmd->domain->fluid) {
FluidDomainSettings *fds = fmd->domain;
@ -590,10 +590,10 @@ static void clamp_bounds_in_domain(FluidDomainSettings *fds,
/* Adapt to velocity. */
if (min_vel && min_vel[i] < 0.0f) {
min[i] += (int)floor(min_vel[i] * dt);
min[i] += int(floor(min_vel[i] * dt));
}
if (max_vel && max_vel[i] > 0.0f) {
max[i] += (int)ceil(max_vel[i] * dt);
max[i] += int(ceil(max_vel[i] * dt));
}
/* Clamp within domain max size. */
@ -650,18 +650,18 @@ static void bb_boundInsert(FluidObjectBB *bb, const float point[3])
int i = 0;
if (!bb->valid) {
for (; i < 3; i++) {
bb->min[i] = (int)floor(point[i]);
bb->max[i] = (int)ceil(point[i]);
bb->min[i] = int(floor(point[i]));
bb->max[i] = int(ceil(point[i]));
}
bb->valid = 1;
}
else {
for (; i < 3; i++) {
if (point[i] < bb->min[i]) {
bb->min[i] = (int)floor(point[i]);
bb->min[i] = int(floor(point[i]));
}
if (point[i] > bb->max[i]) {
bb->max[i] = (int)ceil(point[i]);
bb->max[i] = int(ceil(point[i]));
}
}
}
@ -960,7 +960,7 @@ static void obstacles_from_mesh_task_cb(void *__restrict userdata,
for (int y = data->min[1]; y < data->max[1]; y++) {
const int index = manta_get_index(
x - bb->min[0], bb->res[0], y - bb->min[1], bb->res[1], z - bb->min[2]);
const float ray_start[3] = {(float)x + 0.5f, (float)y + 0.5f, (float)z + 0.5f};
const float ray_start[3] = {float(x) + 0.5f, float(y) + 0.5f, float(z) + 0.5f};
/* Calculate levelset values from meshes. Result in bb->distances. */
update_distances(index,
@ -1055,7 +1055,7 @@ static void obstacles_from_mesh(Object *coll_ob,
/* Set emission map.
* Use 3 cell diagonals as margin (3 * 1.732 = 5.196). */
int bounds_margin = (int)ceil(5.196);
int bounds_margin = int(ceil(5.196));
clamp_bounds_in_domain(fds, bb->min, bb->max, nullptr, nullptr, bounds_margin, dt);
bb_allocateData(bb, true, false);
@ -1216,7 +1216,7 @@ static void compute_obstaclesemission(Scene *scene,
}
/* More splitting because of emission subframe: If no subframes present, sample_size is 1. */
float sample_size = 1.0f / (float)(subframes + 1);
float sample_size = 1.0f / float(subframes + 1);
float subframe_dt = dt * sample_size;
/* Emission loop. When not using subframes this will loop only once. */
@ -1484,7 +1484,7 @@ static void emit_from_particles_task_cb(void *__restrict userdata,
for (int y = data->min[1]; y < data->max[1]; y++) {
const int index = manta_get_index(
x - bb->min[0], bb->res[0], y - bb->min[1], bb->res[1], z - bb->min[2]);
const float ray_start[3] = {((float)x) + 0.5f, ((float)y) + 0.5f, ((float)z) + 0.5f};
const float ray_start[3] = {(float(x)) + 0.5f, (float(y)) + 0.5f, (float(z)) + 0.5f};
/* Find particle distance from the kdtree. */
KDTreeNearest_3d nearest;
@ -1554,7 +1554,7 @@ static void emit_from_particles(Object *flow_ob,
/* setup particle radius emission if enabled */
if (ffs->flags & FLUID_FLOW_USE_PART_SIZE) {
tree = BLI_kdtree_3d_new(psys->totpart + psys->totchild);
bounds_margin = (int)ceil(solid + smooth);
bounds_margin = int(ceil(solid + smooth));
}
/* calculate local position for each particle */
@ -2008,7 +2008,7 @@ static void emit_from_mesh_task_cb(void *__restrict userdata,
for (int y = data->min[1]; y < data->max[1]; y++) {
const int index = manta_get_index(
x - bb->min[0], bb->res[0], y - bb->min[1], bb->res[1], z - bb->min[2]);
const float ray_start[3] = {((float)x) + 0.5f, ((float)y) + 0.5f, ((float)z) + 0.5f};
const float ray_start[3] = {(float(x)) + 0.5f, (float(y)) + 0.5f, (float(z)) + 0.5f};
/* Compute emission only for flow objects that produce fluid (i.e. skip outflow objects).
* Result in bb->influence. Also computes initial velocities. Result in bb->velocity. */
@ -2031,9 +2031,9 @@ static void emit_from_mesh_task_cb(void *__restrict userdata,
data->has_velocity,
data->defgrp_index,
data->dvert,
(float)x,
(float)y,
(float)z);
float(x),
float(y),
float(z));
}
/* Calculate levelset values from meshes. Result in bb->distances. */
@ -2123,7 +2123,7 @@ static void emit_from_mesh(
/* Set emission map.
* Use 3 cell diagonals as margin (3 * 1.732 = 5.196). */
int bounds_margin = (int)ceil(5.196);
int bounds_margin = int(ceil(5.196));
clamp_bounds_in_domain(fds, bb->min, bb->max, nullptr, nullptr, bounds_margin, dt);
bb_allocateData(bb, ffs->flags & FLUID_FLOW_INITVELOCITY, true);
@ -2199,9 +2199,9 @@ static void adaptive_domain_adjust(
/* add to total shift */
add_v3_v3(fds->shift_f, frame_shift_f);
/* convert to integer */
total_shift[0] = (int)floorf(fds->shift_f[0]);
total_shift[1] = (int)floorf(fds->shift_f[1]);
total_shift[2] = (int)floorf(fds->shift_f[2]);
total_shift[0] = int(floorf(fds->shift_f[0]));
total_shift[1] = int(floorf(fds->shift_f[1]));
total_shift[2] = int(floorf(fds->shift_f[2]));
int temp_shift[3];
copy_v3_v3_int(temp_shift, fds->shift);
sub_v3_v3v3_int(new_shift, total_shift, fds->shift);
@ -2733,7 +2733,7 @@ static void compute_flowsemission(Scene *scene,
}
/* More splitting because of emission subframe: If no subframes present, sample_size is 1. */
float sample_size = 1.0f / (float)(subframes + 1);
float sample_size = 1.0f / float(subframes + 1);
float subframe_dt = dt * sample_size;
/* Emission loop. When not using subframes this will loop only once. */
@ -3135,9 +3135,9 @@ static void update_effectors_task_cb(void *__restrict userdata,
normalize_v3(vel);
mul_v3_fl(vel, mag);
voxel_center[0] = fds->p0[0] + fds->cell_size[0] * ((float)(x + fds->res_min[0]) + 0.5f);
voxel_center[1] = fds->p0[1] + fds->cell_size[1] * ((float)(y + fds->res_min[1]) + 0.5f);
voxel_center[2] = fds->p0[2] + fds->cell_size[2] * ((float)(z + fds->res_min[2]) + 0.5f);
voxel_center[0] = fds->p0[0] + fds->cell_size[0] * (float(x + fds->res_min[0]) + 0.5f);
voxel_center[1] = fds->p0[1] + fds->cell_size[1] * (float(y + fds->res_min[1]) + 0.5f);
voxel_center[2] = fds->p0[2] + fds->cell_size[2] * (float(z + fds->res_min[2]) + 0.5f);
mul_m4_v3(fds->obmat, voxel_center);
/* Do effectors. */
@ -3297,7 +3297,7 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
positions[i][2] = manta_liquid_get_vertex_z_at(fds->fluid, i);
/* Adjust coordinates from Mantaflow to match viewport scaling. */
float tmp[3] = {(float)fds->res[0], (float)fds->res[1], (float)fds->res[2]};
float tmp[3] = {float(fds->res[0]), float(fds->res[1]), float(fds->res[2])};
/* Scale to unit cube around 0. */
mul_v3_fl(tmp, fds->mesh_scale * 0.5f);
sub_v3_v3(positions[i], tmp);
@ -4078,7 +4078,7 @@ static void fluid_modifier_processDomain(FluidModifierData *fmd,
static void fluid_modifier_process(
FluidModifierData *fmd, Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *me)
{
const int scene_framenr = (int)DEG_get_ctime(depsgraph);
const int scene_framenr = int(DEG_get_ctime(depsgraph));
if (fmd->type & MOD_FLUID_TYPE_FLOW) {
fluid_modifier_processFlow(fmd, depsgraph, scene, ob, me, scene_framenr);
@ -4304,15 +4304,15 @@ static void manta_smoke_calc_transparency(FluidDomainSettings *fds,
/* Convert light pos to sim cell space. */
mul_m4_v3(fds->imat, light);
light[0] = (light[0] - fds->p0[0]) / fds->cell_size[0] - 0.5f - (float)fds->res_min[0];
light[1] = (light[1] - fds->p0[1]) / fds->cell_size[1] - 0.5f - (float)fds->res_min[1];
light[2] = (light[2] - fds->p0[2]) / fds->cell_size[2] - 0.5f - (float)fds->res_min[2];
light[0] = (light[0] - fds->p0[0]) / fds->cell_size[0] - 0.5f - float(fds->res_min[0]);
light[1] = (light[1] - fds->p0[1]) / fds->cell_size[1] - 0.5f - float(fds->res_min[1]);
light[2] = (light[2] - fds->p0[2]) / fds->cell_size[2] - 0.5f - float(fds->res_min[2]);
/* Calculate domain bounds in sim cell space. */
/* 0,2,4 = 0.0f */
bv[1] = (float)fds->res[0]; /* X */
bv[3] = (float)fds->res[1]; /* Y */
bv[5] = (float)fds->res[2]; /* Z */
bv[1] = float(fds->res[0]); /* X */
bv[3] = float(fds->res[1]); /* Y */
bv[5] = float(fds->res[2]); /* Z */
for (int z = 0; z < fds->res[2]; z++) {
size_t index = z * slabsize;
@ -4327,22 +4327,22 @@ static void manta_smoke_calc_transparency(FluidDomainSettings *fds,
/* Reset shadow value. */
shadow[index] = -1.0f;
voxel_center[0] = (float)x;
voxel_center[1] = (float)y;
voxel_center[2] = (float)z;
voxel_center[0] = float(x);
voxel_center[1] = float(y);
voxel_center[2] = float(z);
/* Get starting cell (light pos). */
if (BLI_bvhtree_bb_raycast(bv, light, voxel_center, pos) > FLT_EPSILON) {
/* We're outside -> use point on side of domain. */
cell[0] = (int)floor(pos[0]);
cell[1] = (int)floor(pos[1]);
cell[2] = (int)floor(pos[2]);
cell[0] = int(floor(pos[0]));
cell[1] = int(floor(pos[1]));
cell[2] = int(floor(pos[2]));
}
else {
/* We're inside -> use light itself. */
cell[0] = (int)floor(light[0]);
cell[1] = (int)floor(light[1]);
cell[2] = (int)floor(light[2]);
cell[0] = int(floor(light[0]));
cell[1] = int(floor(light[1]));
cell[2] = int(floor(light[2]));
}
/* Clamp within grid bounds */
CLAMP(cell[0], 0, fds->res[0] - 1);
@ -4394,9 +4394,9 @@ float BKE_fluid_get_velocity_at(Object *ob, float position[3], float velocity[3]
}
/* map pos between 0.0 - 1.0 */
pos[0] = (pos[0] - fds->res_min[0]) / ((float)fds->res[0]);
pos[1] = (pos[1] - fds->res_min[1]) / ((float)fds->res[1]);
pos[2] = (pos[2] - fds->res_min[2]) / ((float)fds->res[2]);
pos[0] = (pos[0] - fds->res_min[0]) / (float(fds->res[0]));
pos[1] = (pos[1] - fds->res_min[1]) / (float(fds->res[1]));
pos[2] = (pos[2] - fds->res_min[2]) / (float(fds->res[2]));
/* Check if position is outside active area. */
if (fds->type == FLUID_DOMAIN_TYPE_GAS && fds->flags & FLUID_DOMAIN_USE_ADAPTIVE_DOMAIN) {

View File

@ -424,7 +424,7 @@ static void subdiv_foreach_edge_vertices_regular_do(SubdivForeachTaskContext *ct
{
const int resolution = ctx->settings->resolution;
const int resolution_1 = resolution - 1;
const float inv_resolution_1 = 1.0f / (float)resolution_1;
const float inv_resolution_1 = 1.0f / float(resolution_1);
const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
const int coarse_poly_index = coarse_poly - ctx->coarse_polys;
const int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index];
@ -487,7 +487,7 @@ static void subdiv_foreach_edge_vertices_special_do(SubdivForeachTaskContext *ct
const int resolution = ctx->settings->resolution;
const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
const int num_vertices_per_ptex_edge = ((resolution >> 1) + 1);
const float inv_ptex_resolution_1 = 1.0f / (float)(num_vertices_per_ptex_edge - 1);
const float inv_ptex_resolution_1 = 1.0f / float(num_vertices_per_ptex_edge - 1);
const int coarse_poly_index = coarse_poly - ctx->coarse_polys;
const int ptex_face_start_index = ctx->face_ptex_offset[coarse_poly_index];
int ptex_face_index = ptex_face_start_index;
@ -598,7 +598,7 @@ static void subdiv_foreach_inner_vertices_regular(SubdivForeachTaskContext *ctx,
const MPoly *coarse_poly)
{
const int resolution = ctx->settings->resolution;
const float inv_resolution_1 = 1.0f / (float)(resolution - 1);
const float inv_resolution_1 = 1.0f / float(resolution - 1);
const int coarse_poly_index = coarse_poly - ctx->coarse_polys;
const int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index];
const int start_vertex_index = ctx->subdiv_vertex_offset[coarse_poly_index];
@ -625,7 +625,7 @@ static void subdiv_foreach_inner_vertices_special(SubdivForeachTaskContext *ctx,
{
const int resolution = ctx->settings->resolution;
const int ptex_face_resolution = ptex_face_resolution_get(coarse_poly, resolution);
const float inv_ptex_face_resolution_1 = 1.0f / (float)(ptex_face_resolution - 1);
const float inv_ptex_face_resolution_1 = 1.0f / float(ptex_face_resolution - 1);
const int coarse_poly_index = coarse_poly - ctx->coarse_polys;
int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index];
const int start_vertex_index = ctx->subdiv_vertex_offset[coarse_poly_index];
@ -1096,7 +1096,7 @@ static void subdiv_foreach_loops_regular(SubdivForeachTaskContext *ctx,
const int ptex_inner_resolution = ptex_resolution - 2;
const int num_subdiv_edges_per_coarse_edge = resolution - 1;
const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
const float inv_ptex_resolution_1 = 1.0f / (float)(ptex_resolution - 1);
const float inv_ptex_resolution_1 = 1.0f / float(ptex_resolution - 1);
const int ptex_face_index = ctx->face_ptex_offset[coarse_poly_index];
const int start_vertex_index = ctx->vertices_inner_offset +
ctx->subdiv_vertex_offset[coarse_poly_index];
@ -1285,7 +1285,7 @@ static void subdiv_foreach_loops_special(SubdivForeachTaskContext *ctx,
const int coarse_poly_index = coarse_poly - ctx->coarse_polys;
const int ptex_face_resolution = ptex_face_resolution_get(coarse_poly, resolution);
const int ptex_face_inner_resolution = ptex_face_resolution - 2;
const float inv_ptex_resolution_1 = 1.0f / (float)(ptex_face_resolution - 1);
const float inv_ptex_resolution_1 = 1.0f / float(ptex_face_resolution - 1);
const int num_inner_vertices_per_ptex = (ptex_face_resolution - 1) * (ptex_face_resolution - 2);
const int num_inner_edges_per_ptex_face = num_inner_edges_per_ptex_face_get(
ptex_face_inner_resolution + 1);
@ -1685,7 +1685,7 @@ static void subdiv_foreach_vertices_of_loose_edges_task(void *__restrict userdat
}
const int resolution = ctx->settings->resolution;
const int resolution_1 = resolution - 1;
const float inv_resolution_1 = 1.0f / (float)resolution_1;
const float inv_resolution_1 = 1.0f / float(resolution_1);
const int num_subdiv_vertices_per_coarse_edge = resolution - 2;
const MEdge *coarse_edge = &ctx->coarse_edges[coarse_edge_index];
/* Subdivision vertices which corresponds to edge's v1 and v2. */

View File

@ -482,13 +482,13 @@ static float *get_ss_weights(WeightTable *wtable, int gridCuts, int faceLen)
wtable->weight_table[faceLen].w = w = static_cast<float *>(
MEM_callocN(sizeof(float) * faceLen * faceLen * (gridCuts + 2) * (gridCuts + 2),
"weight table alloc"));
fac = 1.0f / (float)faceLen;
fac = 1.0f / float(faceLen);
for (i = 0; i < faceLen; i++) {
for (x = 0; x < gridCuts + 2; x++) {
for (y = 0; y < gridCuts + 2; y++) {
fx = 0.5f - (float)x / (float)(gridCuts + 1) / 2.0f;
fy = 0.5f - (float)y / (float)(gridCuts + 1) / 2.0f;
fx = 0.5f - float(x) / float(gridCuts + 1) / 2.0f;
fy = 0.5f - float(y) / float(gridCuts + 1) / 2.0f;
fac2 = faceLen - 4;
w1 = (1.0f - fx) * (1.0f - fy) + (-fac2 * fx * fy * fac);
@ -498,7 +498,7 @@ static float *get_ss_weights(WeightTable *wtable, int gridCuts, int faceLen)
/* these values aren't used for tri's and cause divide by zero */
if (faceLen > 3) {
fac2 = 1.0f - (w1 + w2 + w4);
fac2 = fac2 / (float)(faceLen - 3);
fac2 = fac2 / float(faceLen - 3);
for (j = 0; j < faceLen; j++) {
w[j] = fac2;
}
@ -537,7 +537,7 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss,
float (*vertexCos)[3],
int useFlatSubdiv)
{
float creaseFactor = (float)ccgSubSurf_getSubdivisionLevels(ss);
float creaseFactor = float(ccgSubSurf_getSubdivisionLevels(ss));
blender::Vector<CCGVertHDL, 16> fverts;
float(*positions)[3] = (float(*)[3])dm->getVertArray(dm);
MEdge *medge = dm->getEdgeArray(dm);
@ -1004,7 +1004,7 @@ static void copyFinalLoopArray_task_cb(void *__restrict userdata,
CCGFace *f = ccgdm->faceMap[iter].face;
const int num_verts = ccgSubSurf_getFaceNumVerts(f);
const int grid_index = data->grid_offset[iter];
const size_t loop_index = 4 * (size_t)grid_index * (grid_size - 1) * (grid_size - 1);
const size_t loop_index = 4 * size_t(grid_index) * (grid_size - 1) * (grid_size - 1);
MLoop *ml = &data->mloop[loop_index];
for (int S = 0; S < num_verts; S++) {
for (int y = 0; y < grid_size - 1; y++) {
@ -1755,7 +1755,7 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
for (x = 1; x < edgeSize - 1; x++) {
float w[2];
w[1] = (float)x / (edgeSize - 1);
w[1] = float(x) / (edgeSize - 1);
w[0] = 1 - w[1];
DM_interp_vert_data(dm, &ccgdm->dm, vertIdx, w, 2, vertNum);
if (vertOrigIndex) {
@ -2036,7 +2036,7 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*r_positions)[3])
/* ad-hoc correction for boundary vertices, to at least avoid them
* moving completely out of place (brecht) */
if (numFaces && numFaces != N) {
mul_v3_fl(face_sum, (float)N / (float)numFaces);
mul_v3_fl(face_sum, float(N) / float(numFaces));
}
const float *co = static_cast<const float *>(ccgSubSurf_getVertData(ss, v));

View File

@ -108,16 +108,16 @@ static void laplacian_increase_edge_count(EdgeHash *edgehash, int v1, int v2)
void **p;
if (BLI_edgehash_ensure_p(edgehash, v1, v2, &p)) {
*p = (void *)((intptr_t)*p + (intptr_t)1);
*p = (void *)(intptr_t(*p) + intptr_t(1));
}
else {
*p = (void *)((intptr_t)1);
*p = (void *)(intptr_t(1));
}
}
static int laplacian_edge_count(EdgeHash *edgehash, int v1, int v2)
{
return (int)(intptr_t)BLI_edgehash_lookup(edgehash, v1, v2);
return int(intptr_t(BLI_edgehash_lookup(edgehash, v1, v2)));
}
static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3)
@ -1248,7 +1248,7 @@ static float meshdeform_interp_w(MeshDeformBind *mdb,
float totweight = 0.0f;
for (int i = 0; i < 3; i++) {
ivec[i] = (int)gridvec[i];
ivec[i] = int(gridvec[i]);
dvec[i] = gridvec[i] - ivec[i];
}
@ -1564,7 +1564,7 @@ static void meshdeform_matrix_solve(MeshDeformModifierData *mmd, MeshDeformBind
"Mesh deform solve %d / %d |||",
a + 1,
mdb->cage_verts_num);
progress_bar((float)(a + 1) / (float)(mdb->cage_verts_num), message);
progress_bar(float(a + 1) / float(mdb->cage_verts_num), message);
}
#if 0

View File

@ -187,7 +187,7 @@ static bool write_internal_bake_pixels(Image *image,
void *lock;
bool is_float;
char *mask_buffer = nullptr;
const size_t pixels_num = (size_t)width * (size_t)height;
const size_t pixels_num = size_t(width) * size_t(height);
ImageUser iuser;
BKE_imageuser_default(&iuser);
@ -383,7 +383,7 @@ static bool write_external_bake_pixels(const char *filepath,
/* margins */
if (margin > 0) {
char *mask_buffer = nullptr;
const size_t pixels_num = (size_t)width * (size_t)height;
const size_t pixels_num = size_t(width) * size_t(height);
mask_buffer = static_cast<char *>(MEM_callocN(sizeof(char) * pixels_num, "Bake Mask"));
RE_bake_mask_fill(pixel_array, pixels_num, mask_buffer);
@ -765,7 +765,7 @@ static bool bake_targets_init_internal(const BakeAPIRender *bkr,
bk_image->offset = targets->pixels_num;
BKE_image_get_tile_uv(bk_image->image, bk_image->tile_number, bk_image->uv_offset);
targets->pixels_num += (size_t)ibuf->x * (size_t)ibuf->y;
targets->pixels_num += size_t(ibuf->x) * size_t(ibuf->y);
}
else {
BKE_image_release_ibuf(bk_image->image, ibuf, lock);
@ -840,7 +840,7 @@ static bool bake_targets_init_external(const BakeAPIRender *bkr,
bk_image->height = bkr->height;
bk_image->offset = targets->pixels_num;
targets->pixels_num += (size_t)bkr->width * (size_t)bkr->height;
targets->pixels_num += size_t(bkr->width) * size_t(bkr->height);
if (!bkr->is_split_materials) {
break;

View File

@ -195,7 +195,7 @@ static float *SCULPT_geodesic_mesh_create(Object *ob,
edge_map_index++) {
const int e_other = ss->vemap[v_other].indices[edge_map_index];
int ev_other;
if (edges[e_other].v1 == (uint)v_other) {
if (edges[e_other].v1 == uint(v_other)) {
ev_other = edges[e_other].v2;
}
else {

View File

@ -1235,7 +1235,7 @@ static size_t sculpt_undo_alloc_and_store_hidden(PBVH *pbvh, SculptUndoNode *uno
int *grid_indices, totgrid;
BKE_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid, NULL, NULL, NULL);
size_t alloc_size = sizeof(*unode->grid_hidden) * (size_t)totgrid;
size_t alloc_size = sizeof(*unode->grid_hidden) * size_t(totgrid);
unode->grid_hidden = static_cast<BLI_bitmap **>(MEM_callocN(alloc_size, "unode->grid_hidden"));
for (int i = 0; i < totgrid; i++) {
@ -1335,24 +1335,24 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
unode->maxloop = 0;
unode->totloop = totloop;
size_t alloc_size = sizeof(int) * (size_t)totloop;
size_t alloc_size = sizeof(int) * size_t(totloop);
usculpt->undo_size += alloc_size;
}
if (need_faces) {
sculpt_undo_store_faces(ss, unode);
const size_t alloc_size = sizeof(*unode->faces) * (size_t)unode->faces_num;
const size_t alloc_size = sizeof(*unode->faces) * size_t(unode->faces_num);
usculpt->undo_size += alloc_size;
}
switch (type) {
case SCULPT_UNDO_COORDS: {
size_t alloc_size = sizeof(*unode->co) * (size_t)allvert;
size_t alloc_size = sizeof(*unode->co) * size_t(allvert);
unode->co = static_cast<float(*)[3]>(MEM_callocN(alloc_size, "SculptUndoNode.co"));
usculpt->undo_size += alloc_size;
/* Needed for original data lookup. */
alloc_size = sizeof(*unode->no) * (size_t)allvert;
alloc_size = sizeof(*unode->no) * size_t(allvert);
unode->no = static_cast<float(*)[3]>(MEM_callocN(alloc_size, "SculptUndoNode.no"));
usculpt->undo_size += alloc_size;
break;
@ -1369,7 +1369,7 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
break;
}
case SCULPT_UNDO_MASK: {
const size_t alloc_size = sizeof(*unode->mask) * (size_t)allvert;
const size_t alloc_size = sizeof(*unode->mask) * size_t(allvert);
unode->mask = static_cast<float *>(MEM_callocN(alloc_size, "SculptUndoNode.mask"));
usculpt->undo_size += alloc_size;
break;
@ -1377,13 +1377,13 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
case SCULPT_UNDO_COLOR: {
/* Allocate vertex colors, even for loop colors we still
* need this for original data lookup. */
const size_t alloc_size = sizeof(*unode->col) * (size_t)allvert;
const size_t alloc_size = sizeof(*unode->col) * size_t(allvert);
unode->col = static_cast<float(*)[4]>(MEM_callocN(alloc_size, "SculptUndoNode.col"));
usculpt->undo_size += alloc_size;
/* Allocate loop colors separately too. */
if (ss->vcol_domain == ATTR_DOMAIN_CORNER) {
size_t alloc_size_loop = sizeof(float) * 4 * (size_t)unode->totloop;
size_t alloc_size_loop = sizeof(float) * 4 * size_t(unode->totloop);
unode->loop_col = static_cast<float(*)[4]>(
MEM_calloc_arrayN(unode->totloop, sizeof(float) * 4, "SculptUndoNode.loop_col"));
@ -1399,7 +1399,7 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
case SCULPT_UNDO_GEOMETRY:
break;
case SCULPT_UNDO_FACE_SETS: {
const size_t alloc_size = sizeof(*unode->face_sets) * (size_t)unode->faces_num;
const size_t alloc_size = sizeof(*unode->face_sets) * size_t(unode->faces_num);
usculpt->undo_size += alloc_size;
break;
}
@ -1411,7 +1411,7 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
unode->totgrid = totgrid;
unode->gridsize = gridsize;
const size_t alloc_size = sizeof(*unode->grids) * (size_t)totgrid;
const size_t alloc_size = sizeof(*unode->grids) * size_t(totgrid);
unode->grids = static_cast<int *>(MEM_callocN(alloc_size, "SculptUndoNode.grids"));
usculpt->undo_size += alloc_size;
}
@ -1419,13 +1419,13 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
/* Regular mesh. */
unode->maxvert = ss->totvert;
const size_t alloc_size = sizeof(*unode->index) * (size_t)allvert;
const size_t alloc_size = sizeof(*unode->index) * size_t(allvert);
unode->index = static_cast<int *>(MEM_callocN(alloc_size, "SculptUndoNode.index"));
usculpt->undo_size += alloc_size;
}
if (ss->deform_modifiers_active) {
const size_t alloc_size = sizeof(*unode->orig_co) * (size_t)allvert;
const size_t alloc_size = sizeof(*unode->orig_co) * size_t(allvert);
unode->orig_co = static_cast<float(*)[3]>(MEM_callocN(alloc_size, "undoSculpt orig_cos"));
usculpt->undo_size += alloc_size;
}

View File

@ -138,7 +138,7 @@ void ED_undo_push(bContext *C, const char *str)
push_retval = BKE_undosys_step_push(wm->undo_stack, C, str);
if (U.undomemory != 0) {
const size_t memory_limit = (size_t)U.undomemory * 1024 * 1024;
const size_t memory_limit = size_t(U.undomemory) * 1024 * 1024;
BKE_undosys_stack_limit_steps_and_memory(wm->undo_stack, -1, memory_limit);
}

View File

@ -482,7 +482,7 @@ static void wm_init_userdef(Main *bmain)
SET_FLAG_FROM_TEST(G.f, (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0, G_FLAG_SCRIPT_AUTOEXEC);
}
MEM_CacheLimiter_set_maximum(((size_t)U.memcachelimit) * 1024 * 1024);
MEM_CacheLimiter_set_maximum((size_t(U.memcachelimit)) * 1024 * 1024);
BKE_sound_init(bmain);
/* Update the temporary directory from the preferences or fallback to the system default. */
@ -1603,10 +1603,10 @@ static ImBuf *blend_file_thumb_from_screenshot(bContext *C, BlendThumbnail **r_t
int ex, ey;
if (ibuf->x > ibuf->y) {
ex = BLEN_THUMB_SIZE;
ey = max_ii(1, (int)(((float)ibuf->y / (float)ibuf->x) * BLEN_THUMB_SIZE));
ey = max_ii(1, int((float(ibuf->y) / float(ibuf->x)) * BLEN_THUMB_SIZE));
}
else {
ex = max_ii(1, (int)(((float)ibuf->x / (float)ibuf->y) * BLEN_THUMB_SIZE));
ex = max_ii(1, int((float(ibuf->x) / float(ibuf->y)) * BLEN_THUMB_SIZE));
ey = BLEN_THUMB_SIZE;
}
@ -2775,14 +2775,14 @@ static char *wm_open_mainfile_description(struct bContext * /*C*/,
char time_st[FILELIST_DIRENTRY_TIME_LEN];
bool is_today, is_yesterday;
BLI_filelist_entry_datetime_to_string(
nullptr, (int64_t)stats.st_mtime, false, time_st, date_st, &is_today, &is_yesterday);
nullptr, int64_t(stats.st_mtime), false, time_st, date_st, &is_today, &is_yesterday);
if (is_today || is_yesterday) {
BLI_strncpy(date_st, is_today ? TIP_("Today") : TIP_("Yesterday"), sizeof(date_st));
}
/* Size. */
char size_str[FILELIST_DIRENTRY_SIZE_LEN];
BLI_filelist_entry_size_to_string(nullptr, (uint64_t)stats.st_size, false, size_str);
BLI_filelist_entry_size_to_string(nullptr, uint64_t(stats.st_size), false, size_str);
return BLI_sprintfN(
"%s\n\n%s: %s %s\n%s: %s", path, TIP_("Modified"), date_st, time_st, TIP_("Size"), size_str);