Cleanup: Replace MIN/MAX macros with C++ functions

Use `std::min` and `std::max` instead. Though keep MIN2 and MAX2
just for C code that hasn't been moved to C++ yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/117384
This commit is contained in:
Hans Goudey 2024-01-22 15:58:18 +01:00 committed by Hans Goudey
parent c478235985
commit 0618de49ad
138 changed files with 488 additions and 436 deletions

View File

@ -6,6 +6,7 @@
* \ingroup intern_mantaflow
*/
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
@ -830,7 +831,7 @@ void MANTA::initializeRNAMap(FluidModifierData *fmd)
string cacheDirectory(fds->cache_directory);
float viscosity = fds->viscosity_base * pow(10.0f, -fds->viscosity_exponent);
float domainSize = MAX3(fds->global_size[0], fds->global_size[1], fds->global_size[2]);
float domainSize = std::max({fds->global_size[0], fds->global_size[1], fds->global_size[2]});
string vdbCompressionMethod = "Compression_None";
if (fds->openvdb_compression == VDB_COMPRESSION_NONE) {

View File

@ -10,6 +10,7 @@
* Isolate since this needs to be called by #ImBuf code (bad level call).
*/
#include <algorithm>
#include <cstdlib>
#include <ft2build.h>
@ -368,9 +369,9 @@ bool BLF_thumb_preview(const char *filename, uchar *buf, int w, int h, int /*cha
width = std::max(width, height);
/* Fill up to 96% horizontally or vertically. */
float font_size = MIN3(float(w),
(float(w) * 0.96f / float(width) * float(w)),
float(h) * 0.96f / float(height) * float(h));
float font_size = std::min({float(w),
(float(w) * 0.96f / float(width) * float(w)),
float(h) * 0.96f / float(height) * float(h)});
if (font_size < 1 || FT_Set_Char_Size(face, int(font_size * 64.0f), 0, 72, 72) != FT_Err_Ok) {
/* Sizing can fail, but very rarely. */

View File

@ -8,6 +8,7 @@
#pragma once
#include <algorithm>
#include <optional>
#include <string>
@ -80,8 +81,8 @@ struct CryptomatteHash {
{
uint32_t mantissa = hash & ((1 << 23) - 1);
uint32_t exponent = (hash >> 23) & ((1 << 8) - 1);
exponent = MAX2(exponent, uint32_t(1));
exponent = MIN2(exponent, uint32_t(254));
exponent = std::max(exponent, uint32_t(1));
exponent = std::min(exponent, uint32_t(254));
exponent = exponent << 23;
uint32_t sign = (hash >> 31);
sign = sign << 31;

View File

@ -10,6 +10,7 @@
* collections/objects/object-data in current scene.
*/
#include <algorithm>
#include <cstdlib>
#include <cstring>
@ -1656,7 +1657,7 @@ static void blendfile_library_relocate_remap(Main *bmain,
old_id->name[dot_pos] = '~';
}
else {
len = MIN2(len, MAX_ID_NAME - 7);
len = std::min<size_t>(len, MAX_ID_NAME - 7);
BLI_strncpy(&old_id->name[len], "~000", 7);
}

View File

@ -1181,7 +1181,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa)
if (len < val.jump_speed * mul || bbd->part->boids->options & BOID_ALLOW_FLIGHT) {
jump = 1;
len = MIN2(len, val.jump_speed);
len = std::min(len, val.jump_speed);
copy_v3_v3(jump_v, dir);
jump_v[2] = z_v;
@ -1320,7 +1320,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
old_speed = len_v3(pa->prev_state.vel);
if (bbd->wanted_speed < old_speed) {
new_speed = MAX2(bbd->wanted_speed, old_speed - val.max_acc);
new_speed = std::max(bbd->wanted_speed, old_speed - val.max_acc);
}
else {
new_speed = std::min(bbd->wanted_speed, old_speed + val.max_acc);
@ -1346,7 +1346,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
/* finally constrain speed to max speed */
new_speed = normalize_v3(new_vel);
mul_v3_fl(new_vel, MIN2(new_speed, val.max_speed));
mul_v3_fl(new_vel, std::min(new_speed, val.max_speed));
/* get acceleration from difference of velocities */
sub_v3_v3v3(acc, new_vel, pa->prev_state.vel);

View File

@ -6,6 +6,8 @@
* \ingroup bke
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "DNA_cloth_types.h"
@ -896,7 +898,7 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd,
VECADDMUL(ib[2], collpair->normal, double(u3) * -impulse);
if ((magrelVel < 0.1f * d * time_multiplier) && (d > ALMOST_ZERO)) {
repulse = MIN2(d / time_multiplier, 0.1f * d * time_multiplier - magrelVel);
repulse = std::min(d / time_multiplier, 0.1f * d * time_multiplier - magrelVel);
if (impulse > ALMOST_ZERO) {
repulse = min_ff(repulse, 5.0 * impulse);
@ -1720,7 +1722,7 @@ int cloth_bvh_collision(
BKE_collision_objects_free(collobjs);
return MIN2(ret, 1);
return std::min(ret, 1);
}
BLI_INLINE void max_v3_v3v3(float r[3], const float a[3], const float b[3])

View File

@ -6,10 +6,10 @@
* \ingroup bke
*/
#include <algorithm>
#include <cmath>
#include <cstdarg>
#include <cstddef>
#include <cmath>
#include <cstdlib>
#include "MEM_guardedalloc.h"
@ -1075,8 +1075,8 @@ static void do_physical_effector(EffectorCache *eff,
copy_v3_v3(force, point->vel);
fac = normalize_v3(force) * point->vel_to_sec;
strength = MIN2(strength, 2.0f);
damp = MIN2(damp, 2.0f);
strength = std::min(strength, 2.0f);
damp = std::min(damp, 2.0f);
mul_v3_fl(force, -efd->falloff * fac * (strength * fac + damp));
break;

View File

@ -442,7 +442,7 @@ static void manta_set_domain_from_mesh(FluidDomainSettings *fds,
}
/* Define grid resolutions from longest domain side. */
if (size[0] >= MAX2(size[1], size[2])) {
if (size[0] >= std::max(size[1], size[2])) {
scale = res / size[0];
fds->scale = size[0] / fabsf(ob->scale[0]);
fds->base_res[0] = res;
@ -793,8 +793,8 @@ static void bb_combineMaps(FluidObjectBB *output,
output->influence[index_out]);
}
}
output->distances[index_out] = MIN2(bb2->distances[index_in],
output->distances[index_out]);
output->distances[index_out] = std::min(bb2->distances[index_in],
output->distances[index_out]);
if (output->velocity && bb2->velocity) {
/* Last sample replaces the velocity. */
output->velocity[index_out * 3] = ADD_IF_LOWER(output->velocity[index_out * 3],
@ -832,7 +832,7 @@ BLI_INLINE void apply_effector_fields(FluidEffectorSettings * /*fes*/,
{
/* Ensure that distance value is "joined" into the levelset. */
if (dest_phi_in) {
dest_phi_in[index] = MIN2(src_distance_value, dest_phi_in[index]);
dest_phi_in[index] = std::min(src_distance_value, dest_phi_in[index]);
}
/* Accumulate effector object count (important once effector object overlap). */
@ -914,15 +914,15 @@ static void update_velocities(FluidEffectorSettings *fes,
velocity_map[index * 3 + 2] = hit_vel[2];
break;
case FLUID_EFFECTOR_GUIDE_MIN:
velocity_map[index * 3] = MIN2(abs_hit_vel[0], abs_vel[0]);
velocity_map[index * 3 + 1] = MIN2(abs_hit_vel[1], abs_vel[1]);
velocity_map[index * 3 + 2] = MIN2(abs_hit_vel[2], abs_vel[2]);
velocity_map[index * 3] = std::min(abs_hit_vel[0], abs_vel[0]);
velocity_map[index * 3 + 1] = std::min(abs_hit_vel[1], abs_vel[1]);
velocity_map[index * 3 + 2] = std::min(abs_hit_vel[2], abs_vel[2]);
break;
case FLUID_EFFECTOR_GUIDE_MAX:
default:
velocity_map[index * 3] = MAX2(abs_hit_vel[0], abs_vel[0]);
velocity_map[index * 3 + 1] = MAX2(abs_hit_vel[1], abs_vel[1]);
velocity_map[index * 3 + 2] = MAX2(abs_hit_vel[2], abs_vel[2]);
velocity_map[index * 3] = std::max(abs_hit_vel[0], abs_vel[0]);
velocity_map[index * 3 + 1] = std::max(abs_hit_vel[1], abs_vel[1]);
velocity_map[index * 3 + 2] = std::max(abs_hit_vel[2], abs_vel[2]);
break;
}
}
@ -1792,7 +1792,7 @@ static void update_distances(int index,
}
/* Update global distance array but ensure that older entries are not overridden. */
distance_map[index] = MIN2(distance_map[index], min_dist);
distance_map[index] = std::min(distance_map[index], min_dist);
/* Sanity check: Ensure that distances don't explode. */
CLAMP(distance_map[index], -PHI_MAX, PHI_MAX);
@ -1973,8 +1973,8 @@ static void sample_mesh(FluidFlowSettings *ffs,
float convert_vel[3];
copy_v3_v3(convert_vel, ffs->vel_coord);
float time_mult = 1.0 / (25.0f * DT_DEFAULT);
float size_mult = MAX3(base_res[0], base_res[1], base_res[2]) /
MAX3(global_size[0], global_size[1], global_size[2]);
float size_mult = std::max({base_res[0], base_res[1], base_res[2]}) /
std::max({global_size[0], global_size[1], global_size[2]});
mul_v3_v3fl(convert_vel, ffs->vel_coord, size_mult * time_mult);
velocity_map[index * 3] += convert_vel[0];
@ -1990,7 +1990,7 @@ static void sample_mesh(FluidFlowSettings *ffs,
}
/* Apply final influence value but also consider volume initialization factor. */
influence_map[index] = MAX2(volume_factor, emission_strength);
influence_map[index] = std::max(volume_factor, emission_strength);
}
struct EmitFromDMData {
@ -2269,7 +2269,7 @@ static void adaptive_domain_adjust(
y - fds->res_min[1],
fds->res[1],
z - fds->res_min[2]);
max_den = (fuel) ? MAX2(density[index], fuel[index]) : density[index];
max_den = (fuel) ? std::max(density[index], fuel[index]) : density[index];
/* Check high resolution bounds if max density isn't already high enough. */
if (max_den < fds->adapt_threshold && fds->flags & FLUID_DOMAIN_USE_NOISE && fds->fluid) {
@ -2283,7 +2283,7 @@ static void adaptive_domain_adjust(
for (j = 0; j < block_size; j++) {
for (k = 0; k < block_size; k++) {
int big_index = manta_get_index(xx + i, wt_res[0], yy + j, wt_res[1], zz + k);
float den = (bigfuel) ? MAX2(bigdensity[big_index], bigfuel[big_index]) :
float den = (bigfuel) ? std::max(bigdensity[big_index], bigfuel[big_index]) :
bigdensity[big_index];
if (den > max_den) {
max_den = den;
@ -2433,7 +2433,7 @@ BLI_INLINE void apply_outflow_fields(int index,
/* Set levelset value for liquid inflow.
* Ensure that distance value is "joined" into the levelset. */
if (phiout) {
phiout[index] = MIN2(distance_value, phiout[index]);
phiout[index] = std::min(distance_value, phiout[index]);
}
/* Set smoke outflow, i.e. reset cell to zero. */
@ -2478,7 +2478,7 @@ BLI_INLINE void apply_inflow_fields(FluidFlowSettings *ffs,
/* Set levelset value for liquid inflow.
* Ensure that distance value is "joined" into the levelset. */
if (phi_in) {
phi_in[index] = MIN2(distance_value, phi_in[index]);
phi_in[index] = std::min(distance_value, phi_in[index]);
}
/* Set emission value for smoke inflow.
@ -2504,13 +2504,13 @@ BLI_INLINE void apply_inflow_fields(FluidFlowSettings *ffs,
if (absolute_flow) {
if (density && density_in) {
if (ffs->type != FLUID_FLOW_TYPE_FIRE && dens_flow > density[index]) {
/* Use MAX2 to preserve values from other emitters at this cell. */
/* Use std::max to preserve values from other emitters at this cell. */
density_in[index] = std::max(dens_flow, density_in[index]);
}
}
if (fuel && fuel_in) {
if (ffs->type != FLUID_FLOW_TYPE_SMOKE && fuel_flow && fuel_flow > fuel[index]) {
/* Use MAX2 to preserve values from other emitters at this cell. */
/* Use std::max to preserve values from other emitters at this cell. */
fuel_in[index] = std::max(fuel_flow, fuel_in[index]);
}
}
@ -3130,7 +3130,7 @@ static void update_effectors_task_cb(void *__restrict userdata,
float voxel_center[3] = {0, 0, 0}, vel[3] = {0, 0, 0}, retvel[3] = {0, 0, 0};
const uint index = manta_get_index(x, fds->res[0], y, fds->res[1], z);
if ((data->fuel && MAX2(data->density[index], data->fuel[index]) < FLT_EPSILON) ||
if ((data->fuel && std::max(data->density[index], data->fuel[index]) < FLT_EPSILON) ||
(data->density && data->density[index] < FLT_EPSILON) ||
(data->phi_obs_in && data->phi_obs_in[index] < 0.0f) ||
data->flags[index] & 2) /* Manta-flow convention: `2 == FlagObstacle`. */
@ -3276,7 +3276,7 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
sub_v3_v3v3(size, max, min);
/* Biggest dimension will be used for up-scaling. */
float max_size = MAX3(size[0], size[1], size[2]);
float max_size = std::max({size[0], size[1], size[2]});
float co_scale[3];
co_scale[0] = max_size / ob->scale[0];
@ -4379,8 +4379,8 @@ float BKE_fluid_get_velocity_at(Object *ob, float position[3], float velocity[3]
if (fmd && (fmd->type & MOD_FLUID_TYPE_DOMAIN) && fmd->domain && fmd->domain->fluid) {
FluidDomainSettings *fds = fmd->domain;
float time_mult = 25.0f * DT_DEFAULT;
float size_mult = MAX3(fds->global_size[0], fds->global_size[1], fds->global_size[2]) /
MAX3(fds->base_res[0], fds->base_res[1], fds->base_res[2]);
float size_mult = std::max({fds->global_size[0], fds->global_size[1], fds->global_size[2]}) /
std::max({fds->base_res[0], fds->base_res[1], fds->base_res[2]});
float vel_mag;
float density = 0.0f, fuel = 0.0f;
float pos[3];

View File

@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdio>
@ -1662,7 +1663,7 @@ float BKE_gpencil_stroke_segment_length(const bGPDstroke *gps,
return 0.0f;
}
int index = MAX2(start_index, 0) + 1;
int index = std::max(start_index, 0) + 1;
int last_index = std::min(end_index, gps->totpoints - 1) + 1;
float *last_pt = &gps->points[index - 1].x;
@ -1804,7 +1805,7 @@ bool BKE_gpencil_stroke_close(bGPDstroke *gps)
}
/* Calc number of points required using the average distance. */
int tot_newpoints = MAX2(dist_close / dist_avg, 1);
int tot_newpoints = std::max<int>(dist_close / dist_avg, 1);
/* Resize stroke array. */
int old_tot = gps->totpoints;
@ -2531,7 +2532,7 @@ static void gpencil_generate_edgeloops(Object *ob,
/* Create Stroke. */
bGPDstroke *gps_stroke = BKE_gpencil_stroke_add(
gpf_stroke, MAX2(stroke_mat_index, 0), array_len + 1, thickness * thickness, false);
gpf_stroke, std::max(stroke_mat_index, 0), array_len + 1, thickness * thickness, false);
/* Create dvert data. */
if (use_vgroups && !dverts.is_empty()) {
@ -3710,7 +3711,7 @@ void BKE_gpencil_stroke_uniform_subdivide(bGPdata *gpd,
(float *)&sp_next->vertex_color,
0.5f);
if (sp->dw && sp_next->dw) {
new_sp->totweight = MIN2(sp->totweight, sp_next->totweight);
new_sp->totweight = std::min(sp->totweight, sp_next->totweight);
new_sp->dw = (MDeformWeight *)MEM_callocN(sizeof(MDeformWeight) * new_sp->totweight,
__func__);
for (uint32_t i = 0; i < new_sp->totweight; ++i) {

View File

@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <algorithm>
#include <cstdio>
#include "MEM_guardedalloc.h"
@ -227,12 +228,13 @@ GpencilLineartLimitInfo BKE_gpencil_get_lineart_modifier_limits(const Object *ob
if (md->type == eGpencilModifierType_Lineart) {
LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
if (is_first || (lmd->flags & LRT_GPENCIL_USE_CACHE)) {
info.min_level = MIN2(info.min_level, lmd->level_start);
info.max_level = MAX2(info.max_level,
(lmd->use_multiple_levels ? lmd->level_end : lmd->level_start));
info.min_level = std::min<char>(info.min_level, lmd->level_start);
info.max_level = std::max<char>(
info.max_level, (lmd->use_multiple_levels ? lmd->level_end : lmd->level_start));
info.edge_types |= lmd->edge_types;
info.shadow_selection = MAX2(lmd->shadow_selection, info.shadow_selection);
info.silhouette_selection = MAX2(lmd->silhouette_selection, info.silhouette_selection);
info.shadow_selection = std::max<char>(lmd->shadow_selection, info.shadow_selection);
info.silhouette_selection = std::max<char>(lmd->silhouette_selection,
info.silhouette_selection);
is_first = false;
}
}

View File

@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <algorithm>
#include <cstdio>
#include <cstring>
@ -96,7 +97,7 @@ static void idp_repr_fn_recursive(ReprState *state, const IDProperty *prop)
switch (prop->type) {
case IDP_STRING: {
STR_APPEND_STR_LEN_QUOTE(IDP_String(prop), uint(MAX2(0, prop->len - 1)));
STR_APPEND_STR_LEN_QUOTE(IDP_String(prop), uint(std::max(0, prop->len - 1)));
break;
}
case IDP_INT: {

View File

@ -388,7 +388,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline,
max_delta_x /= max[0] - min[0];
max_delta_y /= max[1] - min[1];
max_delta = MAX2(max_delta_x, max_delta_y);
max_delta = std::max(max_delta_x, max_delta_y);
buckets_per_side = min_ii(512, 0.9f / max_delta);

View File

@ -358,11 +358,11 @@ void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lvl)
mmd->totlvl = lvl;
if (ob->mode != OB_MODE_SCULPT) {
mmd->lvl = CLAMPIS(MAX2(mmd->lvl, lvl), 0, mmd->totlvl);
mmd->lvl = CLAMPIS(std::max<char>(mmd->lvl, lvl), 0, mmd->totlvl);
}
mmd->sculptlvl = CLAMPIS(MAX2(mmd->sculptlvl, lvl), 0, mmd->totlvl);
mmd->renderlvl = CLAMPIS(MAX2(mmd->renderlvl, lvl), 0, mmd->totlvl);
mmd->sculptlvl = CLAMPIS(std::max<char>(mmd->sculptlvl, lvl), 0, mmd->totlvl);
mmd->renderlvl = CLAMPIS(std::max<char>(mmd->renderlvl, lvl), 0, mmd->totlvl);
}
static void multires_ccg_mark_as_modified(SubdivCCG *subdiv_ccg, MultiresModifiedFlags flags)

View File

@ -9,6 +9,7 @@
/* Allow using deprecated functionality for .blend file I/O. */
#define DNA_DEPRECATED_ALLOW
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
@ -2718,7 +2719,7 @@ static bool psys_thread_context_init_path(ParticleThreadContext *ctx,
totchild = int(float(totchild) * float(part->disp) / 100.0f);
}
totparent = MIN2(totparent, totchild);
totparent = std::min(totparent, totchild);
if (totchild == 0) {
return false;
@ -3356,7 +3357,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
copy_v3_v3(rotmat[2], hairmat[0]);
if (part->draw & PART_ABS_PATH_TIME) {
birthtime = MAX2(pind.birthtime, part->path_start);
birthtime = std::max(pind.birthtime, part->path_start);
dietime = std::min(pind.dietime, part->path_end);
}
else {

View File

@ -127,7 +127,7 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
size[(axis + 2) % 3] = int(ceil(delta[(axis + 2) % 3] / d));
/* float errors grrr. */
size[(axis + 1) % 3] = MIN2(size[(axis + 1) % 3], res);
size[(axis + 1) % 3] = std::min(size[(axis + 1) % 3], res);
size[(axis + 2) % 3] = std::min(size[(axis + 2) % 3], res);
size[0] = std::max(size[0], 1);
@ -1122,7 +1122,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx,
maxweight /= totarea;
}
else {
float min = 1.0f / float(MIN2(totelem, totpart));
float min = 1.0f / float(std::min(totelem, totpart));
for (i = 0; i < totelem; i++) {
element_weight[i] = min;
}

View File

@ -9,6 +9,7 @@
#include <cstddef>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
@ -232,7 +233,7 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
}
if (psys->particles) {
totsaved = MIN2(psys->totpart, totpart);
totsaved = std::min(psys->totpart, totpart);
/* Save old pars. */
if (totsaved) {
memcpy(newpars, psys->particles, totsaved * sizeof(ParticleData));
@ -4404,7 +4405,8 @@ static void particles_fluid_step(ParticleSimulationData *sim,
sub_v3_v3v3(size, max, min);
/* Biggest dimension will be used for up-scaling. */
max_size = MAX3(size[0] / float(upres), size[1] / float(upres), size[2] / float(upres));
max_size = std::max(
{size[0] / float(upres), size[1] / float(upres), size[2] / float(upres)});
/* Set particle position. */
const float posParticle[3] = {posX, posY, posZ};

View File

@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@ -408,7 +409,7 @@ static void ptcache_particle_interpolate(int index,
return;
}
cfra = MIN2(cfra, pa->dietime);
cfra = std::min(cfra, pa->dietime);
cfra1 = std::min(cfra1, pa->dietime);
cfra2 = std::min(cfra2, pa->dietime);
@ -442,7 +443,7 @@ static void ptcache_particle_interpolate(int index,
}
if (cfra > pa->time) {
cfra1 = MAX2(cfra1, pa->time);
cfra1 = std::max(cfra1, pa->time);
}
dfra = cfra2 - cfra1;
@ -2194,7 +2195,7 @@ static int ptcache_read(PTCacheID *pid, int cfra)
if (totpoint != pid_totpoint) {
pid->error(pid->owner_id, pid->calldata, "Number of points in cache does not match mesh");
totpoint = MIN2(totpoint, pid_totpoint);
totpoint = std::min(totpoint, pid_totpoint);
}
}
@ -2251,7 +2252,7 @@ static int ptcache_interpolate(PTCacheID *pid, float cfra, int cfra1, int cfra2)
if (totpoint != pid_totpoint) {
pid->error(pid->owner_id, pid->calldata, "Number of points in cache does not match mesh");
totpoint = MIN2(totpoint, pid_totpoint);
totpoint = std::min(totpoint, pid_totpoint);
}
}
@ -3227,7 +3228,7 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
cache->flag |= PTCACHE_BAKING;
}
else {
endframe = MIN2(endframe, cache->endframe);
endframe = std::min(endframe, cache->endframe);
}
cache->flag &= ~PTCACHE_BAKED;
@ -3267,13 +3268,13 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
}
startframe = MIN2(startframe, cache->startframe);
startframe = std::min(startframe, cache->startframe);
if (bake || render) {
cache->flag |= PTCACHE_BAKING;
if (bake) {
endframe = MAX2(endframe, cache->endframe);
endframe = std::max(endframe, cache->endframe);
}
}

View File

@ -7,6 +7,7 @@
* \brief Blender-side interface and methods for dealing with Rigid Body simulations
*/
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
@ -505,7 +506,7 @@ static rbCollisionShape *rigidbody_validate_sim_shape_helper(RigidBodyWorld *rbw
}
else if (rbo->shape == RB_SHAPE_SPHERE) {
/* take radius to the largest dimension to try and encompass everything */
radius = MAX3(size[0], size[1], size[2]);
radius = std::max({size[0], size[1], size[2]});
}
/* create new shape */
@ -531,7 +532,7 @@ static rbCollisionShape *rigidbody_validate_sim_shape_helper(RigidBodyWorld *rbw
case RB_SHAPE_CONVEXH:
/* try to embed collision margin */
has_volume = (MIN3(size[0], size[1], size[2]) > 0.0f);
has_volume = (std::min({size[0], size[1], size[2]}) > 0.0f);
if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && has_volume) {
hull_margin = 0.04f;
@ -636,7 +637,7 @@ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
if (ELEM(rbo->shape, RB_SHAPE_CAPSULE, RB_SHAPE_CYLINDER, RB_SHAPE_CONE)) {
/* take radius as largest x/y dimension, and height as z-dimension */
radius = MAX2(size[0], size[1]) * 0.5f;
radius = std::max(size[0], size[1]) * 0.5f;
height = size[2];
}
else if (rbo->shape == RB_SHAPE_SPHERE) {
@ -1790,7 +1791,8 @@ static void rigidbody_update_sim_ob(Depsgraph *depsgraph, Object *ob, RigidBodyO
/* compensate for embedded convex hull collision margin */
if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && rbo->shape == RB_SHAPE_CONVEXH) {
RB_shape_set_margin(static_cast<rbCollisionShape *>(rbo->shared->physics_shape),
RBO_GET_MARGIN(rbo) * MIN3(new_scale[0], new_scale[1], new_scale[2]));
RBO_GET_MARGIN(rbo) *
std::min({new_scale[0], new_scale[1], new_scale[2]}));
}
}
}
@ -2026,7 +2028,7 @@ static void rigidbody_update_kinematic_obj_substep(ListBase *substep_targets, fl
/* compensate for embedded convex hull collision margin */
if (!(rbo->flag & RBO_FLAG_USE_MARGIN) && rbo->shape == RB_SHAPE_CONVEXH) {
RB_shape_set_margin(static_cast<rbCollisionShape *>(rbo->shared->physics_shape),
RBO_GET_MARGIN(rbo) * MIN3(scale[0], scale[1], scale[2]));
RBO_GET_MARGIN(rbo) * std::min({scale[0], scale[1], scale[2]}));
}
}
}

View File

@ -994,7 +994,7 @@ static bool seq_foreach_path_callback(Sequence *seq, void *user_data)
if (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE) {
/* only operate on one path */
len = MIN2(1u, len);
len = std::min(1u, len);
}
for (i = 0; i < len; i++, se++) {

View File

@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
@ -1131,7 +1132,7 @@ static bool vfont_to_curve(Object *ob,
current_line_length += twidth;
}
else {
longest_line_length = MAX2(current_line_length, longest_line_length);
longest_line_length = std::max(current_line_length, longest_line_length);
current_line_length = 0.0f;
}
@ -1190,7 +1191,7 @@ static bool vfont_to_curve(Object *ob,
}
current_line_length += xof + twidth - MARGIN_X_MIN;
longest_line_length = MAX2(current_line_length, longest_line_length);
longest_line_length = std::max(current_line_length, longest_line_length);
cu->lines = 1;
for (i = 0; i <= slen; i++) {

View File

@ -142,8 +142,8 @@ using IndexMaskSegment = OffsetSpan<int64_t, int16_t>;
* various sources. Those generally need additional memory which is provided with by an
* #IndexMaskMemory.
*
* Some of the `IndexMask::from_*` functions are have an `IndexMask universe` input. When
* provided, the function will only consider the indices in the "universe". The term comes from
* Some of the `IndexMask::from_*` functions have an `IndexMask universe` input. When provided,
* the function will only consider the indices in the "universe". The term comes from
* mathematics: https://en.wikipedia.org/wiki/Universe_(mathematics).
*
* Iteration:
@ -472,7 +472,7 @@ inline void init_empty_mask(IndexMaskData &data)
data.indices_num_ = 0;
data.segments_num_ = 0;
data.cumulative_segment_sizes_ = cumulative_sizes_for_empty_mask;
/* Intentionally leave some pointer uninitialized which must not be accessed on empty masks
/* Intentionally leave some pointers uninitialized which must not be accessed on empty masks
* anyway. */
}

View File

@ -32,76 +32,9 @@ extern "C" {
/** \name Min/Max Macros
* \{ */
/* useful for finding bad use of min/max */
#if 0
/* gcc only */
# define _TYPECHECK(a, b) ((void)(((typeof(a) *)0) == ((typeof(b) *)0)))
# define MIN2(x, y) (_TYPECHECK(x, y), (((x) < (y) ? (x) : (y))))
# define MAX2(x, y) (_TYPECHECK(x, y), (((x) > (y) ? (x) : (y))))
#endif
/* min/max */
#if defined(__GNUC__) || defined(__clang__)
# define MIN2(a, b) \
__extension__({ \
typeof(a) a_ = (a); \
typeof(b) b_ = (b); \
((a_) < (b_) ? (a_) : (b_)); \
})
# define MAX2(a, b) \
__extension__({ \
typeof(a) a_ = (a); \
typeof(b) b_ = (b); \
((a_) > (b_) ? (a_) : (b_)); \
})
# define MIN3(a, b, c) \
__extension__({ \
typeof(a) a_ = (a); \
typeof(b) b_ = (b); \
typeof(c) c_ = (c); \
((a_ < b_) ? ((a_ < c_) ? a_ : c_) : ((b_ < c_) ? b_ : c_)); \
})
# define MAX3(a, b, c) \
__extension__({ \
typeof(a) a_ = (a); \
typeof(b) b_ = (b); \
typeof(c) c_ = (c); \
((a_ > b_) ? ((a_ > c_) ? a_ : c_) : ((b_ > c_) ? b_ : c_)); \
})
# define MIN4(a, b, c, d) \
__extension__({ \
typeof(a) a_ = (a); \
typeof(b) b_ = (b); \
typeof(c) c_ = (c); \
typeof(d) d_ = (d); \
((a_ < b_) ? ((a_ < c_) ? ((a_ < d_) ? a_ : d_) : ((c_ < d_) ? c_ : d_)) : \
((b_ < c_) ? ((b_ < d_) ? b_ : d_) : ((c_ < d_) ? c_ : d_))); \
})
# define MAX4(a, b, c, d) \
__extension__({ \
typeof(a) a_ = (a); \
typeof(b) b_ = (b); \
typeof(c) c_ = (c); \
typeof(d) d_ = (d); \
((a_ > b_) ? ((a_ > c_) ? ((a_ > d_) ? a_ : d_) : ((c_ > d_) ? c_ : d_)) : \
((b_ > c_) ? ((b_ > d_) ? b_ : d_) : ((c_ > d_) ? c_ : d_))); \
})
#else
#ifndef __cplusplus
# define MIN2(a, b) ((a) < (b) ? (a) : (b))
# define MAX2(a, b) ((a) > (b) ? (a) : (b))
# define MIN3(a, b, c) (MIN2(MIN2((a), (b)), (c)))
# define MIN4(a, b, c, d) (MIN2(MIN2((a), (b)), MIN2((c), (d))))
# define MAX3(a, b, c) (MAX2(MAX2((a), (b)), (c)))
# define MAX4(a, b, c, d) (MAX2(MAX2((a), (b)), MAX2((c), (d))))
#endif
#define INIT_MINMAX(min, max) \

View File

@ -87,6 +87,7 @@
* Otherwise new chunks are created.
*/
#include <algorithm>
#include <cstdlib>
#include <cstring>
@ -158,11 +159,11 @@ struct BChunkList;
# define BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_32BITS 4
# define BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_16BITS 5
/**
* Singe bytes (or boolean) arrays need a higher number of steps
* Single bytes (or boolean) arrays need a higher number of steps
* because the resulting values are not unique enough to result in evenly distributed values.
* Use more accumulation when the size of the structs is small, see: #105046.
*
* With 6 -> 22, one byte each - means an array of booleans can be combine into 22 bits
* With 6 -> 22, one byte each - means an array of booleans can be combined into 22 bits
* representing 4,194,303 different combinations.
*/
# define BCHUNK_HASH_TABLE_ACCUMULATE_STEPS_8BITS 6
@ -479,7 +480,7 @@ static void bchunk_list_ensure_min_size_last(const BArrayInfo *info,
BChunk *chunk_curr = cref->link;
BChunk *chunk_prev = cref->prev->link;
if (MIN2(chunk_prev->data_len, chunk_curr->data_len) < info->chunk_byte_size_min) {
if (std::min(chunk_prev->data_len, chunk_curr->data_len) < info->chunk_byte_size_min) {
const size_t data_merge_len = chunk_prev->data_len + chunk_curr->data_len;
/* We could pass, but no need. */
if (data_merge_len <= info->chunk_byte_size_max) {
@ -632,7 +633,7 @@ static void bchunk_list_append_data(const BArrayInfo *info,
BChunkRef *cref = static_cast<BChunkRef *>(chunk_list->chunk_refs.last);
BChunk *chunk_prev = cref->link;
if (MIN2(chunk_prev->data_len, data_len) < info->chunk_byte_size_min) {
if (std::min(chunk_prev->data_len, data_len) < info->chunk_byte_size_min) {
const size_t data_merge_len = chunk_prev->data_len + data_len;
/* Re-allocate for single user. */
if (cref->link->users == 1) {
@ -1004,7 +1005,7 @@ static hash_key key_from_chunk_ref(const BArrayInfo *info, const BChunkRef *cref
{
hash_key key;
BChunk *chunk = cref->link;
const size_t data_hash_len = MIN2(chunk->data_len, BCHUNK_HASH_LEN * info->chunk_stride);
const size_t data_hash_len = std::min(chunk->data_len, BCHUNK_HASH_LEN * info->chunk_stride);
# ifdef USE_HASH_TABLE_KEY_CACHE
key = chunk->key;
@ -1039,7 +1040,7 @@ static const BChunkRef *table_lookup(const BArrayInfo *info,
const size_t data_hash_len = BCHUNK_HASH_LEN * info->chunk_stride; /* TODO: cache. */
const size_t size_left = data_len - offset;
const hash_key key = hash_data(&data[offset], MIN2(data_hash_len, size_left));
const hash_key key = hash_data(&data[offset], std::min(data_hash_len, size_left));
const uint key_index = (uint)(key % (hash_key)table_len);
for (BTableRef *tref = table[key_index]; tref; tref = tref->next) {
const BChunkRef *cref = tref->cref;
@ -1501,7 +1502,7 @@ BArrayStore *BLI_array_store_create(uint stride, uint chunk_count)
bs->info.chunk_byte_size = chunk_count * stride;
#ifdef USE_MERGE_CHUNKS
bs->info.chunk_byte_size_min = MAX2(1u, chunk_count / BCHUNK_SIZE_MIN_DIV) * stride;
bs->info.chunk_byte_size_min = std::max(1u, chunk_count / BCHUNK_SIZE_MIN_DIV) * stride;
bs->info.chunk_byte_size_max = (chunk_count * BCHUNK_SIZE_MAX_MUL) * stride;
#endif
@ -1531,7 +1532,7 @@ BArrayStore *BLI_array_store_create(uint stride, uint chunk_count)
bs->info.accum_read_ahead_bytes = bs->info.accum_read_ahead_len * stride;
#else
bs->info.accum_read_ahead_bytes = MIN2((size_t)BCHUNK_HASH_LEN, chunk_count) * stride;
bs->info.accum_read_ahead_bytes = std::min((size_t)BCHUNK_HASH_LEN, chunk_count) * stride;
#endif
bs->memory.chunk_list = BLI_mempool_create(sizeof(BChunkList), 0, 512, BLI_MEMPOOL_NOP);

View File

@ -6,6 +6,7 @@
* \ingroup bli
*/
#include <algorithm>
#include <cstdlib> /* malloc */
#include <cstring>
@ -106,7 +107,7 @@ int64_t BLI_read(int fd, void *buf, size_t nbytes)
buf,
#ifdef WIN32
/* Read must not exceed INT_MAX on WIN32, clamp. */
MIN2(nbytes, INT_MAX)
std::min<size_t>(nbytes, INT_MAX)
#else
nbytes
#endif

View File

@ -37,7 +37,7 @@ MINLINE float safe_logf(float a, float base)
MINLINE float safe_sqrtf(float a)
{
return sqrtf(MAX2(a, 0.0f));
return sqrtf(max_ff(a, 0.0f));
}
MINLINE float safe_inverse_sqrtf(float a)

View File

@ -104,7 +104,7 @@ int BLI_path_sequence_decode(const char *path,
BLI_strncpy(tail, &path[nume + 1], tail_maxncpy);
}
if (head) {
BLI_strncpy(head, path, MIN2(head_maxncpy, nums + 1));
BLI_strncpy(head, path, std::min<size_t>(head_maxncpy, nums + 1));
}
if (r_digits_len) {
*r_digits_len = nume - nums + 1;
@ -119,7 +119,7 @@ int BLI_path_sequence_decode(const char *path,
if (head) {
/* Name_end points to last character of head,
* make it +1 so null-terminator is nicely placed. */
BLI_strncpy(head, path, MIN2(head_maxncpy, name_end + 1));
BLI_strncpy(head, path, std::min<size_t>(head_maxncpy, name_end + 1));
}
if (r_digits_len) {
*r_digits_len = 0;

View File

@ -10,6 +10,7 @@
* \ingroup bli
*/
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@ -1069,7 +1070,7 @@ int BLI_str_utf8_offset_from_index(const char *str, const size_t str_len, const
int BLI_str_utf8_offset_to_column(const char *str, const size_t str_len, const int offset_target)
{
BLI_assert(offset_target >= 0);
const size_t offset_target_clamp = MIN2(size_t(offset_target), str_len);
const size_t offset_target_clamp = std::min(size_t(offset_target), str_len);
size_t offset = 0;
int column = 0;
while (offset < offset_target_clamp) {
@ -1101,7 +1102,7 @@ int BLI_str_utf8_offset_to_column_with_tabs(const char *str,
const int tab_width)
{
BLI_assert(offset_target >= 0);
const size_t offset_target_clamp = MIN2(size_t(offset_target), str_len);
const size_t offset_target_clamp = std::min(size_t(offset_target), str_len);
size_t offset = 0;
int column = 0;
while (offset < offset_target_clamp) {

View File

@ -53,7 +53,7 @@ TEST(string, StrCopyUTF8_ASCII_Truncate)
char dst[sizeof(src)]; \
memset(dst, 0xff, sizeof(dst)); \
BLI_strncpy_utf8(dst, src, maxncpy); \
int len_expect = MIN2(sizeof(src), maxncpy) - 1; \
int len_expect = std::min<int>(sizeof(src), maxncpy) - 1; \
src[len_expect] = '\0'; /* To be able to use `EXPECT_STREQ`. */ \
EXPECT_EQ(strlen(dst), len_expect); \
EXPECT_STREQ(dst, src); \

View File

@ -698,7 +698,7 @@ static BHeadN *get_bhead(FileData *fd)
bh8_from_bh4(&bhead, &bhead4);
}
else {
/* MIN2 is only to quiet '-Warray-bounds' compiler warning. */
/* std::min is only to quiet '-Warray-bounds' compiler warning. */
BLI_assert(sizeof(bhead) == sizeof(bhead4));
memcpy(&bhead, &bhead4, std::min(sizeof(bhead), sizeof(bhead4)));
}
@ -721,7 +721,7 @@ static BHeadN *get_bhead(FileData *fd)
bh4_from_bh8(&bhead, &bhead8, (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0);
}
else {
/* MIN2 is only to quiet `-Warray-bounds` compiler warning. */
/* std::min is only to quiet `-Warray-bounds` compiler warning. */
BLI_assert(sizeof(bhead) == sizeof(bhead8));
memcpy(&bhead, &bhead8, std::min(sizeof(bhead), sizeof(bhead8)));
}

View File

@ -9,6 +9,7 @@
/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW
#include <algorithm>
#include <cfloat>
#include <cstring>
@ -3312,8 +3313,8 @@ void blo_do_versions_280(FileData *fd, Library * /*lib*/, Main *bmain)
/* Calculate window width/height from screen vertices */
int win_width = 0, win_height = 0;
LISTBASE_FOREACH (ScrVert *, vert, &screen->vertbase) {
win_width = MAX2(win_width, vert->vec.x);
win_height = MAX2(win_height, vert->vec.y);
win_width = std::max<int>(win_width, vert->vec.x);
win_height = std::max<int>(win_height, vert->vec.y);
}
for (ScrArea *area = static_cast<ScrArea *>(screen->areabase.first), *area_next; area;

View File

@ -8,6 +8,8 @@
/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW
#include <algorithm>
#include "BLI_listbase.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
@ -227,8 +229,8 @@ static void seq_convert_transform_crop(const Scene *scene,
old_image_center_y = image_size_y / 2 - c->bottom + t->yofs;
/* Preserve original image size. */
t->scale_x = t->scale_y = MAX2(float(image_size_x) / float(scene->r.xsch),
float(image_size_y) / float(scene->r.ysch));
t->scale_x = t->scale_y = std::max(float(image_size_x) / float(scene->r.xsch),
float(image_size_y) / float(scene->r.ysch));
/* Convert crop. */
if ((seq->flag & use_crop_flag) != 0) {
@ -311,8 +313,8 @@ static void seq_convert_transform_crop_2(const Scene *scene,
}
/* Calculate scale factor, so image fits in preview area with original aspect ratio. */
const float scale_to_fit_factor = MIN2(float(scene->r.xsch) / float(image_size_x),
float(scene->r.ysch) / float(image_size_y));
const float scale_to_fit_factor = std::min(float(scene->r.xsch) / float(image_size_x),
float(scene->r.ysch) / float(image_size_y));
t->scale_x *= scale_to_fit_factor;
t->scale_y *= scale_to_fit_factor;
c->top /= scale_to_fit_factor;

View File

@ -6,6 +6,7 @@
* \ingroup blenloader
*/
#include <algorithm>
#include <climits>
#ifndef WIN32
@ -1323,8 +1324,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain)
SubsurfModifierData *smd = (SubsurfModifierData *)BKE_modifier_new(
eModifierType_Subsurf);
smd->levels = MAX2(1, mesh->subdiv);
smd->renderLevels = MAX2(1, mesh->subdivr);
smd->levels = std::max<short>(1, mesh->subdiv);
smd->renderLevels = std::max<short>(1, mesh->subdivr);
smd->subdivType = mesh->subsurftype;
smd->modifier.mode = 0;

View File

@ -438,8 +438,8 @@ inline void ExecutionGroup::determine_chunk_rect(rcti *r_rect,
else {
const uint minx = x_chunk * chunk_size_ + viewer_border_.xmin;
const uint miny = y_chunk * chunk_size_ + viewer_border_.ymin;
const uint width = MIN2(uint(viewer_border_.xmax), width_);
const uint height = MIN2(uint(viewer_border_.ymax), height_);
const uint width = std::min(uint(viewer_border_.xmax), width_);
const uint height = std::min(uint(viewer_border_.ymax), height_);
BLI_rcti_init(r_rect,
std::min(minx, width_),
std::min(minx + chunk_size_, width),

View File

@ -407,8 +407,8 @@ void MemoryBuffer::fill(const rcti &area,
void MemoryBuffer::fill_from(const MemoryBuffer &src)
{
rcti overlap;
overlap.xmin = MAX2(rect_.xmin, src.rect_.xmin);
overlap.xmax = MIN2(rect_.xmax, src.rect_.xmax);
overlap.xmin = std::max(rect_.xmin, src.rect_.xmin);
overlap.xmax = std::min(rect_.xmax, src.rect_.xmax);
overlap.ymin = std::max(rect_.ymin, src.rect_.ymin);
overlap.ymax = std::min(rect_.ymax, src.rect_.ymax);
copy_from(&src, overlap);

View File

@ -106,8 +106,8 @@ void BokehBlurOperation::execute_pixel(float output[4], int x, int y, void *data
int maxx = x + pixel_size;
miny = std::max(miny, input_rect.ymin);
minx = std::max(minx, input_rect.xmin);
maxy = MIN2(maxy, input_rect.ymax);
maxx = MIN2(maxx, input_rect.xmax);
maxy = std::min(maxy, input_rect.ymax);
maxx = std::min(maxx, input_rect.xmax);
int step = get_step();
int offsetadd = get_offset_add() * COM_DATA_TYPE_COLOR_CHANNELS;
@ -340,9 +340,9 @@ void BokehBlurOperation::update_memory_buffer_partial(MemoryBuffer *output,
multiplier_accum[3] = 1.0f;
}
const int miny = std::max(y - pixel_size, image_rect.ymin);
const int maxy = MIN2(y + pixel_size, image_rect.ymax);
const int maxy = std::min(y + pixel_size, image_rect.ymax);
const int minx = std::max(x - pixel_size, image_rect.xmin);
const int maxx = MIN2(x + pixel_size, image_rect.xmax);
const int maxx = std::min(x + pixel_size, image_rect.xmax);
const int step = get_step();
const int elem_stride = image_input->elem_stride * step;
const int row_stride = image_input->row_stride * step;

View File

@ -34,8 +34,8 @@ void BoxMaskOperation::execute_pixel_sampled(float output[4],
float input_mask[4];
float input_value[4];
float rx = x / MAX2(this->get_width() - 1.0f, FLT_EPSILON);
float ry = y / MAX2(this->get_height() - 1.0f, FLT_EPSILON);
float rx = x / std::max(this->get_width() - 1.0f, FLT_EPSILON);
float ry = y / std::max(this->get_height() - 1.0f, FLT_EPSILON);
const float dy = (ry - data_->y) / aspect_ratio_;
const float dx = rx - data_->x;
@ -130,8 +130,8 @@ void BoxMaskOperation::apply_mask(MemoryBuffer *output,
Span<MemoryBuffer *> inputs,
MaskFunc mask_func)
{
const float op_last_x = MAX2(this->get_width() - 1.0f, FLT_EPSILON);
const float op_last_y = MAX2(this->get_height() - 1.0f, FLT_EPSILON);
const float op_last_x = std::max(this->get_width() - 1.0f, FLT_EPSILON);
const float op_last_y = std::max(this->get_height() - 1.0f, FLT_EPSILON);
const float half_w = data_->width / 2.0f + FLT_EPSILON;
const float half_h = data_->height / 2.0f + FLT_EPSILON;
for (BuffersIterator<float> it = output->iterate_with(inputs, area); !it.is_end(); ++it) {

View File

@ -115,7 +115,7 @@ void ChannelMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
const float *color = it.in(0);
/* Matte operation. */
float alpha = color[ids_[0]] - MAX2(color[ids_[1]], color[ids_[2]]);
float alpha = color[ids_[0]] - std::max(color[ids_[1]], color[ids_[2]]);
/* Flip because 0.0 is transparent, not 1.0. */
alpha = 1.0f - alpha;
@ -136,7 +136,7 @@ void ChannelMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
*/
/* Don't make something that was more transparent less transparent. */
*it.out = MIN2(alpha, color[3]);
*it.out = std::min(alpha, color[3]);
}
}

View File

@ -27,12 +27,12 @@ class ChannelMatteOperation : public MultiThreadedOperation {
/**
* ids to use for the operations (max and simple)
* alpha = in[ids[0]] - MAX2(in[ids[1]], in[ids[2]])
* alpha = in[ids[0]] - std::max(in[ids[1]], in[ids[2]])
* the simple operation is using:
* alpha = in[ids[0]] - in[ids[1]]
* but to use the same formula and operation for both we do:
* ids[2] = ids[1]
* alpha = in[ids[0]] - MAX2(in[ids[1]], in[ids[2]])
* alpha = in[ids[0]] - std::max(in[ids[1]], in[ids[2]])
*/
int ids_[3];

View File

@ -47,7 +47,7 @@ void ColorBalanceASCCDLOperation::execute_pixel_sampled(float output[4],
input_color_operation_->read_sampled(input_color, x, y, sampler);
float fac = value[0];
fac = MIN2(1.0f, fac);
fac = std::min(1.0f, fac);
const float mfac = 1.0f - fac;
output[0] = mfac * input_color[0] +
@ -64,7 +64,7 @@ void ColorBalanceASCCDLOperation::update_memory_buffer_row(PixelCursor &p)
for (; p.out < p.row_end; p.next()) {
const float *in_factor = p.ins[0];
const float *in_color = p.ins[1];
const float fac = MIN2(1.0f, in_factor[0]);
const float fac = std::min(1.0f, in_factor[0]);
const float fac_m = 1.0f - fac;
p.out[0] = fac_m * in_color[0] +
fac * colorbalance_cdl(in_color[0], offset_[0], power_[0], slope_[0]);

View File

@ -71,7 +71,7 @@ void ColorBalanceLGGOperation::update_memory_buffer_row(PixelCursor &p)
for (; p.out < p.row_end; p.next()) {
const float *in_factor = p.ins[0];
const float *in_color = p.ins[1];
const float fac = MIN2(1.0f, in_factor[0]);
const float fac = std::min(1.0f, in_factor[0]);
const float fac_m = 1.0f - fac;
p.out[0] = fac_m * in_color[0] +
fac * colorbalance_lgg(in_color[0], lift_[0], gamma_inv_[0], gain_[0]);

View File

@ -54,7 +54,7 @@ void ColorCorrectionOperation::execute_pixel_sampled(float output[4],
float r, g, b;
float value = input_mask[0];
value = MIN2(1.0f, value);
value = std::min(1.0f, value);
const float mvalue = 1.0f - value;
float level_shadows = 0.0;
@ -204,7 +204,7 @@ void ColorCorrectionOperation::update_memory_buffer_row(PixelCursor &p)
b = color_correct_powf_safe(b * gain + lift, inv_gamma, b);
/* Mix with mask. */
const float value = MIN2(1.0f, in_mask[0]);
const float value = std::min(1.0f, in_mask[0]);
const float value_ = 1.0f - value;
r = value_ * in_color[0] + value * r;
g = value_ * in_color[1] + value * g;

View File

@ -74,10 +74,10 @@ void ConvolutionEdgeFilterOperation::execute_pixel(float output[4], int x, int y
output[3] = in2[3];
/* Make sure we don't return negative color. */
output[0] = MAX2(output[0], 0.0f);
output[1] = MAX2(output[1], 0.0f);
output[2] = MAX2(output[2], 0.0f);
output[3] = MAX2(output[3], 0.0f);
output[0] = std::max(output[0], 0.0f);
output[1] = std::max(output[1], 0.0f);
output[2] = std::max(output[2], 0.0f);
output[3] = std::max(output[3], 0.0f);
}
void ConvolutionEdgeFilterOperation::update_memory_buffer_partial(MemoryBuffer *output,

View File

@ -90,10 +90,10 @@ void ConvolutionFilterOperation::execute_pixel(float output[4], int x, int y, vo
output[3] = output[3] * value[0] + in2[3] * mval;
/* Make sure we don't return negative color. */
output[0] = MAX2(output[0], 0.0f);
output[1] = MAX2(output[1], 0.0f);
output[2] = MAX2(output[2], 0.0f);
output[3] = MAX2(output[3], 0.0f);
output[0] = std::max(output[0], 0.0f);
output[1] = std::max(output[1], 0.0f);
output[2] = std::max(output[2], 0.0f);
output[3] = std::max(output[3], 0.0f);
}
bool ConvolutionFilterOperation::determine_depending_area_of_interest(

View File

@ -34,8 +34,8 @@ void EllipseMaskOperation::execute_pixel_sampled(float output[4],
float input_mask[4];
float input_value[4];
float rx = x / MAX2(this->get_width() - 1.0f, FLT_EPSILON);
float ry = y / MAX2(this->get_height() - 1.0f, FLT_EPSILON);
float rx = x / std::max(this->get_width() - 1.0f, FLT_EPSILON);
float ry = y / std::max(this->get_height() - 1.0f, FLT_EPSILON);
const float dy = (ry - data_->y) / aspect_ratio_;
const float dx = rx - data_->x;
@ -138,8 +138,8 @@ void EllipseMaskOperation::apply_mask(MemoryBuffer *output,
{
const MemoryBuffer *input_mask = inputs[0];
const MemoryBuffer *input_value = inputs[1];
const float op_last_x = MAX2(this->get_width() - 1.0f, FLT_EPSILON);
const float op_last_y = MAX2(this->get_height() - 1.0f, FLT_EPSILON);
const float op_last_x = std::max(this->get_width() - 1.0f, FLT_EPSILON);
const float op_last_y = std::max(this->get_height() - 1.0f, FLT_EPSILON);
const float half_w = data_->width / 2.0f;
const float half_h = data_->height / 2.0f;
const float tx = half_w * half_w;

View File

@ -44,9 +44,9 @@ void GlareThresholdOperation::execute_pixel_sampled(float output[4],
output[1] -= threshold;
output[2] -= threshold;
output[0] = MAX2(output[0], 0.0f);
output[1] = MAX2(output[1], 0.0f);
output[2] = MAX2(output[2], 0.0f);
output[0] = std::max(output[0], 0.0f);
output[1] = std::max(output[1], 0.0f);
output[2] = std::max(output[2], 0.0f);
}
else {
zero_v3(output);

View File

@ -42,7 +42,8 @@ void LuminanceMatteOperation::execute_pixel_sampled(float output[4],
float alpha;
/* one line thread-friend algorithm:
* output[0] = MIN2(input_value[3], MIN2(1.0f, MAX2(0.0f, ((luminance - low) / (high - low))));
* output[0] = std::min(input_value[3], std::min(1.0f, std::max(0.0f, ((luminance - low) / (high
* - low))));
*/
/* test range */
@ -73,7 +74,8 @@ void LuminanceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
const float luminance = IMB_colormanagement_get_luminance(color);
/* One line thread-friend algorithm:
* `it.out[0] = MIN2(color[3], MIN2(1.0f, MAX2(0.0f, ((luminance - low) / (high - low))));`
* `it.out[0] = std::min(color[3], std::min(1.0f, std::max(0.0f, ((luminance - low) / (high -
* low))));`
*/
/* Test range. */
@ -95,7 +97,7 @@ void LuminanceMatteOperation::update_memory_buffer_partial(MemoryBuffer *output,
*/
/* Don't make something that was more transparent less transparent. */
it.out[0] = MIN2(alpha, color[3]);
it.out[0] = std::min(alpha, color[3]);
}
}

View File

@ -83,7 +83,7 @@ class MaskOperation : public MultiThreadedOperation {
void set_motion_blur_samples(int samples)
{
raster_mask_handle_tot_ = MIN2(MAX2(1, samples), CMP_NODE_MASK_MBLUR_SAMPLES_MAX);
raster_mask_handle_tot_ = std::min(std::max(1, samples), CMP_NODE_MASK_MBLUR_SAMPLES_MAX);
}
void set_motion_blur_shutter(float shutter)
{

View File

@ -468,7 +468,7 @@ void MathMinimumOperation::execute_pixel_sampled(float output[4],
input_value1_operation_->read_sampled(input_value1, x, y, sampler);
input_value2_operation_->read_sampled(input_value2, x, y, sampler);
output[0] = MIN2(input_value1[0], input_value2[0]);
output[0] = std::min(input_value1[0], input_value2[0]);
clamp_if_needed(output);
}
@ -476,7 +476,7 @@ void MathMinimumOperation::execute_pixel_sampled(float output[4],
void MathMinimumOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
{
for (; !it.is_end(); ++it) {
*it.out = MIN2(*it.in(0), *it.in(1));
*it.out = std::min(*it.in(0), *it.in(1));
clamp_when_enabled(it.out);
}
}
@ -492,7 +492,7 @@ void MathMaximumOperation::execute_pixel_sampled(float output[4],
input_value1_operation_->read_sampled(input_value1, x, y, sampler);
input_value2_operation_->read_sampled(input_value2, x, y, sampler);
output[0] = MAX2(input_value1[0], input_value2[0]);
output[0] = std::max(input_value1[0], input_value2[0]);
clamp_if_needed(output);
}
@ -500,7 +500,7 @@ void MathMaximumOperation::execute_pixel_sampled(float output[4],
void MathMaximumOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
{
for (; !it.is_end(); ++it) {
*it.out = MAX2(*it.in(0), *it.in(1));
*it.out = std::max(*it.in(0), *it.in(1));
clamp_when_enabled(it.out);
}
}
@ -1007,7 +1007,7 @@ void MathCompareOperation::execute_pixel_sampled(float output[4],
void MathCompareOperation::update_memory_buffer_partial(BuffersIterator<float> &it)
{
for (; !it.is_end(); ++it) {
*it.out = (fabsf(*it.in(0) - *it.in(1)) <= MAX2(*it.in(2), 1e-5f)) ? 1.0f : 0.0f;
*it.out = (fabsf(*it.in(0) - *it.in(1)) <= std::max(*it.in(2), 1e-5f)) ? 1.0f : 0.0f;
clamp_when_enabled(it.out);
}
}

View File

@ -803,9 +803,9 @@ void MixGlareOperation::execute_pixel_sampled(float output[4],
input_weight = 1.0f - value;
glare_weight = 1.0f;
}
output[0] = input_weight * MAX2(input_color1[0], 0.0f) + glare_weight * input_color2[0];
output[1] = input_weight * MAX2(input_color1[1], 0.0f) + glare_weight * input_color2[1];
output[2] = input_weight * MAX2(input_color1[2], 0.0f) + glare_weight * input_color2[2];
output[0] = input_weight * std::max(input_color1[0], 0.0f) + glare_weight * input_color2[0];
output[1] = input_weight * std::max(input_color1[1], 0.0f) + glare_weight * input_color2[1];
output[2] = input_weight * std::max(input_color1[2], 0.0f) + glare_weight * input_color2[2];
output[3] = input_color1[3];
clamp_if_needed(output);
@ -828,9 +828,9 @@ void MixGlareOperation::update_memory_buffer_row(PixelCursor &p)
input_weight = 1.0f - value;
glare_weight = 1.0f;
}
p.out[0] = input_weight * MAX2(p.color1[0], 0.0f) + glare_weight * p.color2[0];
p.out[1] = input_weight * MAX2(p.color1[1], 0.0f) + glare_weight * p.color2[1];
p.out[2] = input_weight * MAX2(p.color1[2], 0.0f) + glare_weight * p.color2[2];
p.out[0] = input_weight * std::max(p.color1[0], 0.0f) + glare_weight * p.color2[0];
p.out[1] = input_weight * std::max(p.color1[1], 0.0f) + glare_weight * p.color2[1];
p.out[2] = input_weight * std::max(p.color1[2], 0.0f) + glare_weight * p.color2[2];
p.out[3] = p.color1[3];
clamp_if_needed(p.out);
@ -963,13 +963,13 @@ void MixLightenOperation::update_memory_buffer_row(PixelCursor &p)
}
float tmp = value * p.color2[0];
p.out[0] = MAX2(tmp, p.color1[0]);
p.out[0] = std::max(tmp, p.color1[0]);
tmp = value * p.color2[1];
p.out[1] = MAX2(tmp, p.color1[1]);
p.out[1] = std::max(tmp, p.color1[1]);
tmp = value * p.color2[2];
p.out[2] = MAX2(tmp, p.color1[2]);
p.out[2] = std::max(tmp, p.color1[2]);
p.out[3] = p.color1[3];

View File

@ -57,10 +57,10 @@ void RotateOperation::get_area_rotation_bounds(const rcti &area,
const float y2 = center_y + (sine * dxmax + cosine * dymin);
const float y3 = center_y + (sine * dxmin + cosine * dymax);
const float y4 = center_y + (sine * dxmax + cosine * dymax);
const float minx = MIN2(x1, MIN2(x2, MIN2(x3, x4)));
const float maxx = std::max(x1, MAX2(x2, std::max(x3, x4)));
const float miny = MIN2(y1, std::min(y2, MIN2(y3, y4)));
const float maxy = std::max(y1, MAX2(y2, std::max(y3, y4)));
const float minx = std::min(x1, std::min(x2, std::min(x3, x4)));
const float maxx = std::max(x1, std::max(x2, std::max(x3, x4)));
const float miny = std::min(y1, std::min(y2, std::min(y3, y4)));
const float maxy = std::max(y1, std::max(y2, std::max(y3, y4)));
r_bounds.xmin = floor(minx);
r_bounds.xmax = ceil(maxx);

View File

@ -54,14 +54,14 @@ class ScaleOperation : public BaseScaleOperation {
static float scale_coord(const float coord, const float center, const float relative_scale)
{
return center + (coord - center) * MAX2(relative_scale, MIN_RELATIVE_SCALE);
return center + (coord - center) * std::max(relative_scale, MIN_RELATIVE_SCALE);
}
static float scale_coord_inverted(const float coord,
const float center,
const float relative_scale)
{
return center + (coord - center) / MAX2(relative_scale, MIN_RELATIVE_SCALE);
return center + (coord - center) / std::max(relative_scale, MIN_RELATIVE_SCALE);
}
static void get_scale_offset(const rcti &input_canvas,

View File

@ -41,7 +41,7 @@ void TonemapOperation::execute_pixel(float output[4], int x, int y, void *data)
const float igm = avg->igm;
if (igm != 0.0f) {
output[0] = powf(std::max(output[0], 0.0f), igm);
output[1] = powf(MAX2(output[1], 0.0f), igm);
output[1] = powf(std::max(output[1], 0.0f), igm);
output[2] = powf(std::max(output[2], 0.0f), igm);
}
}
@ -115,7 +115,7 @@ void *TonemapOperation::initialize_tile_data(rcti *rect)
float L = IMB_colormanagement_get_luminance(bc);
Lav += L;
add_v3_v3(cav, bc);
lsum += logf(MAX2(L, 0.0f) + 1e-5f);
lsum += logf(std::max(L, 0.0f) + 1e-5f);
maxl = (L > maxl) ? L : maxl;
minl = (L < minl) ? L : minl;
bc += 4;
@ -164,9 +164,9 @@ static Luminance calc_area_luminance(const MemoryBuffer *input, const rcti &area
const float lu = IMB_colormanagement_get_luminance(elem);
lum.sum += lu;
add_v3_v3(lum.color_sum, elem);
lum.log_sum += logf(MAX2(lu, 0.0f) + 1e-5f);
lum.max = MAX2(lu, lum.max);
lum.min = MIN2(lu, lum.min);
lum.log_sum += logf(std::max(lu, 0.0f) + 1e-5f);
lum.max = std::max(lu, lum.max);
lum.min = std::min(lu, lum.min);
lum.num_pixels++;
}
return lum;
@ -235,8 +235,8 @@ void TonemapOperation::update_memory_buffer_partial(MemoryBuffer *output,
it.out[1] /= ((dg == 0.0f) ? 1.0f : dg);
it.out[2] /= ((db == 0.0f) ? 1.0f : db);
if (igm != 0.0f) {
it.out[0] = powf(MAX2(it.out[0], 0.0f), igm);
it.out[1] = powf(MAX2(it.out[1], 0.0f), igm);
it.out[0] = powf(std::max(it.out[0], 0.0f), igm);
it.out[1] = powf(std::max(it.out[1], 0.0f), igm);
it.out[2] = powf(std::max(it.out[2], 0.0f), igm);
}
}

View File

@ -906,7 +906,7 @@ void zbuf_accumulate_vecblur(NodeBlurData *nbd,
dz2[3] += bfac * dr->colpoin[3];
*rw += bfac;
*rm = MAX2(*rm, bfac);
*rm = std::max(*rm, bfac);
}
}
}

View File

@ -6,15 +6,13 @@
* \ingroup datatoc
*/
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
/* #define VERBOSE */
#define MAX2(x, y) ((x) > (y) ? (x) : (y))
#define MAX3(x, y, z) MAX2(MAX2((x), (y)), (z))
#define STRPREFIX(a, b) (strncmp((a), (b), strlen(b)) == 0)
static char *arg_basename(char *string)
@ -30,7 +28,7 @@ static char *arg_basename(char *string)
lfslash++;
}
return MAX3(string, lfslash, lbslash);
return std::max({string, lfslash, lbslash});
}
/**

View File

@ -1098,8 +1098,8 @@ static void compute_cell_id(EEVEE_LightGrid *egrid,
probe->grid_resolution_z;
/* Add one for level 0 */
int max_lvl = int(floorf(log2f(
float(MAX3(probe->grid_resolution_x, probe->grid_resolution_y, probe->grid_resolution_z)))));
int max_lvl = int(floorf(log2f(float(
std::max({probe->grid_resolution_x, probe->grid_resolution_y, probe->grid_resolution_z})))));
int visited_cells = 0;
*r_stride = 0;

View File

@ -6,6 +6,8 @@
* \ingroup draw
*/
#include <algorithm>
#include "BLI_listbase.h"
#include "BLI_rect.h"
#include "BLI_string.h"
@ -178,7 +180,7 @@ void DRW_stats_reset()
timer->time_average = timer->time_average * (1.0 - GPU_TIMER_FALLOFF) +
time * GPU_TIMER_FALLOFF;
timer->time_average = MIN2(timer->time_average, 1000000000);
timer->time_average = std::min(timer->time_average, uint64_t(1000000000));
}
else {
timer->time_average = lvl_time[timer->lvl + 1];

View File

@ -885,7 +885,7 @@ static void update_keyblocks(AnimKeylist *keylist, BezTriple *bezt, const int be
int max_curve = 0;
LISTBASE_FOREACH (ActKeyColumn *, col, &keylist->key_columns) {
max_curve = MAX2(max_curve, col->totcurve);
max_curve = std::max(max_curve, int(col->totcurve));
}
/* Propagate blocks to inserted keys. */

View File

@ -8,6 +8,7 @@
* Operators for dealing with GP data-blocks and layers.
*/
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdio>
@ -2729,7 +2730,7 @@ static int gpencil_vertex_group_normalize_all_exec(bContext *C, wmOperator *op)
}
/* Normalize weights. */
float fac = MAX2(0, (1.0f - sum_lock) / sum_unlock);
float fac = std::max(0.0f, (1.0f - sum_lock) / sum_unlock);
for (v = 0; v < defbase_tot; v++) {
/* Get vertex group. */

View File

@ -6,6 +6,7 @@
* \ingroup edgpencil
*/
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdio>
@ -1770,7 +1771,7 @@ float ED_gpencil_cursor_radius(bContext *C, int x, int y)
point2D.m_xy[0] = float(x + 64);
gpencil_stroke_convertcoords_tpoint(scene, region, ob, &point2D, nullptr, p2);
/* Clip extreme zoom level (and avoid division by zero). */
distance = MAX2(len_v3v3(p1, p2), 0.001f);
distance = std::max(len_v3v3(p1, p2), 0.001f);
/* Handle layer thickness change. */
float brush_size = float(brush->size);

View File

@ -6,6 +6,7 @@
* \ingroup edinterface
*/
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
@ -798,10 +799,10 @@ static ImBuf *create_mono_icon_with_border(ImBuf *buf,
const int blur_size = 2 / resolution_divider;
for (int bx = 0; bx < icon_width; bx++) {
const int asx = std::max(bx - blur_size, 0);
const int aex = MIN2(bx + blur_size + 1, icon_width);
const int aex = std::min(bx + blur_size + 1, icon_width);
for (int by = 0; by < icon_height; by++) {
const int asy = std::max(by - blur_size, 0);
const int aey = MIN2(by + blur_size + 1, icon_height);
const int aey = std::min(by + blur_size + 1, icon_height);
/* blur alpha channel */
const int write_offset = by * (ICON_GRID_W + 2 * ICON_MONO_BORDER_OUTSET) + bx;
@ -2584,7 +2585,7 @@ ImBuf *UI_icon_alert_imbuf_get(eAlertIcon icon)
return nullptr;
#else
const int ALERT_IMG_SIZE = 256;
icon = eAlertIcon(MIN2(icon, ALERT_ICON_MAX - 1));
icon = eAlertIcon(std::min<int>(icon, ALERT_ICON_MAX - 1));
const int left = icon * ALERT_IMG_SIZE;
const rcti crop = {left, left + ALERT_IMG_SIZE - 1, 0, ALERT_IMG_SIZE - 1};
ImBuf *ibuf = IMB_ibImageFromMemory((const uchar *)datatoc_alert_icons_png,

View File

@ -6,6 +6,7 @@
* \ingroup edinterface
*/
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
@ -4302,7 +4303,7 @@ static void ui_litem_estimate_column_flow(uiLayout *litem)
int totitem = 0;
LISTBASE_FOREACH (uiItem *, item, &litem->items) {
ui_item_size(item, &itemw, &itemh);
maxw = MAX2(maxw, itemw);
maxw = std::max(maxw, itemw);
toth += itemh;
totitem++;
}
@ -6382,7 +6383,7 @@ uiLayout *uiItemsAlertBox(uiBlock *block, const int size, const eAlertIcon icon)
{
const uiStyle *style = UI_style_get_dpi();
const short icon_size = 64 * UI_SCALE_FAC;
const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points);
const int text_points_max = std::max(style->widget.points, style->widgetlabel.points);
const int dialog_width = icon_size + (text_points_max * size * UI_SCALE_FAC);
/* By default, the space between icon and text/buttons will be equal to the 'columnspace',
* this extra padding will add some space by increasing the left column width,

View File

@ -8,6 +8,7 @@
* PopUp Menu Region
*/
#include <algorithm>
#include <cstdarg>
#include <cstdlib>
#include <cstring>
@ -592,7 +593,7 @@ void UI_popup_menu_reports(bContext *C, ReportList *reports)
msg_next = strchr(msg, '\n');
if (msg_next) {
msg_next++;
BLI_strncpy(buf, msg, MIN2(sizeof(buf), msg_next - msg));
BLI_strncpy(buf, msg, std::min(sizeof(buf), size_t(msg_next - msg)));
msg = buf;
}
uiItemL(layout, msg, icon);

View File

@ -17,6 +17,7 @@
* For now it's not a priority, so leave as-is.
*/
#include <algorithm>
#include <cstdarg>
#include <cstdlib>
#include <cstring>

View File

@ -6,6 +6,7 @@
* \ingroup edinterface
*/
#include <algorithm>
#include <cstdlib>
#include <cstring>
@ -1006,7 +1007,8 @@ static void ui_template_list_layout_draw(const bContext *C,
const int size_x = UI_preview_tile_size_x();
const int size_y = show_names ? UI_preview_tile_size_y() : UI_preview_tile_size_y_no_label();
const int cols_per_row = MAX2((uiLayoutGetWidth(box) - V2D_SCROLL_WIDTH) / size_x, 1);
const int cols_per_row = std::max(int((uiLayoutGetWidth(box) - V2D_SCROLL_WIDTH) / size_x),
1);
uiLayout *grid = uiLayoutGridFlow(row, true, cols_per_row, true, true, true);
TemplateListLayoutDrawData adjusted_layout_data = *layout_data;

View File

@ -6,6 +6,7 @@
* \ingroup edinterface
*/
#include <algorithm>
#include <cctype>
#include <cstddef>
#include <cstdlib>
@ -7272,7 +7273,7 @@ static void uiTemplateRecentFiles_tooltip_func(bContext * /*C*/, uiTooltipData *
}
if (thumb) {
float scale = (72.0f * UI_SCALE_FAC) / float(MAX2(thumb->x, thumb->y));
float scale = (72.0f * UI_SCALE_FAC) / float(std::max(thumb->x, thumb->y));
short size[2] = {short(float(thumb->x) * scale), short(float(thumb->y) * scale)};
UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);

View File

@ -6,6 +6,7 @@
* \ingroup edinterface
*/
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstring>
@ -2846,7 +2847,7 @@ static void ui_hsv_cursor(const float x,
immUniform1f("outlineWidth", U.pixelsize);
/* Alpha of outline colors just strong enough to give good contrast. */
const float fg = MIN2(1.0f - hsv[2] + 0.2, 0.8f);
const float fg = std::min(1.0f - hsv[2] + 0.2f, 0.8f);
const float bg = hsv[2] / 2.0f;
immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, bg);

View File

@ -6,6 +6,7 @@
* \ingroup edinterface
*/
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
@ -148,7 +149,7 @@ static void get_parallel_lines_draw_steps(const ParallelLinesSet *lines,
lines->offset;
if (region_start <= *r_first && region_end >= *r_first) {
*r_steps = MAX2(0, floorf((region_end - *r_first) / lines->distance)) + 1;
*r_steps = std::max(0.0f, floorf((region_end - *r_first) / lines->distance)) + 1;
}
else {
*r_steps = 0;

View File

@ -6,6 +6,8 @@
* \ingroup edmask
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BKE_context.hh"
@ -85,13 +87,13 @@ static void setup_vertex_point(Mask *mask,
current_point = &spline->points[point_index];
if (current_point->bezt.h1 != HD_VECT || current_point->bezt.h2 != HD_VECT) {
bezt->h1 = bezt->h2 = MAX2(current_point->bezt.h2, current_point->bezt.h1);
bezt->h1 = bezt->h2 = std::max(current_point->bezt.h2, current_point->bezt.h1);
break;
}
}
}
else {
bezt->h1 = bezt->h2 = MAX2(reference_point->bezt.h2, reference_point->bezt.h1);
bezt->h1 = bezt->h2 = std::max(reference_point->bezt.h2, reference_point->bezt.h1);
}
reference_parent_point = reference_point;
@ -121,12 +123,12 @@ static void setup_vertex_point(Mask *mask,
}
/* handle type */
char handle_type = 0;
uint8_t handle_type = 0;
if (prev_point) {
handle_type = prev_point->bezt.h2;
}
if (next_point) {
handle_type = MAX2(next_point->bezt.h2, handle_type);
handle_type = std::max(next_point->bezt.h2, handle_type);
}
bezt->h1 = bezt->h2 = handle_type;

View File

@ -9,6 +9,8 @@
* tools operating on meshes
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLI_math_matrix.h"
@ -1049,12 +1051,12 @@ static uint mirror_facehash(const void *ptr)
uint v0, v1;
if (mf->v4) {
v0 = MIN4(mf->v1, mf->v2, mf->v3, mf->v4);
v1 = MAX4(mf->v1, mf->v2, mf->v3, mf->v4);
v0 = std::min({mf->v1, mf->v2, mf->v3, mf->v4});
v1 = std::max({mf->v1, mf->v2, mf->v3, mf->v4});
}
else {
v0 = MIN3(mf->v1, mf->v2, mf->v3);
v1 = MAX3(mf->v1, mf->v2, mf->v3);
v0 = std::min({mf->v1, mf->v2, mf->v3});
v1 = std::min({mf->v1, mf->v2, mf->v3});
}
return ((v0 * 39) ^ (v1 * 31));

View File

@ -6,6 +6,7 @@
* \ingroup edphys
*/
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
@ -4637,7 +4638,7 @@ static int brush_add(const bContext *C, PEData *data, short number)
mul_v3_fl(key3[0].co, weight[0]);
/* TODO: interpolating the weight would be nicer */
thkey->weight = (ppa->hair + MIN2(k, ppa->totkey - 1))->weight;
thkey->weight = (ppa->hair + std::min(k, ppa->totkey - 1))->weight;
if (maxw > 1) {
key3[1].time = key3[0].time;

View File

@ -8,6 +8,7 @@
/* global includes */
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
@ -1383,8 +1384,8 @@ static void icon_copy_rect(ImBuf *ibuf, uint w, uint h, uint *rect)
}
/* Scaling down must never assign zero width/height, see: #89868. */
ex = MAX2(1, short(scaledx));
ey = MAX2(1, short(scaledy));
ex = std::max(short(1), short(scaledx));
ey = std::max(short(1), short(scaledy));
dx = (w - ex) / 2;
dy = (h - ey) / 2;

View File

@ -286,8 +286,8 @@ eScreenDir area_getorientation(ScrArea *sa_a, ScrArea *sa_b)
short overlapy = std::min(top_a, top_b) - std::max(bottom_a, bottom_b);
/* Minimum overlap required. */
const short minx = MIN3(AREAJOINTOLERANCEX, right_a - left_a, right_b - left_b);
const short miny = MIN3(AREAJOINTOLERANCEY, top_a - bottom_a, top_b - bottom_b);
const short minx = std::min({int(AREAJOINTOLERANCEX), right_a - left_a, right_b - left_b});
const short miny = std::min({int(AREAJOINTOLERANCEY), top_a - bottom_a, top_b - bottom_b});
if (top_a == bottom_b && overlapx >= minx) {
return eScreenDir(1); /* sa_a to bottom of sa_b = N */

View File

@ -84,7 +84,7 @@ ScrEdge *screen_geom_area_map_find_active_scredge(const ScrAreaMap *area_map,
if (screen_geom_edge_is_horizontal(se)) {
if ((se->v1->vec.y > bounds_rect->ymin) && (se->v1->vec.y < (bounds_rect->ymax - 1))) {
short min, max;
min = MIN2(se->v1->vec.x, se->v2->vec.x);
min = std::min(se->v1->vec.x, se->v2->vec.x);
max = std::max(se->v1->vec.x, se->v2->vec.x);
if (abs(my - se->v1->vec.y) <= safety && mx >= min && mx <= max) {
@ -95,7 +95,7 @@ ScrEdge *screen_geom_area_map_find_active_scredge(const ScrAreaMap *area_map,
else {
if ((se->v1->vec.x > bounds_rect->xmin) && (se->v1->vec.x < (bounds_rect->xmax - 1))) {
short min, max;
min = MIN2(se->v1->vec.y, se->v2->vec.y);
min = std::min(se->v1->vec.y, se->v2->vec.y);
max = std::max(se->v1->vec.y, se->v2->vec.y);
if (abs(mx - se->v1->vec.x) <= safety && my >= min && my <= max) {

View File

@ -692,7 +692,7 @@ static void brush_painter_2d_refresh_cache(ImagePaintState *s,
Brush *brush = painter->brush;
BrushPainterCache *cache = &tile->cache;
/* Adding 4 pixels of padding for brush anti-aliasing. */
const int diameter = MAX2(1, size * 2) + 4;
const int diameter = std::max(1, int(size * 2)) + 4;
bool do_random = false;
bool do_partial_update = false;

View File

@ -7,6 +7,7 @@
* \brief Functions to paint images in 2D and 3D.
*/
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
@ -1375,7 +1376,7 @@ static void uv_image_outset(const ProjPaintState *ps,
len_fact = UNLIKELY(len_fact < FLT_EPSILON) ? FLT_MAX : (1.0f / len_fact);
/* Clamp the length factor, see: #62236. */
len_fact = MIN2(len_fact, 10.0f);
len_fact = std::min(len_fact, 10.0f);
mul_v2_fl(no, ps->seam_bleed_px * len_fact);

View File

@ -799,10 +799,10 @@ static void calc_clay_surface_task_cb(Object *ob,
float plane_dist = dist_signed_to_plane_v3(vd.co, plane);
float plane_dist_abs = fabsf(plane_dist);
if (plane_dist > 0.0f) {
csd->plane_dist[0] = MIN2(csd->plane_dist[0], plane_dist_abs);
csd->plane_dist[0] = std::min(csd->plane_dist[0], plane_dist_abs);
}
else {
csd->plane_dist[1] = MIN2(csd->plane_dist[1], plane_dist_abs);
csd->plane_dist[1] = std::min(csd->plane_dist[1], plane_dist_abs);
}
BKE_pbvh_vertex_iter_end;
}

View File

@ -311,7 +311,7 @@ static void file_draw_tooltip_custom_func(bContext * /*C*/, uiTooltipData *tip,
}
if (thumb && params->display != FILE_IMGDISPLAY) {
float scale = (96.0f * UI_SCALE_FAC) / float(MAX2(thumb->x, thumb->y));
float scale = (96.0f * UI_SCALE_FAC) / float(std::max(thumb->x, thumb->y));
short size[2] = {short(float(thumb->x) * scale), short(float(thumb->y) * scale)};
UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
UI_tooltip_text_field_add(tip, {}, {}, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
@ -1281,7 +1281,8 @@ void file_draw_list(const bContext *C, ARegion *region)
if (do_drag) {
const uiStyle *style = UI_style_get();
const int str_width = UI_fontstyle_string_width(&style->widget, file->name);
const int drag_width = MIN2(str_width + icon_ofs, column_width - ATTRIBUTE_COLUMN_PADDING);
const int drag_width = std::min(str_width + icon_ofs,
int(column_width - ATTRIBUTE_COLUMN_PADDING));
if (drag_width > 0) {
uiBut *drag_but = uiDefBut(block,
UI_BTYPE_LABEL,

View File

@ -792,7 +792,7 @@ static bool file_walk_select_selection_set(bContext *C,
/* do the actual selection */
if (fill) {
FileSelection sel = {MIN2(active, last_sel), MAX2(active, last_sel)};
FileSelection sel = {std::min(active, last_sel), std::max(active, last_sel)};
/* fill selection between last and first selected file */
filelist_entries_select_index_range_set(

View File

@ -6,6 +6,7 @@
* \ingroup spfile
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
@ -163,7 +164,7 @@ static void fsmenu_entry_generate_name(FSMenuEntry *fsentry, char *name, size_t
len += 1;
}
BLI_strncpy(name, &fsentry->path[offset], MIN2(len, name_size));
BLI_strncpy(name, &fsentry->path[offset], std::min(size_t(len), name_size));
if (!name[0]) {
name[0] = '/';
name[1] = '\0';

View File

@ -998,7 +998,7 @@ static void node_update_hidden(bNode &node, uiBlock &block)
}
float hiddenrad = HIDDEN_RAD;
float tot = MAX2(totin, totout);
float tot = std::max(totin, totout);
if (tot > 4) {
hiddenrad += 5.0f * float(tot - 4);
}

View File

@ -91,7 +91,7 @@ static void outliner_tree_dimensions_impl(SpaceOutliner *space_outliner,
int *height)
{
LISTBASE_FOREACH (TreeElement *, te, lb) {
*width = MAX2(*width, te->xend);
*width = std::max(*width, int(te->xend));
if (height != nullptr) {
*height += UI_UNIT_Y;
}

View File

@ -6,6 +6,7 @@
* \ingroup spoutliner
*/
#include <algorithm>
#include <cmath>
#include <cstring>
@ -691,7 +692,7 @@ static void outliner_restore_scrolling_position(SpaceOutliner *space_outliner,
int ys_new = te_new->ys;
int ys_old = focus->ys;
float y_move = MIN2(ys_new - ys_old, -v2d->cur.ymax);
float y_move = std::min(float(ys_new - ys_old), -v2d->cur.ymax);
BLI_rctf_translate(&v2d->cur, 0, y_move);
}
else {

View File

@ -6,6 +6,7 @@
* \ingroup spoutliner
*/
#include <algorithm>
#include <cstring>
#include "BLI_listbase.h"
@ -421,7 +422,7 @@ void outliner_scroll_view(SpaceOutliner *space_outliner, ARegion *region, int de
{
int tree_width, tree_height;
outliner_tree_dimensions(space_outliner, &tree_width, &tree_height);
int y_min = MIN2(region->v2d.cur.ymin, -tree_height);
int y_min = std::min(int(region->v2d.cur.ymin), -tree_height);
region->v2d.cur.ymax += delta_y;
region->v2d.cur.ymin += delta_y;

View File

@ -6,6 +6,8 @@
* \ingroup sptext
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLF_api.h"
@ -271,7 +273,7 @@ void space_text_wrap_offset(
while (chars--) {
if (i + columns - start > max) {
end = MIN2(end, i);
end = std::min(end, i);
if (chop && linep == linein && i >= cursin) {
if (i == cursin) {
@ -348,7 +350,7 @@ void space_text_wrap_offset_in_line(
while (chars--) {
if (i + columns - start > max) {
end = MIN2(end, i);
end = std::min(end, i);
if (chop && i >= cursin) {
if (i == cursin) {
@ -939,7 +941,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *region, rcti *scroll, rcti *b
st, region, static_cast<TextLine *>(st->text->lines.first), st->text->curl);
sell_off = space_text_get_span_wrap(
st, region, static_cast<TextLine *>(st->text->lines.first), st->text->sell);
lhlstart = MIN2(curl_off, sell_off);
lhlstart = std::min(curl_off, sell_off);
lhlend = std::max(curl_off, sell_off);
if (ltexth > 0) {
@ -1672,7 +1674,7 @@ void space_text_update_character_width(SpaceText *st)
text_font_begin(&tdc);
st->runtime->cwidth_px = BLF_fixed_width(tdc.font_id);
st->runtime->cwidth_px = MAX2(st->runtime->cwidth_px, char(1));
st->runtime->cwidth_px = std::max(st->runtime->cwidth_px, 1);
text_font_end(&tdc);
}

View File

@ -6,6 +6,7 @@
* \ingroup sptext
*/
#include <algorithm>
#include <cerrno>
#include <cstring>
#include <sstream>
@ -1790,7 +1791,7 @@ static int space_text_get_cursor_rel(
curs = j;
}
if (i + columns - start > max) {
end = MIN2(end, i);
end = std::min(end, i);
if (found) {
/* exact cursor position was found, check if it's */
@ -1985,7 +1986,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
while (chars--) {
if (i + columns - start > max) {
end = MIN2(end, i);
end = std::min(end, i);
*charp = endj;
@ -2072,7 +2073,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
while (chars--) {
if (i + columns - start > max) {
end = MIN2(end, i);
end = std::min(end, i);
if (chop) {
endj = BLI_str_find_prev_char_utf8((*linep)->line + j, (*linep)->line) - (*linep)->line;
@ -3164,7 +3165,7 @@ static void space_text_cursor_set_to_pos_wrapped(
curs = j;
}
if (i + columns - start > max) {
end = MIN2(end, i);
end = std::min(end, i);
if (found) {
/* exact cursor position was found, check if it's still on needed line

View File

@ -14,6 +14,8 @@
* - matrix_offset: used to store the orientation.
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLI_math_matrix.h"
@ -225,12 +227,12 @@ static void gizmo_axis_draw(const bContext *C, wmGizmo *gz)
if (is_aligned_front) {
interp_v4_v4v4(
negative_color, blender::float4{1.0f, 1.0f, 1.0f, 1.0f}, axis_color[axis], 0.5f);
negative_color[3] = MIN2(depth + 1, 1.0f);
negative_color[3] = std::min(depth + 1, 1.0f);
outline_color = negative_color;
}
else {
interp_v4_v4v4(negative_color, view_color, axis_color[axis], 0.25f);
negative_color[3] = MIN2(depth + 1, 1.0f);
negative_color[3] = std::min(depth + 1, 1.0f);
inner_color = negative_color;
}
}

View File

@ -6,6 +6,8 @@
* \ingroup edutil
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLI_math_vector_types.hh"
@ -124,10 +126,10 @@ static void image_sample_rect_color_ubyte(const ImBuf *ibuf,
}
mul_v4_fl(r_col_linear, 1.0 / float(col_tot));
r_col[0] = MIN2(col_accum_ub[0] / col_tot, 255);
r_col[1] = MIN2(col_accum_ub[1] / col_tot, 255);
r_col[2] = MIN2(col_accum_ub[2] / col_tot, 255);
r_col[3] = MIN2(col_accum_ub[3] / col_tot, 255);
r_col[0] = std::min<uchar>(col_accum_ub[0] / col_tot, 255);
r_col[1] = std::min<uchar>(col_accum_ub[1] / col_tot, 255);
r_col[2] = std::min<uchar>(col_accum_ub[2] / col_tot, 255);
r_col[3] = std::min<uchar>(col_accum_ub[3] / col_tot, 255);
}
static void image_sample_rect_color_float(ImBuf *ibuf, const rcti *rect, float r_col[4])

View File

@ -2,6 +2,8 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include <algorithm>
#include "GEO_reverse_uv_sampler.hh"
#include "BLI_math_geom.h"
@ -72,7 +74,7 @@ ReverseUVSampler::Result ReverseUVSampler::sample(const float2 &query_uv) const
const float x_dist = std::max(-bary_weights.x, bary_weights.x - 1.0f);
const float y_dist = std::max(-bary_weights.y, bary_weights.y - 1.0f);
const float z_dist = std::max(-bary_weights.z, bary_weights.z - 1.0f);
const float dist = MAX3(x_dist, y_dist, z_dist);
const float dist = std::max({x_dist, y_dist, z_dist});
if (dist <= 0.0f && best_dist <= 0.0f) {
const float worse_dist = std::max(dist, best_dist);

View File

@ -6,7 +6,7 @@
* \ingroup modifiers
*/
#include <algorithm> /* For `min/max`. */
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
@ -809,7 +809,7 @@ static void generate_geometry(GpencilModifierData *md,
if (gpf->next) {
/* Use the next frame or upper bound as end frame, whichever is lower/closer */
end_frame = MIN2(end_frame, gpf->next->framenum);
end_frame = std::min(end_frame, float(gpf->next->framenum));
}
/* Early exit if current frame is outside start/end bounds */

View File

@ -6,6 +6,7 @@
* \ingroup modifiers
*/
#include <algorithm>
#include <cstdio>
#include <cstring>
@ -143,7 +144,7 @@ static bool stroke_dash(const bGPDstroke *gps,
continue;
}
const int size = MIN2(gps->totpoints - new_stroke_offset, seg);
const int size = std::min(gps->totpoints - new_stroke_offset, seg);
if (size == 0) {
continue;
}

View File

@ -108,8 +108,8 @@ static void deform_stroke(GpencilModifierData *md,
return;
}
const float dist_max = MAX2(mmd->dist_start, mmd->dist_end);
const float dist_min = MIN2(mmd->dist_start, mmd->dist_end);
const float dist_max = std::max(mmd->dist_start, mmd->dist_end);
const float dist_min = std::min(mmd->dist_start, mmd->dist_end);
const int target_def_nr = BKE_object_defgroup_name_index(ob, mmd->target_vgname);
if (target_def_nr == -1) {

View File

@ -13,6 +13,7 @@
#include "BLI_math_vector.h"
#include "BLI_threads.h"
#include <algorithm>
#include <math.h>
#ifdef __cplusplus
@ -743,7 +744,7 @@ BLI_INLINE int lineart_intersect_seg_seg(const double a1[2],
if (LRT_DOUBLE_CLOSE_ENOUGH(b1[0], b2[0])) {
y = interpd(a2[1], a1[1], ratio);
if (y > MAX2(b1[1], b2[1]) || y < MIN2(b1[1], b2[1])) {
if (y > std::max(b1[1], b2[1]) || y < std::min(b1[1], b2[1])) {
return 0;
}
}

View File

@ -1372,7 +1372,7 @@ void MOD_lineart_chain_offset_towards_camera(LineartData *ld, float dist, bool u
sub_v3_v3v3(dir, cam, eci->gpos);
float orig_len = len_v3(dir);
normalize_v3(dir);
mul_v3_fl(dir, MIN2(dist, orig_len - ld->conf.near_clip));
mul_v3_fl(dir, std::min<float>(dist, orig_len - ld->conf.near_clip));
add_v3_v3(eci->gpos, dir);
}
}

View File

@ -6,6 +6,8 @@
* \ingroup editors
*/
#include <algorithm>
#include "MOD_gpencil_legacy_lineart.h"
#include "MOD_lineart.h"
@ -344,7 +346,7 @@ void lineart_edge_cut(LineartData *ld,
continue;
}
min_occ = MIN2(min_occ, seg->occlusion);
min_occ = std::min<int8_t>(min_occ, seg->occlusion);
prev_seg = seg;
}
@ -2843,11 +2845,11 @@ static bool lineart_triangle_edge_image_space_occlusion(const LineartTriangle *t
*FBC1 = tri->v[1]->fbcoord, *FBC2 = tri->v[2]->fbcoord;
/* Overlapping not possible, return early. */
if ((MAX3(FBC0[0], FBC1[0], FBC2[0]) < MIN2(LFBC[0], RFBC[0])) ||
(MIN3(FBC0[0], FBC1[0], FBC2[0]) > MAX2(LFBC[0], RFBC[0])) ||
(MAX3(FBC0[1], FBC1[1], FBC2[1]) < MIN2(LFBC[1], RFBC[1])) ||
(MIN3(FBC0[1], FBC1[1], FBC2[1]) > MAX2(LFBC[1], RFBC[1])) ||
(MIN3(FBC0[3], FBC1[3], FBC2[3]) > MAX2(LFBC[3], RFBC[3])))
if ((std::max({FBC0[0], FBC1[0], FBC2[0]}) < std::min(LFBC[0], RFBC[0])) ||
(std::min({FBC0[0], FBC1[0], FBC2[0]}) > std::max(LFBC[0], RFBC[0])) ||
(std::max({FBC0[1], FBC1[1], FBC2[1]}) < std::min(LFBC[1], RFBC[1])) ||
(std::min({FBC0[1], FBC1[1], FBC2[1]}) > std::max(LFBC[1], RFBC[1])) ||
(std::min({FBC0[3], FBC1[3], FBC2[3]}) > std::max(LFBC[3], RFBC[3])))
{
return false;
}
@ -3067,8 +3069,8 @@ static bool lineart_triangle_edge_image_space_occlusion(const LineartTriangle *t
/* Determine the start and end point of image space cut on a line. */
if (dot_1f <= 0 && dot_2f <= 0 && (dot_v1 || dot_v2)) {
*from = MAX2(0, cross_ratios[cross_v1]);
*to = MIN2(1, cross_ratios[cross_v2]);
*from = std::max(0.0, cross_ratios[cross_v1]);
*to = std::min(1.0, cross_ratios[cross_v2]);
if (*from >= *to) {
return false;
}
@ -3076,14 +3078,14 @@ static bool lineart_triangle_edge_image_space_occlusion(const LineartTriangle *t
}
if (dot_1f >= 0 && dot_2f <= 0 && (dot_v1 || dot_v2)) {
*from = std::max(cut, cross_ratios[cross_v1]);
*to = MIN2(1, cross_ratios[cross_v2]);
*to = std::min(1.0, cross_ratios[cross_v2]);
if (*from >= *to) {
return false;
}
return true;
}
if (dot_1f <= 0 && dot_2f >= 0 && (dot_v1 || dot_v2)) {
*from = MAX2(0, cross_ratios[cross_v1]);
*from = std::max(0.0, cross_ratios[cross_v1]);
*to = std::min(cut, cross_ratios[cross_v2]);
if (*from >= *to) {
return false;
@ -3346,7 +3348,7 @@ static bool lineart_schedule_new_triangle_task(LineartIsecThread *th)
while (remaining > 0 && eln) {
int remaining_this_eln = eln->element_count - ld->isect_scheduled_up_to_index;
int added_count = MIN2(remaining, remaining_this_eln);
int added_count = std::min(remaining, remaining_this_eln);
remaining -= added_count;
if (remaining || added_count == remaining_this_eln) {
eln = eln->next;
@ -3441,12 +3443,12 @@ static void lineart_triangle_intersect_in_bounding_area(LineartTriangle *tri,
*RG2 = testing_triangle->v[2]->gloc;
/* Bounding box not overlapping or triangles share edges, not potential of intersecting. */
if ((MIN3(G0[2], G1[2], G2[2]) > MAX3(RG0[2], RG1[2], RG2[2])) ||
(MAX3(G0[2], G1[2], G2[2]) < MIN3(RG0[2], RG1[2], RG2[2])) ||
(MIN3(G0[0], G1[0], G2[0]) > MAX3(RG0[0], RG1[0], RG2[0])) ||
(MAX3(G0[0], G1[0], G2[0]) < MIN3(RG0[0], RG1[0], RG2[0])) ||
(MIN3(G0[1], G1[1], G2[1]) > MAX3(RG0[1], RG1[1], RG2[1])) ||
(MAX3(G0[1], G1[1], G2[1]) < MIN3(RG0[1], RG1[1], RG2[1])) ||
if ((std::min({G0[2], G1[2], G2[2]}) > std::max({RG0[2], RG1[2], RG2[2]})) ||
(std::max({G0[2], G1[2], G2[2]}) < std::min({RG0[2], RG1[2], RG2[2]})) ||
(std::min({G0[0], G1[0], G2[0]}) > std::max({RG0[0], RG1[0], RG2[0]})) ||
(std::max({G0[0], G1[0], G2[0]}) < std::min({RG0[0], RG1[0], RG2[0]})) ||
(std::min({G0[1], G1[1], G2[1]}) > std::max({RG0[1], RG1[1], RG2[1]})) ||
(std::max({G0[1], G1[1], G2[1]}) < std::min({RG0[1], RG1[1], RG2[1]})) ||
lineart_triangle_share_edge(tri, testing_triangle))
{
continue;
@ -4029,10 +4031,10 @@ static void lineart_bounding_area_split(LineartData *ld,
LineartTriangle *tri = root->linked_triangles[i];
double b[4];
b[0] = MIN3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
b[1] = MAX3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
b[2] = MAX3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
b[3] = MIN3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
b[0] = std::min({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
b[1] = std::max({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
b[2] = std::max({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
b[3] = std::min({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
/* Re-link triangles into child tiles, not doing intersection lines during this because this
* batch of triangles are all tested with each other for intersections. */
@ -4068,8 +4070,9 @@ static bool lineart_bounding_area_edge_intersect(LineartData * /*fb*/,
double converted[4];
double c1, c;
if (((converted[0] = ba->l) > MAX2(l[0], r[0])) || ((converted[1] = ba->r) < MIN2(l[0], r[0])) ||
((converted[2] = ba->b) > MAX2(l[1], r[1])) ||
if (((converted[0] = ba->l) > std::max(l[0], r[0])) ||
((converted[1] = ba->r) < std::min(l[0], r[0])) ||
((converted[2] = ba->b) > std::max(l[1], r[1])) ||
((converted[3] = ba->u) < std::min(l[1], r[1])))
{
return false;
@ -4177,10 +4180,10 @@ static void lineart_bounding_area_link_triangle(LineartData *ld,
double *B1 = l_r_u_b;
double b[4];
if (!l_r_u_b) {
b[0] = MIN3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
b[1] = MAX3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
b[2] = MAX3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
b[3] = MIN3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
b[0] = std::min({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
b[1] = std::max({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
b[2] = std::max({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
b[3] = std::min({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
B1 = b;
}
for (int iba = 0; iba < 4; iba++) {
@ -4409,10 +4412,10 @@ static bool lineart_get_triangle_bounding_areas(
return false;
}
b[0] = MIN3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
b[1] = MAX3(tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]);
b[2] = MIN3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
b[3] = MAX3(tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]);
b[0] = std::min({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
b[1] = std::max({tri->v[0]->fbcoord[0], tri->v[1]->fbcoord[0], tri->v[2]->fbcoord[0]});
b[2] = std::min({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
b[3] = std::max({tri->v[0]->fbcoord[1], tri->v[1]->fbcoord[1], tri->v[2]->fbcoord[1]});
if (b[0] > 1 || b[1] < -1 || b[2] > 1 || b[3] < -1) {
return false;
@ -4453,9 +4456,9 @@ static bool lineart_get_edge_bounding_areas(
return false;
}
b[0] = MIN2(e->v1->fbcoord[0], e->v2->fbcoord[0]);
b[0] = std::min(e->v1->fbcoord[0], e->v2->fbcoord[0]);
b[1] = std::max(e->v1->fbcoord[0], e->v2->fbcoord[0]);
b[2] = MIN2(e->v1->fbcoord[1], e->v2->fbcoord[1]);
b[2] = std::min(e->v1->fbcoord[1], e->v2->fbcoord[1]);
b[3] = std::max(e->v1->fbcoord[1], e->v2->fbcoord[1]);
if (b[0] > 1 || b[1] < -1 || b[2] > 1 || b[3] < -1) {
@ -4799,7 +4802,7 @@ LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *self,
ux = x + (uy - y) / k;
r1 = ratiod(fbcoord1[0], fbcoord2[0], rx);
r2 = ratiod(fbcoord1[0], fbcoord2[0], ux);
if (MIN2(r1, r2) > 1) {
if (std::min(r1, r2) > 1) {
return nullptr;
}
@ -4832,7 +4835,7 @@ LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *self,
bx = x + (by - y) / k;
r1 = ratiod(fbcoord1[0], fbcoord2[0], rx);
r2 = ratiod(fbcoord1[0], fbcoord2[0], bx);
if (MIN2(r1, r2) > 1) {
if (std::min(r1, r2) > 1) {
return nullptr;
}
if (r1 <= r2) {
@ -4884,7 +4887,7 @@ LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *self,
ux = x + (uy - y) / k;
r1 = ratiod(fbcoord1[0], fbcoord2[0], lx);
r2 = ratiod(fbcoord1[0], fbcoord2[0], ux);
if (MIN2(r1, r2) > 1) {
if (std::min(r1, r2) > 1) {
return nullptr;
}
if (r1 <= r2) {
@ -4915,7 +4918,7 @@ LineartBoundingArea *lineart_bounding_area_next(LineartBoundingArea *self,
bx = x + (by - y) / k;
r1 = ratiod(fbcoord1[0], fbcoord2[0], lx);
r2 = ratiod(fbcoord1[0], fbcoord2[0], bx);
if (MIN2(r1, r2) > 1) {
if (std::min(r1, r2) > 1) {
return nullptr;
}
if (r1 <= r2) {

View File

@ -736,10 +736,10 @@ static bool lineart_shadow_cast_onto_triangle(LineartData *ld,
/* Bound box check. Because we have already done occlusion in the shadow camera, so any visual
* intersection found in this function must mean that the triangle is behind the given line so it
* will always project a shadow, hence no need to do depth bound-box check. */
if ((MAX3(FBC0[0], FBC1[0], FBC2[0]) < MIN2(LFBC[0], RFBC[0])) ||
(MIN3(FBC0[0], FBC1[0], FBC2[0]) > MAX2(LFBC[0], RFBC[0])) ||
(MAX3(FBC0[1], FBC1[1], FBC2[1]) < MIN2(LFBC[1], RFBC[1])) ||
(MIN3(FBC0[1], FBC1[1], FBC2[1]) > MAX2(LFBC[1], RFBC[1])))
if ((std::max({FBC0[0], FBC1[0], FBC2[0]}) < std::min(LFBC[0], RFBC[0])) ||
(std::min({FBC0[0], FBC1[0], FBC2[0]}) > std::max(LFBC[0], RFBC[0])) ||
(std::max({FBC0[1], FBC1[1], FBC2[1]}) < std::min(LFBC[1], RFBC[1])) ||
(std::min({FBC0[1], FBC1[1], FBC2[1]}) > std::max(LFBC[1], RFBC[1])))
{
return false;
}

View File

@ -186,8 +186,8 @@ void GPU_indexbuf_set_line_verts(GPUIndexBufBuilder *builder, uint elem, uint v1
uint idx = elem * 2;
builder->data[idx++] = v1;
builder->data[idx++] = v2;
builder->index_min = MIN3(builder->index_min, v1, v2);
builder->index_max = MAX3(builder->index_max, v1, v2);
builder->index_min = std::min({builder->index_min, v1, v2});
builder->index_max = std::max({builder->index_max, v1, v2});
builder->index_len = std::max(builder->index_len, idx);
}
@ -204,8 +204,8 @@ void GPU_indexbuf_set_tri_verts(GPUIndexBufBuilder *builder, uint elem, uint v1,
builder->data[idx++] = v2;
builder->data[idx++] = v3;
builder->index_min = MIN4(builder->index_min, v1, v2, v3);
builder->index_max = MAX4(builder->index_max, v1, v2, v3);
builder->index_min = std::min({builder->index_min, v1, v2, v3});
builder->index_max = std::max({builder->index_max, v1, v2, v3});
builder->index_len = std::max(builder->index_len, idx);
}
@ -390,7 +390,7 @@ void IndexBuf::squeeze_indices_short(uint min_idx,
0xFFFFu :
(max_idx - min_idx);
for (uint i = 0; i < index_len_; i++) {
ushort_idx[i] = uint16_t(MIN2(clamp_max_idx, uint_idx[i] - min_idx));
ushort_idx[i] = std::min<uint16_t>(clamp_max_idx, uint_idx[i] - min_idx);
}
}
else {

View File

@ -8,6 +8,7 @@
* Manages materials, lights and textures.
*/
#include <algorithm>
#include <cmath>
#include <cstring>
@ -433,8 +434,8 @@ static void compute_sss_kernel(GPUSssKernelData *kd, const float radii[3], int s
{
float rad[3];
/* Minimum radius */
rad[0] = MAX2(radii[0], 1e-15f);
rad[1] = MAX2(radii[1], 1e-15f);
rad[0] = std::max(radii[0], 1e-15f);
rad[1] = std::max(radii[1], 1e-15f);
rad[2] = std::max(radii[2], 1e-15f);
kd->avg_inv_radius = 3.0f / (rad[0] + rad[1] + rad[2]);
@ -448,7 +449,7 @@ static void compute_sss_kernel(GPUSssKernelData *kd, const float radii[3], int s
/* XXX 0.6f Out of nowhere to match cycles! Empirical! Can be tweak better. */
mul_v3_v3fl(d, l, 0.6f / s);
mul_v3_v3fl(rad, d, BURLEY_TRUNCATE);
kd->max_radius = MAX3(rad[0], rad[1], rad[2]);
kd->max_radius = std::max({rad[0], rad[1], rad[2]});
copy_v3_v3(kd->param, d);

View File

@ -6,6 +6,8 @@
* \ingroup ikplugin
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BIK_api.h"
@ -142,11 +144,11 @@ static void initialize_posetree(Object * /*ob*/, bPoseChannel *pchan_tip)
BLI_addtail(&pchan_root->iktree, tree);
}
else {
tree->iterations = MAX2(data->iterations, tree->iterations);
tree->iterations = std::max<int>(data->iterations, tree->iterations);
tree->stretch = tree->stretch && !(data->flag & CONSTRAINT_IK_STRETCH);
/* Skip common pose channels and add remaining. */
const int size = MIN2(segcount, tree->totchannel);
const int size = std::min(segcount, tree->totchannel);
int a, t;
a = t = 0;
while (a < size && t < tree->totchannel) {

View File

@ -6,6 +6,7 @@
* \ingroup ikplugin
*/
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
@ -299,11 +300,11 @@ static int initialize_chain(Object *ob, bPoseChannel *pchan_tip, bConstraint *co
treecount = 1;
}
else {
tree->iterations = MAX2(data->iterations, tree->iterations);
tree->iterations = std::max<int>(data->iterations, tree->iterations);
tree->stretch = tree->stretch && !(data->flag & CONSTRAINT_IK_STRETCH);
/* Skip common pose channels and add remaining. */
size = MIN2(segcount, tree->totchannel);
size = std::min(segcount, tree->totchannel);
a = t = 0;
while (a < size && t < tree->totchannel) {
/* locate first matching channel */

View File

@ -191,6 +191,10 @@ if(WIN32)
)
endif()
if(WIN32)
add_definitions(-DNOMINMAX)
endif()
# no need to compile object files for inline headers.
set_source_files_properties(
intern/colormanagement_inline.cc

Some files were not shown because too many files have changed in this diff Show More