Cleanup: Replace some CLAMP macros with C++ functions

Pull Request: https://projects.blender.org/blender/blender/pulls/117460
This commit is contained in:
Hans Goudey
2024-01-23 21:10:33 +01:00
committed by Hans Goudey
parent 1c503c094c
commit 99f9084bee
48 changed files with 145 additions and 264 deletions
+2 -4
View File
@@ -4317,10 +4317,8 @@ static void tablet_tool_handle_tilt(void *data,
CLOG_INFO(LOG, 2, "tilt (x=%.4f, y=%.4f)", UNPACK2(tilt_unit));
GWL_TabletTool *tablet_tool = static_cast<GWL_TabletTool *>(data);
GHOST_TabletData &td = tablet_tool->data;
td.Xtilt = tilt_unit[0];
td.Ytilt = tilt_unit[1];
CLAMP(td.Xtilt, -1.0f, 1.0f);
CLAMP(td.Ytilt, -1.0f, 1.0f);
td.Xtilt = std::clamp(tilt_unit[0], -1.0f, 1.0f);
td.Ytilt = std::clamp(tilt_unit[1], -1.0f, 1.0f);
gwl_tablet_tool_frame_event_add(tablet_tool, GWL_TabletTool_EventTypes::Tilt);
}
-107
View File
@@ -104,113 +104,6 @@
/** \} */
/* -------------------------------------------------------------------- */
/** \name Clamp Macros
* \{ */
#define CLAMPIS(a, b, c) ((a) < (b) ? (b) : (a) > (c) ? (c) : (a))
#define CLAMP(a, b, c) \
{ \
if ((a) < (b)) { \
(a) = (b); \
} \
else if ((a) > (c)) { \
(a) = (c); \
} \
} \
(void)0
#define CLAMP_MAX(a, c) \
{ \
if ((a) > (c)) { \
(a) = (c); \
} \
} \
(void)0
#define CLAMP_MIN(a, b) \
{ \
if ((a) < (b)) { \
(a) = (b); \
} \
} \
(void)0
#define CLAMP2(vec, b, c) \
{ \
CLAMP((vec)[0], b, c); \
CLAMP((vec)[1], b, c); \
} \
(void)0
#define CLAMP2_MIN(vec, b) \
{ \
CLAMP_MIN((vec)[0], b); \
CLAMP_MIN((vec)[1], b); \
} \
(void)0
#define CLAMP2_MAX(vec, b) \
{ \
CLAMP_MAX((vec)[0], b); \
CLAMP_MAX((vec)[1], b); \
} \
(void)0
#define CLAMP3(vec, b, c) \
{ \
CLAMP((vec)[0], b, c); \
CLAMP((vec)[1], b, c); \
CLAMP((vec)[2], b, c); \
} \
(void)0
#define CLAMP3_MIN(vec, b) \
{ \
CLAMP_MIN((vec)[0], b); \
CLAMP_MIN((vec)[1], b); \
CLAMP_MIN((vec)[2], b); \
} \
(void)0
#define CLAMP3_MAX(vec, b) \
{ \
CLAMP_MAX((vec)[0], b); \
CLAMP_MAX((vec)[1], b); \
CLAMP_MAX((vec)[2], b); \
} \
(void)0
#define CLAMP4(vec, b, c) \
{ \
CLAMP((vec)[0], b, c); \
CLAMP((vec)[1], b, c); \
CLAMP((vec)[2], b, c); \
CLAMP((vec)[3], b, c); \
} \
(void)0
#define CLAMP4_MIN(vec, b) \
{ \
CLAMP_MIN((vec)[0], b); \
CLAMP_MIN((vec)[1], b); \
CLAMP_MIN((vec)[2], b); \
CLAMP_MIN((vec)[3], b); \
} \
(void)0
#define CLAMP4_MAX(vec, b) \
{ \
CLAMP_MAX((vec)[0], b); \
CLAMP_MAX((vec)[1], b); \
CLAMP_MAX((vec)[2], b); \
CLAMP_MAX((vec)[3], b); \
} \
(void)0
/** \} */
/* -------------------------------------------------------------------- */
/** \name String Macros
* \{ */
+1 -1
View File
@@ -335,7 +335,7 @@ void BKE_mask_clipboard_paste_to_layer(struct Main *bmain, struct MaskLayer *mas
/* `mask_evaluate.cc` */
unsigned int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height);
int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height);
unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height);
int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline, unsigned int resol);
@@ -6,6 +6,8 @@
* \ingroup bke
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
@@ -665,7 +667,7 @@ static void splineik_evaluate_bone(
}
if (bulge < 1.0f) {
if (ik_data->flag & CONSTRAINT_SPLINEIK_USE_BULGE_MIN) {
float bulge_min = CLAMPIS(ik_data->bulge_min, 0.0f, 1.0f);
float bulge_min = std::clamp(ik_data->bulge_min, 0.0f, 1.0f);
float hard = max_ff(bulge, bulge_min);
float range = 1.0f - bulge_min;
@@ -9,6 +9,7 @@
/* Allow using deprecated functionality for .blend file I/O. */
#define DNA_DEPRECATED_ALLOW
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstddef>
@@ -3552,7 +3553,7 @@ static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
}
if (bulge < 1.0f) {
if (data->flag & STRETCHTOCON_USE_BULGE_MIN) {
float bulge_min = CLAMPIS(data->bulge_min, 0.0f, 1.0f);
float bulge_min = std::clamp(data->bulge_min, 0.0f, 1.0f);
float hard = max_ff(bulge, bulge_min);
float range = 1.0f - bulge_min;
+1 -1
View File
@@ -524,7 +524,7 @@ static float eff_calc_visibility(ListBase *colliders,
absorption = col->ob->pd->absorption;
/* visibility is only between 0 and 1, calculated from 1-absorption */
visibility *= CLAMPIS(1.0f - absorption, 0.0f, 1.0f);
visibility *= std::clamp(1.0f - absorption, 0.0f, 1.0f);
if (visibility <= 0.0f) {
break;
@@ -561,7 +561,7 @@ static bool BKE_gpencil_stroke_extra_points(bGPDstroke *gps,
MDeformVert *new_dv = (MDeformVert *)MEM_mallocN(sizeof(MDeformVert) * new_count, __func__);
for (int i = 0; i < new_count; i++) {
MDeformVert *dv = &gps->dvert[CLAMPIS(i - count_before, 0, gps->totpoints - 1)];
MDeformVert *dv = &gps->dvert[std::clamp(i - count_before, 0, gps->totpoints - 1)];
int inew = i;
new_dv[inew].flag = dv->flag;
new_dv[inew].totweight = dv->totweight;
@@ -8,6 +8,7 @@
* Deform coordinates by a lattice object (used by modifier).
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
@@ -210,13 +211,13 @@ void BKE_lattice_deform_data_eval_co(LatticeDeformData *lattice_deform_data,
for (ww = wi - 1; ww <= wi + 2; ww++) {
w = weight * tw[ww - wi + 1];
idx_w = CLAMPIS(ww * w_stride, 0, idx_w_max);
idx_w = std::clamp(ww * w_stride, 0, idx_w_max);
for (vv = vi - 1; vv <= vi + 2; vv++) {
v = w * tv[vv - vi + 1];
idx_v = CLAMPIS(vv * v_stride, 0, idx_v_max);
idx_v = std::clamp(vv * v_stride, 0, idx_v_max);
for (uu = ui - 1; uu <= ui + 2; uu++) {
u = v * tu[uu - ui + 1];
idx_u = CLAMPIS(uu, 0, idx_u_max);
idx_u = std::clamp(uu, 0, idx_u_max);
const int idx = idx_w + idx_v + idx_u;
#if BLI_HAVE_SSE2
{
@@ -29,10 +29,10 @@
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
uint BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
{
float max_segment = 0.01f;
uint i, resol = 1;
int i, resol = 1;
if (width != 0 && height != 0) {
max_segment = 1.0f / float(max_ii(width, height));
@@ -42,7 +42,7 @@ uint BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
MaskSplinePoint *point = &spline->points[i];
BezTriple *bezt_curr, *bezt_next;
float a, b, c, len;
uint cur_resol;
int cur_resol;
bezt_curr = &point->bezt;
bezt_next = BKE_mask_spline_point_next_bezt(spline, spline->points, point);
@@ -65,13 +65,13 @@ uint BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
}
}
return CLAMPIS(resol, 1, MASK_RESOL_MAX);
return std::clamp(resol, 1, MASK_RESOL_MAX);
}
uint BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height)
{
const float max_segment = 0.005;
uint resol = BKE_mask_spline_resolution(spline, width, height);
int resol = BKE_mask_spline_resolution(spline, width, height);
float max_jump = 0.0f;
/* Avoid checking the feather if we already hit the maximum value. */
@@ -104,7 +104,7 @@ uint BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int heigh
resol += max_jump / max_segment;
return CLAMPIS(resol, 1, MASK_RESOL_MAX);
return std::clamp(resol, 1, MASK_RESOL_MAX);
}
int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, const uint resol)
@@ -183,7 +183,7 @@ float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline,
float (*BKE_mask_spline_differentiate(
MaskSpline *spline, int width, int height, uint *r_tot_diff_point))[2]
{
uint resol = BKE_mask_spline_resolution(spline, width, height);
int resol = BKE_mask_spline_resolution(spline, width, height);
return BKE_mask_spline_differentiate_with_resolution(spline, resol, r_tot_diff_point);
}
@@ -630,9 +630,9 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
float(*diff_feather_points_flip)[2];
uint tot_diff_feather_points;
const uint resol_a = BKE_mask_spline_resolution(spline, width, height) / 4;
const uint resol_a = uint(BKE_mask_spline_resolution(spline, width, height) / 4);
const uint resol_b = BKE_mask_spline_feather_resolution(spline, width, height) / 4;
const uint resol = CLAMPIS(std::max(resol_a, resol_b), 4, 512);
const uint resol = std::clamp(std::max(resol_a, resol_b), 4u, 512u);
diff_points = BKE_mask_spline_differentiate_with_resolution(spline, resol, &tot_diff_point);
+4 -4
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(std::max<char>(mmd->lvl, lvl), 0, mmd->totlvl);
mmd->lvl = std::clamp<char>(std::max<char>(mmd->lvl, 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);
mmd->sculptlvl = std::clamp<char>(std::max<char>(mmd->sculptlvl, lvl), 0, mmd->totlvl);
mmd->renderlvl = std::clamp<char>(std::max<char>(mmd->renderlvl, lvl), 0, mmd->totlvl);
}
static void multires_ccg_mark_as_modified(SubdivCCG *subdiv_ccg, MultiresModifiedFlags flags)
@@ -934,7 +934,7 @@ static void multires_disp_run_cb(void *__restrict userdata,
case CALC_DISPLACEMENTS:
/* Copy mask from DM to gpm */
mask = *CCG_grid_elem_mask(key, grid, x, y);
gpm->data[y * gridSize + x] = CLAMPIS(mask, 0, 1);
gpm->data[y * gridSize + x] = std::clamp(mask, 0.0f, 1.0f);
break;
case ADD_DISPLACEMENTS:
/* Add mask displacement to gpm */
@@ -7,10 +7,9 @@
* \ingroup bke
*/
#include <cstddef>
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <cstring>
@@ -3398,7 +3397,7 @@ static void hair_create_input_mesh(ParticleSimulationData *sim,
mul_m4_m4m4(root_mat, sim->ob->object_to_world, hairmat);
normalize_m4(root_mat);
bending_stiffness = CLAMPIS(
bending_stiffness = std::clamp(
1.0f - part->bending_random * psys_frand(psys, p + 666), 0.0f, 1.0f);
for (k = 0, key = pa->hair; k < pa->totkey; k++, key++) {
-49
View File
@@ -219,8 +219,6 @@ inline constexpr int64_t power_of_2_max(const int64_t x)
/** \name Clamp Macros
* \{ */
#define CLAMPIS(a, b, c) ((a) < (b) ? (b) : (a) > (c) ? (c) : (a))
#define CLAMP(a, b, c) \
{ \
if ((a) < (b)) { \
@@ -248,27 +246,6 @@ inline constexpr int64_t power_of_2_max(const int64_t x)
} \
(void)0
#define CLAMP2(vec, b, c) \
{ \
CLAMP((vec)[0], b, c); \
CLAMP((vec)[1], b, c); \
} \
(void)0
#define CLAMP2_MIN(vec, b) \
{ \
CLAMP_MIN((vec)[0], b); \
CLAMP_MIN((vec)[1], b); \
} \
(void)0
#define CLAMP2_MAX(vec, b) \
{ \
CLAMP_MAX((vec)[0], b); \
CLAMP_MAX((vec)[1], b); \
} \
(void)0
#define CLAMP3(vec, b, c) \
{ \
CLAMP((vec)[0], b, c); \
@@ -285,23 +262,6 @@ inline constexpr int64_t power_of_2_max(const int64_t x)
} \
(void)0
#define CLAMP3_MAX(vec, b) \
{ \
CLAMP_MAX((vec)[0], b); \
CLAMP_MAX((vec)[1], b); \
CLAMP_MAX((vec)[2], b); \
} \
(void)0
#define CLAMP4(vec, b, c) \
{ \
CLAMP((vec)[0], b, c); \
CLAMP((vec)[1], b, c); \
CLAMP((vec)[2], b, c); \
CLAMP((vec)[3], b, c); \
} \
(void)0
#define CLAMP4_MIN(vec, b) \
{ \
CLAMP_MIN((vec)[0], b); \
@@ -311,15 +271,6 @@ inline constexpr int64_t power_of_2_max(const int64_t x)
} \
(void)0
#define CLAMP4_MAX(vec, b) \
{ \
CLAMP_MAX((vec)[0], b); \
CLAMP_MAX((vec)[1], b); \
CLAMP_MAX((vec)[2], b); \
CLAMP_MAX((vec)[3], b); \
} \
(void)0
/** \} */
/* -------------------------------------------------------------------- */
+1 -1
View File
@@ -665,7 +665,7 @@ float perlin_ridged_multi_fractal(T p,
for (int i = 1; i <= int(detail); i++) {
p *= lacunarity;
weight = CLAMPIS(signal * gain, 0.0f, 1.0f);
weight = std::clamp(signal * gain, 0.0f, 1.0f);
signal = offset - std::abs(perlin_signed(p));
signal *= signal;
signal *= weight;
@@ -8,6 +8,8 @@
* Creates a solid wireframe from connected faces.
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "DNA_meshdata_types.h"
@@ -154,7 +156,7 @@ void BM_mesh_wireframe(BMesh *bm,
const int defgrp_index,
const bool defgrp_invert,
const short mat_offset,
const short mat_max,
const int mat_max,
/* for operators */
const bool use_tag)
{
@@ -423,7 +425,7 @@ void BM_mesh_wireframe(BMesh *bm,
f_new = BM_face_create_quad_tri(bm, v_l1, v_l2, v_neg2, v_neg1, f_src, BM_CREATE_NOP);
if (mat_offset) {
f_new->mat_nr = CLAMPIS(f_new->mat_nr + mat_offset, 0, mat_max);
f_new->mat_nr = std::clamp(f_new->mat_nr + mat_offset, 0, mat_max);
}
BM_elem_flag_enable(f_new, BM_ELEM_TAG);
l_new = BM_FACE_FIRST_LOOP(f_new);
@@ -436,7 +438,7 @@ void BM_mesh_wireframe(BMesh *bm,
f_new = BM_face_create_quad_tri(bm, v_l2, v_l1, v_pos1, v_pos2, f_src, BM_CREATE_NOP);
if (mat_offset) {
f_new->mat_nr = CLAMPIS(f_new->mat_nr + mat_offset, 0, mat_max);
f_new->mat_nr = std::clamp(f_new->mat_nr + mat_offset, 0, mat_max);
}
BM_elem_flag_enable(f_new, BM_ELEM_TAG);
l_new = BM_FACE_FIRST_LOOP(f_new);
@@ -455,7 +457,7 @@ void BM_mesh_wireframe(BMesh *bm,
f_new = BM_face_create_quad_tri(bm, v_b2, v_b1, v_neg1, v_neg2, f_src, BM_CREATE_NOP);
if (mat_offset) {
f_new->mat_nr = CLAMPIS(f_new->mat_nr + mat_offset, 0, mat_max);
f_new->mat_nr = std::clamp(f_new->mat_nr + mat_offset, 0, mat_max);
}
BM_elem_flag_enable(f_new, BM_ELEM_TAG);
l_new = BM_FACE_FIRST_LOOP(f_new);
@@ -467,7 +469,7 @@ void BM_mesh_wireframe(BMesh *bm,
f_new = BM_face_create_quad_tri(bm, v_b1, v_b2, v_pos2, v_pos1, f_src, BM_CREATE_NOP);
if (mat_offset) {
f_new->mat_nr = CLAMPIS(f_new->mat_nr + mat_offset, 0, mat_max);
f_new->mat_nr = std::clamp(f_new->mat_nr + mat_offset, 0, mat_max);
}
BM_elem_flag_enable(f_new, BM_ELEM_TAG);
l_new = BM_FACE_FIRST_LOOP(f_new);
@@ -29,5 +29,5 @@ void BM_mesh_wireframe(BMesh *bm,
int defgrp_index,
bool defgrp_invert,
short mat_offset,
short mat_max,
int mat_max,
bool use_tag);
@@ -105,7 +105,7 @@ void BoxMaskOperation::update_memory_buffer_partial(MemoryBuffer *output,
break;
case CMP_NODE_MASKTYPE_SUBTRACT:
mask_func = [](const bool is_inside, const float *mask, const float *value) {
return is_inside ? CLAMPIS(mask[0] - value[0], 0, 1) : mask[0];
return is_inside ? std::clamp(mask[0] - value[0], 0.0f, 1.0f) : mask[0];
};
break;
case CMP_NODE_MASKTYPE_MULTIPLY:
@@ -111,7 +111,7 @@ void EllipseMaskOperation::update_memory_buffer_partial(MemoryBuffer *output,
break;
case CMP_NODE_MASKTYPE_SUBTRACT:
mask_func = [](const bool is_inside, const float *mask, const float *value) {
return is_inside ? CLAMPIS(mask[0] - value[0], 0, 1) : mask[0];
return is_inside ? std::clamp(mask[0] - value[0], 0.0f, 1.0f) : mask[0];
};
break;
case CMP_NODE_MASKTYPE_MULTIPLY:
@@ -35,7 +35,7 @@ class MathBaseOperation : public MultiThreadedOperation {
float clamp_when_enabled(float value)
{
if (use_clamp_) {
return CLAMPIS(value, 0.0f, 1.0f);
return std::clamp(value, 0.0f, 1.0f);
}
return value;
}
@@ -308,7 +308,7 @@ void MixColorBurnOperation::update_memory_buffer_row(PixelCursor &p)
}
else {
tmp = 1.0f - (1.0f - p.color1[0]) / tmp;
p.out[0] = CLAMPIS(tmp, 0.0f, 1.0f);
p.out[0] = std::clamp(tmp, 0.0f, 1.0f);
}
tmp = value_m + value * p.color2[1];
@@ -317,7 +317,7 @@ void MixColorBurnOperation::update_memory_buffer_row(PixelCursor &p)
}
else {
tmp = 1.0f - (1.0f - p.color1[1]) / tmp;
p.out[1] = CLAMPIS(tmp, 0.0f, 1.0f);
p.out[1] = std::clamp(tmp, 0.0f, 1.0f);
}
tmp = value_m + value * p.color2[2];
@@ -326,7 +326,7 @@ void MixColorBurnOperation::update_memory_buffer_row(PixelCursor &p)
}
else {
tmp = 1.0f - (1.0f - p.color1[2]) / tmp;
p.out[2] = CLAMPIS(tmp, 0.0f, 1.0f);
p.out[2] = std::clamp(tmp, 0.0f, 1.0f);
}
p.out[3] = p.color1[3];
@@ -100,8 +100,8 @@ static void sample_bilinear_horizontal(T *reader, int x, int y, float xoffset, f
static inline const float *areatex_sample_internal(const float *areatex, int x, int y)
{
return &areatex[(CLAMPIS(x, 0, SMAA_AREATEX_SIZE - 1) +
CLAMPIS(y, 0, SMAA_AREATEX_SIZE - 1) * SMAA_AREATEX_SIZE) *
return &areatex[(std::clamp(x, 0, SMAA_AREATEX_SIZE - 1) +
std::clamp(y, 0, SMAA_AREATEX_SIZE - 1) * SMAA_AREATEX_SIZE) *
2];
}
@@ -948,8 +948,8 @@ void SMAABlendingWeightCalculationOperation::detect_horizontal_corner_pattern(
factor[1] -= rounding * e[0];
}
weights[0] *= CLAMPIS(factor[0], 0.0f, 1.0f);
weights[1] *= CLAMPIS(factor[1], 0.0f, 1.0f);
weights[0] *= std::clamp(factor[0], 0.0f, 1.0f);
weights[1] *= std::clamp(factor[1], 0.0f, 1.0f);
}
void SMAABlendingWeightCalculationOperation::detect_vertical_corner_pattern(
@@ -977,8 +977,8 @@ void SMAABlendingWeightCalculationOperation::detect_vertical_corner_pattern(
factor[1] -= rounding * e[1];
}
weights[0] *= CLAMPIS(factor[0], 0.0f, 1.0f);
weights[1] *= CLAMPIS(factor[1], 0.0f, 1.0f);
weights[0] *= std::clamp(factor[0], 0.0f, 1.0f);
weights[1] *= std::clamp(factor[1], 0.0f, 1.0f);
}
/*-----------------------------------------------------------------------------*/
@@ -21,6 +21,7 @@
#include "BLI_lasso_2d.h"
#include "BLI_math_color.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.hh"
#include "BLI_rand.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
@@ -2893,7 +2894,7 @@ static void gpencil_sbuffer_vertex_color_random(
int ix = int(tpt->m_xy[0] * seed);
int iy = int(tpt->m_xy[1] * seed);
int iz = ix + iy * seed;
float hsv[3];
blender::float3 hsv;
float factor_value[3];
zero_v3(factor_value);
@@ -2960,7 +2961,7 @@ static void gpencil_sbuffer_vertex_color_random(
hsv[0] -= 1.0f;
}
CLAMP3(hsv, 0.0f, 1.0f);
hsv = blender::math::clamp(hsv, 0.0f, 1.0f);
hsv_to_rgb_v(hsv, tpt->vert_color);
}
}
@@ -148,7 +148,7 @@ static int template_search_textbut_width(PointerRNA *ptr, PropertyRNA *name_prop
}
/* Clamp to some min/max width. */
return CLAMPIS(
return std::clamp(
estimated_width, TEMPLATE_SEARCH_TEXTBUT_MIN_WIDTH, TEMPLATE_SEARCH_TEXTBUT_MIN_WIDTH * 3);
}
@@ -966,14 +966,14 @@ static void shape_preset_trias_from_rect_dash(uiWidgetTrias *tria, const rcti *r
static void shadecolors4(
uchar coltop[4], uchar coldown[4], const uchar *color, short shadetop, short shadedown)
{
coltop[0] = CLAMPIS(color[0] + shadetop, 0, 255);
coltop[1] = CLAMPIS(color[1] + shadetop, 0, 255);
coltop[2] = CLAMPIS(color[2] + shadetop, 0, 255);
coltop[0] = std::clamp(color[0] + shadetop, 0, 255);
coltop[1] = std::clamp(color[1] + shadetop, 0, 255);
coltop[2] = std::clamp(color[2] + shadetop, 0, 255);
coltop[3] = color[3];
coldown[0] = CLAMPIS(color[0] + shadedown, 0, 255);
coldown[1] = CLAMPIS(color[1] + shadedown, 0, 255);
coldown[2] = CLAMPIS(color[2] + shadedown, 0, 255);
coldown[0] = std::clamp(color[0] + shadedown, 0, 255);
coldown[1] = std::clamp(color[1] + shadedown, 0, 255);
coldown[2] = std::clamp(color[2] + shadedown, 0, 255);
coldown[3] = color[3];
}
@@ -5218,9 +5218,9 @@ static void ui_draw_popover_back_impl(const uiWidgetColors *wcol,
{
/* Alas, this isn't nice. */
const float unit_half = unit_size / 2;
const float cent_x = mval_origin ? CLAMPIS(mval_origin[0],
rect->xmin + unit_size,
rect->xmax - unit_size) :
const float cent_x = mval_origin ? std::clamp(mval_origin[0],
rect->xmin + unit_size,
rect->xmax - unit_size) :
BLI_rcti_cent_x(rect);
GPU_blend(GPU_BLEND_ALPHA);
@@ -172,7 +172,7 @@ static float edge_pan_speed(View2DEdgePanData *vpd,
/* Zoom factor increases speed when zooming in and decreases speed when zooming out. */
const float zoomx = float(BLI_rcti_size_x(&region->winrct) + 1) /
BLI_rctf_size_x(&region->v2d.cur);
const float zoom_factor = 1.0f + CLAMPIS(vpd->zoom_influence, 0.0f, 1.0f) * (zoomx - 1.0f);
const float zoom_factor = 1.0f + std::clamp(vpd->zoom_influence, 0.0f, 1.0f) * (zoomx - 1.0f);
return distance_factor * delay_factor * zoom_factor * vpd->max_speed * U.widget_unit *
float(UI_SCALE_FAC);
@@ -334,7 +334,7 @@ static bool edbm_bevel_calc(wmOperator *op)
EDBM_redo_state_restore(&opdata->ob_store[ob_index].mesh_backup, em, false);
}
const int material = CLAMPIS(material_init, -1, obedit->totcol - 1);
const int material = std::clamp(material_init, -1, obedit->totcol - 1);
EDBM_op_init(em,
&bmop,
@@ -9,6 +9,8 @@
* an experimental tool for quickly constructing/manipulating faces.
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "DNA_object_types.h"
@@ -312,7 +314,7 @@ static int edbm_polybuild_face_at_cursor_invoke(bContext *C, wmOperator *op, con
mul_m4_v3(vc.obedit->world_to_object, center);
if (f_reference->len == 3 && RNA_boolean_get(op->ptr, "create_quads")) {
const float fac = line_point_factor_v3(center, e_act->v1->co, e_act->v2->co);
BMVert *v_new = BM_edge_split(bm, e_act, e_act->v1, nullptr, CLAMPIS(fac, 0.0f, 1.0f));
BMVert *v_new = BM_edge_split(bm, e_act, e_act->v1, nullptr, std::clamp(fac, 0.0f, 1.0f));
copy_v3_v3(v_new->co, center);
edbm_flag_disable_all_multi(vc.scene, vc.view_layer, vc.v3d, BM_ELEM_SELECT);
BM_vert_select_set(bm, v_new, true);
@@ -477,7 +479,7 @@ static int edbm_polybuild_split_at_cursor_invoke(bContext *C,
mul_m4_v3(vc.obedit->world_to_object, center);
const float fac = line_point_factor_v3(center, e_act->v1->co, e_act->v2->co);
BMVert *v_new = BM_edge_split(bm, e_act, e_act->v1, nullptr, CLAMPIS(fac, 0.0f, 1.0f));
BMVert *v_new = BM_edge_split(bm, e_act, e_act->v1, nullptr, std::clamp(fac, 0.0f, 1.0f));
copy_v3_v3(v_new->co, center);
edbm_flag_disable_all_multi(vc.scene, vc.view_layer, vc.v3d, BM_ELEM_SELECT);
@@ -6,6 +6,7 @@
* \ingroup edsculpt
*/
#include <algorithm>
#include <cfloat>
#include <cmath>
@@ -1160,7 +1161,7 @@ static void paint_stroke_add_sample(
const Paint *paint, PaintStroke *stroke, float x, float y, float pressure)
{
PaintSample *sample = &stroke->samples[stroke->cur_sample];
int max_samples = CLAMPIS(paint->num_input_samples, 1, PAINT_MAX_INPUT_SAMPLES);
int max_samples = std::clamp(paint->num_input_samples, 1, PAINT_MAX_INPUT_SAMPLES);
sample->mouse[0] = x;
sample->mouse[1] = y;
@@ -10,6 +10,7 @@
#include "BLI_math_color.h"
#include "BLI_math_color_blend.h"
#include "BLI_math_vector.hh"
#include "BLI_task.h"
#include "BLT_translation.h"
@@ -92,7 +93,9 @@ static void color_filter_task(Object *ob,
SCULPT_orig_vert_data_update(&orig_data, &vd);
auto_mask::node_update(automask_data, vd);
float orig_color[3], final_color[4], hsv_color[3];
float3 orig_color;
float4 final_color;
float3 hsv_color;
int hue;
float brightness, contrast, gain, delta, offset;
float fade = vd.mask;
@@ -209,7 +212,7 @@ static void color_filter_task(Object *ob,
blend_color_interpolate_float(final_color, col, smooth_color, fade);
}
CLAMP4(final_color, 0.0f, 1.0f);
final_color = math::clamp(final_color, 0.0f, 1.0f);
/* Prevent accumulated numeric error from corrupting alpha. */
if (copy_alpha) {
@@ -529,7 +529,7 @@ struct StrokeCache {
float4x4 stroke_local_mat;
float multiplane_scrape_angle;
float wet_mix_prev_color[4];
float4 wet_mix_prev_color;
float density_seed;
rcti previous_r; /* previous redraw rectangle */
@@ -12,6 +12,7 @@
#include "BLI_hash.h"
#include "BLI_math_color_blend.h"
#include "BLI_math_vector.hh"
#include "BLI_task.h"
#include "BLI_vector.hh"
@@ -192,10 +193,10 @@ static void do_paint_brush_task(Object *ob,
ss->cache->automasking.get(), ss, vd.vertex, &automask_data);
mul_v4_v4fl(buffer_color, color_buffer->color[vd.i], brush->alpha * automasking);
float col[4];
float4 col;
SCULPT_vertex_color_get(ss, vd.vertex, col);
IMB_blend_color_float(col, orig_data.col, buffer_color, IMB_BlendMode(brush->blend));
CLAMP4(col, 0.0f, 1.0f);
col = math::clamp(col, 0.0f, 1.0f);
SCULPT_vertex_color_set(ss, vd.vertex, col);
}
BKE_pbvh_vertex_iter_end;
@@ -286,7 +287,7 @@ void do_paint_brush(PaintModeSettings *paint_mode_settings,
/* Regular Paint mode. */
/* Wet paint color sampling. */
float wet_color[4] = {0.0f};
float4 wet_color(0);
if (ss->cache->paint_brush.wet_mix > 0.0f) {
const SampleWetPaintData swptd = threading::parallel_reduce(
nodes.index_range(),
@@ -308,7 +309,7 @@ void do_paint_brush(PaintModeSettings *paint_mode_settings,
if (swptd.tot_samples > 0 && is_finite_v4(swptd.color)) {
copy_v4_v4(wet_color, swptd.color);
mul_v4_fl(wet_color, 1.0f / swptd.tot_samples);
CLAMP4(wet_color, 0.0f, 1.0f);
wet_color = math::clamp(wet_color, 0.0f, 1.0f);
if (ss->cache->first_time) {
copy_v4_v4(ss->cache->wet_mix_prev_color, wet_color);
@@ -318,7 +319,7 @@ void do_paint_brush(PaintModeSettings *paint_mode_settings,
ss->cache->wet_mix_prev_color,
ss->cache->paint_brush.wet_persistence);
copy_v4_v4(ss->cache->wet_mix_prev_color, wet_color);
CLAMP4(ss->cache->wet_mix_prev_color, 0.0f, 1.0f);
ss->cache->wet_mix_prev_color == math::clamp(ss->cache->wet_mix_prev_color, 0.0f, 1.0f);
}
}
@@ -6,6 +6,8 @@
* \ingroup spinfo
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLF_api.h"
@@ -325,10 +327,10 @@ int textview_draw(TextViewContext *tvc,
const int mval[2] = {
(mval_init[0] == INT_MAX) ?
INT_MAX :
CLAMPIS(mval_init[0], tvc->draw_rect.xmin, tvc->draw_rect.xmax) - tvc->draw_rect.xmin,
std::clamp(mval_init[0], tvc->draw_rect.xmin, tvc->draw_rect.xmax) - tvc->draw_rect.xmin,
(mval_init[1] == INT_MAX) ?
INT_MAX :
CLAMPIS(mval_init[1], tvc->draw_rect.ymin, tvc->draw_rect.ymax) + tvc->scroll_ymin,
std::clamp(mval_init[1], tvc->draw_rect.ymin, tvc->draw_rect.ymax) + tvc->scroll_ymin,
};
if (r_mval_pick_offset != nullptr) {
@@ -3340,7 +3340,7 @@ static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *ev
if (event->type == TIMER) {
text_cursor_set_to_pos(
st, region, CLAMPIS(event->mval[0], 0, region->winx), event->mval[1], true);
st, region, std::clamp(event->mval[0], 0, int(region->winx)), event->mval[1], true);
ED_space_text_scroll_to_cursor(st, region, false);
WM_event_add_notifier(C, NC_TEXT | ND_CURSOR, st->text);
}
@@ -6,6 +6,7 @@
* \ingroup edtransform
*/
#include <algorithm>
#include <cstdlib>
#include "MEM_guardedalloc.h"
@@ -84,7 +85,7 @@ static void applyTimeSlideValue(TransInfo *t, float sval, float cval)
/* only apply to data if in range */
if ((sval > minx) && (sval < maxx)) {
float cvalc = CLAMPIS(cval, minx, maxx);
float cvalc = std::clamp(cval, minx, maxx);
float timefac;
float *dst;
float ival;
@@ -11,6 +11,7 @@
#include "BLI_math_color.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "DNA_gpencil_legacy_types.h"
#include "DNA_material_types.h"
@@ -287,11 +288,11 @@ void GpencilExporterPDF::color_set(bGPDlayer *gpl, const bool do_fill)
HPDF_Page_GSave(page_);
HPDF_ExtGState gstate = (need_state) ? HPDF_CreateExtGState(pdf_) : nullptr;
float col[3];
float3 col;
if (do_fill) {
interp_v3_v3v3(col, fill_color_, gpl->tintcolor, gpl->tintcolor[3]);
linearrgb_to_srgb_v3_v3(col, col);
CLAMP3(col, 0.0f, 1.0f);
col = math::clamp(col, 0.0f, 1.0f);
HPDF_Page_SetRGBFill(page_, col[0], col[1], col[2]);
if (gstate) {
HPDF_ExtGState_SetAlphaFill(gstate, clamp_f(fill_opacity, 0.0f, 1.0f));
@@ -300,7 +301,7 @@ void GpencilExporterPDF::color_set(bGPDlayer *gpl, const bool do_fill)
else {
interp_v3_v3v3(col, stroke_color_, gpl->tintcolor, gpl->tintcolor[3]);
linearrgb_to_srgb_v3_v3(col, col);
CLAMP3(col, 0.0f, 1.0f);
col = math::clamp(col, 0.0f, 1.0f);
HPDF_Page_SetRGBFill(page_, col[0], col[1], col[2]);
HPDF_Page_SetRGBStroke(page_, col[0], col[1], col[2]);
+6 -5
View File
@@ -1101,10 +1101,10 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
if (iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX || iprop->range) {
if (array) {
fprintf(f, "CLAMPIS(values[i], ");
fprintf(f, "std::clamp(values[i], ");
}
else {
fprintf(f, "CLAMPIS(value, ");
fprintf(f, "std::clamp(value, ");
}
if (iprop->range) {
fprintf(f, "prop_clamp_min, prop_clamp_max);\n");
@@ -1123,10 +1123,10 @@ static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
if (fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX || fprop->range) {
if (array) {
fprintf(f, "CLAMPIS(values[i], ");
fprintf(f, "std::clamp(values[i], ");
}
else {
fprintf(f, "CLAMPIS(value, ");
fprintf(f, "std::clamp(value, ");
}
if (fprop->range) {
fprintf(f, "prop_clamp_min, prop_clamp_max);\n");
@@ -1466,7 +1466,7 @@ static char *rna_def_property_set_func(
/* C++ may require casting to an enum type. */
fprintf(f, "#ifdef __cplusplus\n");
fprintf(f,
/* If #rna_clamp_value() adds an expression like `CLAMPIS(...)`
/* If #rna_clamp_value() adds an expression like `std::clamp(...)`
* (instead of an `lvalue`), #decltype() yields a reference,
* so that has to be removed. */
" data->%s = %s(std::remove_reference_t<decltype(data->%s)>)",
@@ -4848,6 +4848,7 @@ static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const
fprintf(f, "#include <limits>\n");
fprintf(f, "#include <string.h>\n\n");
fprintf(f, "#include <stddef.h>\n\n");
fprintf(f, "#include <algorithm>\n\n");
fprintf(f, "#include \"MEM_guardedalloc.h\"\n\n");
+4 -2
View File
@@ -183,6 +183,8 @@ static const EnumPropertyItem rna_enum_driver_target_context_property_items[] =
#ifdef RNA_RUNTIME
# include <algorithm>
# include "WM_api.hh"
static StructRNA *rna_FModifierType_refine(PointerRNA *ptr)
@@ -1026,7 +1028,7 @@ static void rna_FModifierStepped_frame_start_set(PointerRNA *ptr, float value)
float prop_clamp_min = -FLT_MAX, prop_clamp_max = FLT_MAX, prop_soft_min, prop_soft_max;
rna_FModifierStepped_start_frame_range(
ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);
value = CLAMPIS(value, prop_clamp_min, prop_clamp_max);
value = std::clamp(value, prop_clamp_min, prop_clamp_max);
/* Need to set both step-data's start/end and the start/end on the base-data,
* or else Restrict-Range doesn't work due to RNA-property shadowing (#52009)
@@ -1043,7 +1045,7 @@ static void rna_FModifierStepped_frame_end_set(PointerRNA *ptr, float value)
float prop_clamp_min = -FLT_MAX, prop_clamp_max = FLT_MAX, prop_soft_min, prop_soft_max;
rna_FModifierStepped_end_frame_range(
ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);
value = CLAMPIS(value, prop_clamp_min, prop_clamp_max);
value = std::clamp(value, prop_clamp_min, prop_clamp_max);
/* Need to set both step-data's start/end and the start/end on the base-data,
* or else Restrict-Range doesn't work due to RNA-property shadowing (#52009)
+5 -3
View File
@@ -53,6 +53,8 @@ static const EnumPropertyItem image_source_items[] = {
#ifdef RNA_RUNTIME
# include <algorithm>
# include "BLI_math_base.h"
# include "BLI_math_vector.h"
@@ -132,7 +134,7 @@ static void rna_Image_generated_width_set(PointerRNA *ptr, int value)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
base_tile->gen_x = CLAMPIS(value, 1, 65536);
base_tile->gen_x = std::clamp(value, 1, 65536);
}
static int rna_Image_generated_height_get(PointerRNA *ptr)
@@ -146,7 +148,7 @@ static void rna_Image_generated_height_set(PointerRNA *ptr, int value)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
base_tile->gen_y = CLAMPIS(value, 1, 65536);
base_tile->gen_y = std::clamp(value, 1, 65536);
}
static bool rna_Image_generated_float_get(PointerRNA *ptr)
@@ -180,7 +182,7 @@ void rna_Image_generated_color_set(PointerRNA *ptr, const float values[4])
Image *ima = (Image *)(ptr->data);
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
for (uint i = 0; i < 4; i++) {
base_tile->gen_color[i] = CLAMPIS(values[i], 0.0f, FLT_MAX);
base_tile->gen_color[i] = std::clamp(values[i], 0.0f, FLT_MAX);
}
}
@@ -22,6 +22,8 @@
#ifdef RNA_RUNTIME
# include <algorithm>
# include "DNA_object_types.h"
# include "DNA_scene_types.h"
@@ -184,21 +186,21 @@ static void rna_Lattice_points_u_set(PointerRNA *ptr, int value)
{
Lattice *lt = (Lattice *)ptr->data;
lt->opntsu = CLAMPIS(value, 1, 64);
lt->opntsu = std::clamp(value, 1, 64);
}
static void rna_Lattice_points_v_set(PointerRNA *ptr, int value)
{
Lattice *lt = (Lattice *)ptr->data;
lt->opntsv = CLAMPIS(value, 1, 64);
lt->opntsv = std::clamp(value, 1, 64);
}
static void rna_Lattice_points_w_set(PointerRNA *ptr, int value)
{
Lattice *lt = (Lattice *)ptr->data;
lt->opntsw = CLAMPIS(value, 1, 64);
lt->opntsw = std::clamp(value, 1, 64);
}
static void rna_Lattice_vg_name_set(PointerRNA *ptr, const char *value)
@@ -687,6 +687,9 @@ const EnumPropertyItem rna_enum_subdivision_boundary_smooth_items[] = {
};
#ifdef RNA_RUNTIME
# include <algorithm>
# include "DNA_curve_types.h"
# include "DNA_fluid_types.h"
# include "DNA_material_types.h"
@@ -1178,7 +1181,7 @@ static void rna_UVProjectModifier_num_projectors_set(PointerRNA *ptr, int value)
UVProjectModifierData *md = (UVProjectModifierData *)ptr->data;
int a;
md->projectors_num = CLAMPIS(value, 1, MOD_UVPROJECT_MAXPROJECTORS);
md->projectors_num = std::clamp(value, 1, MOD_UVPROJECT_MAXPROJECTORS);
for (a = md->projectors_num; a < MOD_UVPROJECT_MAXPROJECTORS; a++) {
md->projectors[a] = nullptr;
}
+4 -2
View File
@@ -538,6 +538,8 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = {
#ifdef RNA_RUNTIME
# include <algorithm>
# include "AS_asset_representation.hh"
# include "DNA_anim_types.h"
@@ -1900,7 +1902,7 @@ static void rna_SpaceUVEditor_tile_grid_shape_set(PointerRNA *ptr, const int *va
int clamp[2] = {10, 100};
for (int i = 0; i < 2; i++) {
data->tile_grid_shape[i] = CLAMPIS(values[i], 1, clamp[i]);
data->tile_grid_shape[i] = std::clamp(values[i], 1, clamp[i]);
}
}
@@ -1909,7 +1911,7 @@ static void rna_SpaceUVEditor_custom_grid_subdiv_set(PointerRNA *ptr, const int
SpaceImage *data = (SpaceImage *)(ptr->data);
for (int i = 0; i < 2; i++) {
data->custom_grid_subdiv[i] = CLAMPIS(values[i], 1, 5000);
data->custom_grid_subdiv[i] = std::clamp(values[i], 1, 5000);
}
}
+3 -1
View File
@@ -6,6 +6,8 @@
* \ingroup modifiers
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLI_math_vector.h"
@@ -95,7 +97,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh
const int offset_type = bmd->val_flags;
const int profile_type = bmd->profile_type;
const float value = bmd->value;
const int mat = CLAMPIS(bmd->mat, -1, ctx->object->totcol - 1);
const int mat = std::clamp(int(bmd->mat), -1, ctx->object->totcol - 1);
const bool loop_slide = (bmd->flags & MOD_BEVEL_EVEN_WIDTHS) == 0;
const bool mark_seam = (bmd->edge_flags & MOD_BEVEL_MARK_SEAM);
const bool mark_sharp = (bmd->edge_flags & MOD_BEVEL_MARK_SHARP);
@@ -6,6 +6,7 @@
* \ingroup modifiers
*/
#include <algorithm>
#include <cerrno>
#include <cstdio>
#include <cstring>
@@ -300,7 +301,7 @@ bool MOD_meshcache_read_mdd_times(const char *filepath,
return false;
}
frame = CLAMPIS(time, 0.0f, 1.0f) * float(mdd_head.frame_tot);
frame = std::clamp(time, 0.0f, 1.0f) * float(mdd_head.frame_tot);
rewind(fp);
break;
}
@@ -6,6 +6,7 @@
* \ingroup modifiers
*/
#include <algorithm>
#include <cerrno>
#include <cstdio>
#include <cstring>
@@ -269,7 +270,7 @@ bool MOD_meshcache_read_pc2_times(const char *filepath,
return false;
}
frame = CLAMPIS(time, 0.0f, 1.0f) * float(pc2_head.frame_tot);
frame = std::clamp(time, 0.0f, 1.0f) * float(pc2_head.frame_tot);
rewind(fp);
break;
}
@@ -6,6 +6,8 @@
* \ingroup texnodes
*/
#include <algorithm>
#include "BKE_colortools.hh"
#include "NOD_texture.h"
#include "node_texture_util.hh"
@@ -29,7 +31,7 @@ static void time_colorfn(
CurveMapping *mapping = static_cast<CurveMapping *>(node->storage);
BKE_curvemapping_init(mapping);
fac = BKE_curvemapping_evaluateF(mapping, 0, fac);
out[0] = CLAMPIS(fac, 0.0f, 1.0f);
out[0] = std::clamp(fac, 0.0f, 1.0f);
}
static void time_exec(void *data,
@@ -780,8 +780,8 @@ static void area_sample(TexResult *texr, ImBuf *ibuf, float fx, float fy, const
int xsam = int(0.5f * sqrtf(ux * ux + uy * uy) + 0.5f);
int ysam = int(0.5f * sqrtf(vx * vx + vy * vy) + 0.5f);
const int minsam = AFD->intpol ? 2 : 4;
xsam = CLAMPIS(xsam, minsam, ibuf->x * 2);
ysam = CLAMPIS(ysam, minsam, ibuf->y * 2);
xsam = std::clamp(xsam, minsam, ibuf->x * 2);
ysam = std::clamp(ysam, minsam, ibuf->y * 2);
xsd = 1.0f / xsam;
ysd = 1.0f / ysam;
texr->trgba[0] = texr->trgba[1] = texr->trgba[2] = texr->trgba[3] = 0.0f;
@@ -6,6 +6,8 @@
* \ingroup sim
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "DNA_cloth_types.h"
@@ -1057,7 +1059,7 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt)
interp_v3_v3v3(col,
col0,
col1,
CLAMPIS(gdensity * clmd->sim_parms->density_strength, 0.0, 1.0));
std::clamp(gdensity * clmd->sim_parms->density_strength, 0.0, 1.0));
# if 0
BKE_sim_debug_data_add_circle(clmd->debug_data,
x,
@@ -6,6 +6,8 @@
* \ingroup sim
*/
#include <algorithm>
#include "MEM_guardedalloc.h"
#include "BLI_math_matrix.h"
@@ -544,7 +546,7 @@ void SIM_hair_volume_add_segment(HairGrid *grid,
float shift1, shift2; /* fraction of a full cell shift [0.0, 1.0) */
int jmin, jmax, kmin, kmax;
h = CLAMPIS(float(i), start0, end0);
h = std::clamp(float(i), start0, end0);
shift1 = start1 + (h - start0) * inc1;
shift2 = start2 + (h - start0) * inc2;
@@ -810,11 +812,11 @@ bool SIM_hair_volume_solve_divergence(HairGrid *grid,
grid_to_world(grid, wloc, loc);
if (divergence > 0.0f) {
fac = CLAMPIS(divergence * target_strength, 0.0, 1.0);
fac = std::clamp(divergence * target_strength, 0.0, 1.0);
interp_v3_v3v3(col, col0, colp, fac);
}
else {
fac = CLAMPIS(-divergence * target_strength, 0.0, 1.0);
fac = std::clamp(-divergence * target_strength, 0.0, 1.0);
interp_v3_v3v3(col, col0, coln, fac);
}
if (fac > 0.05f) {
@@ -977,11 +979,11 @@ bool SIM_hair_volume_solve_divergence(HairGrid *grid,
float pressure = p[u];
if (pressure > 0.0f) {
fac = CLAMPIS(pressure * grid->debug1, 0.0, 1.0);
fac = std::clamp(pressure * grid->debug1, 0.0, 1.0);
interp_v3_v3v3(col, col0, colp, fac);
}
else {
fac = CLAMPIS(-pressure * grid->debug1, 0.0, 1.0);
fac = std::clamp(-pressure * grid->debug1, 0.0, 1.0);
interp_v3_v3v3(col, col0, coln, fac);
}
if (fac > 0.05f) {
@@ -999,7 +1001,7 @@ bool SIM_hair_volume_solve_divergence(HairGrid *grid,
}
if (!is_margin) {
float d = CLAMPIS(vert->density * grid->debug2, 0.0f, 1.0f);
float d = std::clamp(vert->density * grid->debug2, 0.0f, 1.0f);
float col0[3] = {0.3, 0.3, 0.3};
float colp[3] = {0.0, 0.0, 1.0};
float col[3];