Cleanup: Replace ABS/SQUARE/CUBE with function calls

While it might be handy to have type-less functionality which is
similar to how C++ math is implemented it can not be easily achieved
with just preprocessor in a way which does not have side-effects on
wrong usage.

There macros where often used on a non-trivial expression, and there
was at least one usage where it was causing an actual side effect/bug
on Windows (see change around square_f(sh[index++]) in studiolight.c).

For such cases it is handy to have a function which is guaranteed to
have zero side-effects. The motivation behind actually removing the
macros is that there is already a way to do similar calculation. Also,
not having such macros is a way to guarantee that its usage is not
changed in a way which have side-effects and that it's not used as an
inspiration for cases where it should not be used.

Differential Revision: https://developer.blender.org/D7051
This commit is contained in:
Sergey Sharybin 2020-03-06 17:18:10 +01:00
parent ee5d7bc16b
commit 598ab525da
67 changed files with 256 additions and 186 deletions

View File

@ -1579,7 +1579,7 @@ void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2],
do {
rand_pos[0] = BLI_rng_get_float(brush_rng) - 0.5f;
rand_pos[1] = BLI_rng_get_float(brush_rng) - 0.5f;
} while (len_squared_v2(rand_pos) > SQUARE(0.5f));
} while (len_squared_v2(rand_pos) > square_f(0.5f));
if (brush->flag & BRUSH_ABSOLUTE_JITTER) {
diameter = 2 * brush->jitter_absolute;

View File

@ -375,7 +375,7 @@ static void mesh_edges_spherecast(void *userdata,
const MVert *vert = data->vert;
const MEdge *edge = &data->edge[index];
const float radius_sq = SQUARE(ray->radius);
const float radius_sq = square_f(ray->radius);
float dist;
const float *v1, *v2, *r1;
float r2[3], i1[3], i2[3];

View File

@ -625,7 +625,7 @@ static void collision_compute_barycentric(const float pv[3],
d = (a * c - b * b);
if (ABS(d) < (double)ALMOST_ZERO) {
if (fabs(d) < (double)ALMOST_ZERO) {
*w1 = *w2 = *w3 = 1.0 / 3.0;
return;
}
@ -856,18 +856,18 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
for (int j = 0; j < 3; j++) {
if (cloth1->verts[collpair->ap1].impulse_count > 0 &&
ABS(cloth1->verts[collpair->ap1].impulse[j]) < ABS(i1[j])) {
fabsf(cloth1->verts[collpair->ap1].impulse[j]) < fabsf(i1[j])) {
cloth1->verts[collpair->ap1].impulse[j] = i1[j];
}
if (cloth1->verts[collpair->ap2].impulse_count > 0 &&
ABS(cloth1->verts[collpair->ap2].impulse[j]) < ABS(i2[j])) {
fabsf(cloth1->verts[collpair->ap2].impulse[j]) < fabsf(i2[j])) {
cloth1->verts[collpair->ap2].impulse[j] = i2[j];
}
if (!is_hair) {
if (cloth1->verts[collpair->ap3].impulse_count > 0 &&
ABS(cloth1->verts[collpair->ap3].impulse[j]) < ABS(i3[j])) {
fabsf(cloth1->verts[collpair->ap3].impulse[j]) < fabsf(i3[j])) {
cloth1->verts[collpair->ap3].impulse[j] = i3[j];
}
}
@ -888,15 +888,15 @@ static void cloth_selfcollision_impulse_vert(const float clamp_sq,
return;
}
if (ABS(vert->impulse[0]) < ABS(impulse[0])) {
if (fabsf(vert->impulse[0]) < fabsf(impulse[0])) {
vert->impulse[0] = impulse[0];
}
if (ABS(vert->impulse[1]) < ABS(impulse[1])) {
if (fabsf(vert->impulse[1]) < fabsf(impulse[1])) {
vert->impulse[1] = impulse[1];
}
if (ABS(vert->impulse[2]) < ABS(impulse[2])) {
if (fabsf(vert->impulse[2]) < fabsf(impulse[2])) {
vert->impulse[2] = impulse[2];
}

View File

@ -485,7 +485,7 @@ static void contarget_get_mesh_mat(Object *ob, const char *substring, float mat[
copy_v3_v3(plane, tmat[1]);
cross_v3_v3v3(mat[0], normal, plane);
if (len_squared_v3(mat[0]) < SQUARE(1e-3f)) {
if (len_squared_v3(mat[0]) < square_f(1e-3f)) {
copy_v3_v3(plane, tmat[0]);
cross_v3_v3v3(mat[0], normal, plane);
}

View File

@ -2705,7 +2705,7 @@ static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceDa
/* Check if it's close enough to likely touch the intended triangle. Any triangle
* becomes thinner than a pixel at its vertices, so robustness requires some margin. */
const float final_pt[2] = {((final_index % w) + 0.5f) / w, ((final_index / w) + 0.5f) / h};
const float threshold = SQUARE(0.7f) / (w * h);
const float threshold = square_f(0.7f) / (w * h);
if (dist_squared_to_looptri_uv_edges(
mlooptri, mloopuv, tempPoints[final_index].tri_index, final_pt) > threshold) {

View File

@ -570,7 +570,7 @@ float effector_falloff(EffectorCache *eff,
break;
case PFIELD_FALL_TUBE:
falloff *= falloff_func_dist(eff->pd, ABS(fac));
falloff *= falloff_func_dist(eff->pd, fabsf(fac));
if (falloff == 0.0f) {
break;
}
@ -580,7 +580,7 @@ float effector_falloff(EffectorCache *eff,
falloff *= falloff_func_rad(eff->pd, r_fac);
break;
case PFIELD_FALL_CONE:
falloff *= falloff_func_dist(eff->pd, ABS(fac));
falloff *= falloff_func_dist(eff->pd, fabsf(fac));
if (falloff == 0.0f) {
break;
}

View File

@ -1546,7 +1546,7 @@ static float dvar_eval_rotDiff(ChannelDriver *driver, DriverVar *dvar)
invert_qt_normalized(q1);
mul_qt_qtqt(quat, q1, q2);
angle = 2.0f * (saacos(quat[0]));
angle = ABS(angle);
angle = fabsf(angle);
return (angle > (float)M_PI) ? (float)((2.0f * (float)M_PI) - angle) : (float)(angle);
}

View File

@ -398,7 +398,7 @@ float BKE_mask_spline_project_co(MaskSpline *spline,
float u = -1.0f, du = 1.0f / N, u1 = start_u, u2 = start_u;
float ang = -1.0f;
BLI_assert(ABS(sign) <= 1); /* (-1, 0, 1) */
BLI_assert(abs(sign) <= 1); /* (-1, 0, 1) */
while (u1 > 0.0f || u2 < 1.0f) {
float n1[2], n2[2], co1[2], co2[2];

View File

@ -341,8 +341,8 @@ static int customdata_compare(
int ltot = m1->totloop;
for (j = 0; j < ltot; j++, lp1++, lp2++) {
if (ABS(lp1->r - lp2->r) > thresh || ABS(lp1->g - lp2->g) > thresh ||
ABS(lp1->b - lp2->b) > thresh || ABS(lp1->a - lp2->a) > thresh) {
if (abs(lp1->r - lp2->r) > thresh || abs(lp1->g - lp2->g) > thresh ||
abs(lp1->b - lp2->b) > thresh || abs(lp1->a - lp2->a) > thresh) {
return MESHCMP_LOOPCOLMISMATCH;
}
}

View File

@ -121,7 +121,7 @@ static BLI_bitmap *multires_mdisps_upsample_hidden(BLI_bitmap *lo_hidden,
return MEM_dupallocN(lo_hidden);
}
subd = BLI_BITMAP_NEW(SQUARE(hi_gridsize), "MDisps.hidden upsample");
subd = BLI_BITMAP_NEW(square_i(hi_gridsize), "MDisps.hidden upsample");
factor = BKE_ccg_factor(lo_level, hi_level);
offset = 1 << (hi_level - lo_level - 1);
@ -179,7 +179,7 @@ static BLI_bitmap *multires_mdisps_downsample_hidden(BLI_bitmap *old_hidden,
BLI_assert(new_level <= old_level);
factor = BKE_ccg_factor(new_level, old_level);
new_hidden = BLI_BITMAP_NEW(SQUARE(new_gridsize), "downsample hidden");
new_hidden = BLI_BITMAP_NEW(square_i(new_gridsize), "downsample hidden");
for (y = 0; y < new_gridsize; y++) {
for (x = 0; x < new_gridsize; x++) {
@ -238,7 +238,7 @@ static MDisps *multires_mdisps_initialize_hidden(Mesh *me, int level)
{
MDisps *mdisps = CustomData_add_layer(&me->ldata, CD_MDISPS, CD_CALLOC, NULL, me->totloop);
int gridsize = BKE_ccg_gridsize(level);
int gridarea = SQUARE(gridsize);
int gridarea = square_i(gridsize);
int i, j;
for (i = 0; i < me->totpoly; i++) {
@ -622,7 +622,7 @@ static void multires_grid_paint_mask_downsample(GridPaintMask *gpm, int level)
if (level < gpm->level) {
int gridsize = BKE_ccg_gridsize(level);
float *data = MEM_calloc_arrayN(
SQUARE(gridsize), sizeof(float), "multires_grid_paint_mask_downsample");
square_i(gridsize), sizeof(float), "multires_grid_paint_mask_downsample");
int x, y;
for (y = 0; y < gridsize; y++) {

View File

@ -872,7 +872,7 @@ static void long_edge_queue_edge_add(EdgeQueueContext *eq_ctx, BMEdge *e)
static void long_edge_queue_edge_add_recursive(
EdgeQueueContext *eq_ctx, BMLoop *l_edge, BMLoop *l_end, const float len_sq, float limit_len)
{
BLI_assert(len_sq > SQUARE(limit_len));
BLI_assert(len_sq > square_f(limit_len));
# ifdef USE_EDGEQUEUE_FRONTFACE
if (eq_ctx->q->use_view_normal) {
@ -905,7 +905,7 @@ static void long_edge_queue_edge_add_recursive(
const float len_sq_cmp = len_sq * EVEN_EDGELEN_THRESHOLD;
limit_len *= EVEN_GENERATION_SCALE;
const float limit_len_sq = SQUARE(limit_len);
const float limit_len_sq = square_f(limit_len);
BMLoop *l_iter = l_edge;
do {

View File

@ -1118,7 +1118,7 @@ static int sb_detect_face_pointCached(float face_v1[3],
/* origin to face_v2*/
sub_v3_v3(nv1, face_v2);
facedist = dot_v3v3(nv1, d_nvect);
if (ABS(facedist) < outerfacethickness) {
if (fabsf(facedist) < outerfacethickness) {
if (isect_point_tri_prism_v3(nv1, face_v1, face_v2, face_v3)) {
float df;
if (facedist > 0) {
@ -2020,7 +2020,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene,
sub_v3_v3v3(def, bp->pos, obp->pos);
/* rather check the AABBoxes before ever calculating the real distance */
/* mathematically it is completely nuts, but performance is pretty much (3) times faster */
if ((ABS(def[0]) > compare) || (ABS(def[1]) > compare) || (ABS(def[2]) > compare)) {
if ((fabsf(def[0]) > compare) || (fabsf(def[1]) > compare) || (fabsf(def[2]) > compare)) {
continue;
}
distance = normalize_v3(def);
@ -3414,7 +3414,7 @@ static void softbody_step(
}
forcetime = forcetimemax; /* hope for integrating in one step */
while ((ABS(timedone) < ABS(dtime)) && (loops < 2000)) {
while ((fabsf(timedone) < fabsf(dtime)) && (loops < 2000)) {
/* set goals in time */
interpolate_exciter(ob, 200, (int)(200.0f * (timedone / dtime)));

View File

@ -609,8 +609,8 @@ static void studiolight_calculate_radiance_cubemap_buffers(StudioLight *sl)
BKE_studiolight_ensure_flag(sl, STUDIOLIGHT_EXTERNAL_IMAGE_LOADED);
ImBuf *ibuf = sl->equirect_radiance_buffer;
if (ibuf) {
float *colbuf = MEM_mallocN(SQUARE(STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE) * sizeof(float[4]),
__func__);
float *colbuf = MEM_malloc_arrayN(
square_i(STUDIOLIGHT_RADIANCE_CUBEMAP_SIZE), sizeof(float[4]), __func__);
/* front */
studiolight_calculate_radiance_buffer(ibuf, colbuf, 0, 2, 1, 1, -1, 1);
@ -772,11 +772,11 @@ static float studiolight_spherical_harmonics_lambda_get(float *sh, float max_lap
table_b[0] = 0.0f;
int index = 1;
for (int level = 1; level < STUDIOLIGHT_SH_BANDS; level++) {
table_l[level] = (float)(SQUARE(level) * SQUARE(level + 1));
table_l[level] = (float)(square_i(level) * square_i(level + 1));
float b = 0.0f;
for (int m = -1; m <= level; m++) {
b += SQUARE(sh[index++]);
b += square_f(sh[index++]);
}
table_b[level] = b;
}
@ -797,9 +797,9 @@ static float studiolight_spherical_harmonics_lambda_get(float *sh, float max_lap
float fd = 0.0f;
for (int level = 1; level < STUDIOLIGHT_SH_BANDS; level++) {
f += table_l[level] * table_b[level] / SQUARE(1.0f + lambda * table_l[level]);
fd += (2.0f * SQUARE(table_l[level]) * table_b[level]) /
CUBE(1.0f + lambda * table_l[level]);
f += table_l[level] * table_b[level] / square_f(1.0f + lambda * table_l[level]);
fd += (2.0f * square_f(table_l[level]) * table_b[level]) /
cube_f(1.0f + lambda * table_l[level]);
}
f = target_squared_laplacian - f;
@ -807,7 +807,7 @@ static float studiolight_spherical_harmonics_lambda_get(float *sh, float max_lap
float delta = -f / fd;
lambda += delta;
if (ABS(delta) < 1e-6f) {
if (fabsf(delta) < 1e-6f) {
break;
}
}
@ -837,9 +837,11 @@ static void studiolight_spherical_harmonics_apply_windowing(float (*sh)[3], floa
int index = 0;
for (int level = 0; level < STUDIOLIGHT_SH_BANDS; level++) {
float s[3];
s[0] = 1.0f / (1.0f + lambda_r * SQUARE(level) * SQUARE(level + 1.0f));
s[1] = 1.0f / (1.0f + lambda_g * SQUARE(level) * SQUARE(level + 1.0f));
s[2] = 1.0f / (1.0f + lambda_b * SQUARE(level) * SQUARE(level + 1.0f));
const int level_sq = square_i(level);
const int level_1_sq = square_i(level + 1.0f);
s[0] = 1.0f / (1.0f + lambda_r * level_sq * level_1_sq);
s[1] = 1.0f / (1.0f + lambda_g * level_sq * level_1_sq);
s[2] = 1.0f / (1.0f + lambda_b * level_sq * level_1_sq);
for (int m = -1; m <= level; m++) {
mul_v3_v3(sh[index++], s);
@ -947,7 +949,8 @@ static void studiolight_spherical_harmonics_apply_band_factors(StudioLight *sl,
int index = 0, dst_idx = 0;
for (int band = 0; band < STUDIOLIGHT_SH_BANDS; band++) {
for (int m = 0; m < SQUARE(band + 1) - SQUARE(band); m++) {
const int last_band = square_i(band + 1) - square_i(band);
for (int m = 0; m < last_band; m++) {
/* Skip L3 */
if (band != 3) {
mul_v3_v3fl(sl->spherical_harmonics_coefs[dst_idx++], sh[index], sl_sh_band_factors[band]);
@ -1265,7 +1268,7 @@ static void sphere_normal_from_uv(float normal[3], float u, float v)
normal[0] = u * 2.0f - 1.0f;
normal[1] = v * 2.0f - 1.0f;
float dist = len_v2(normal);
normal[2] = sqrtf(1.0f - SQUARE(dist));
normal[2] = sqrtf(1.0f - square_f(dist));
}
static void studiolight_radiance_preview(uint *icon_buffer, StudioLight *sl)

View File

@ -114,6 +114,23 @@ MINLINE float sasqrt(float fac);
MINLINE float interpf(float a, float b, float t);
MINLINE double interpd(double a, double b, double t);
/* NOTE: Compilers will upcast all types smaller than int to int when performing arithmetic
* operation. */
MINLINE int square_s(short a);
MINLINE int square_uchar(unsigned char a);
MINLINE int cube_s(short a);
MINLINE int cube_uchar(unsigned char a);
MINLINE int square_i(int a);
MINLINE unsigned int square_uint(unsigned int a);
MINLINE float square_f(float a);
MINLINE double square_d(double a);
MINLINE int cube_i(int a);
MINLINE unsigned int cube_uint(unsigned int a);
MINLINE float cube_f(float a);
MINLINE double cube_d(double a);
MINLINE float min_ff(float a, float b);
MINLINE float max_ff(float a, float b);
MINLINE float min_fff(float a, float b, float c);

View File

@ -293,33 +293,6 @@ extern "C" {
/** \name Simple Math Macros
* \{ */
/* avoid multiple access for supported compilers */
#if defined(__GNUC__) || defined(__clang__)
# define ABS(a) \
({ \
typeof(a) a_ = (a); \
((a_) < 0 ? (-(a_)) : (a_)); \
})
# define SQUARE(a) \
({ \
typeof(a) a_ = (a); \
((a_) * (a_)); \
})
# define CUBE(a) \
({ \
typeof(a) a_ = (a); \
((a_) * (a_) * (a_)); \
})
#else
# define ABS(a) ((a) < 0 ? (-(a)) : (a))
# define SQUARE(a) ((a) * (a))
# define CUBE(a) ((a) * (a) * (a))
#endif
/* Float equality checks. */
#define IS_EQ(a, b) \

View File

@ -79,7 +79,7 @@ static float len_squared_vnvn(const float v0[KD_DIMS], const float v1[KD_DIMS])
{
float d = 0.0f;
for (uint j = 0; j < KD_DIMS; j++) {
d += SQUARE(v0[j] - v1[j]);
d += square_f(v0[j] - v1[j]);
}
return d;
}
@ -893,7 +893,7 @@ int BLI_kdtree_nd_(calc_duplicates_fast)(const KDTree *tree,
struct DeDuplicateParams p = {
.nodes = tree->nodes,
.range = range,
.range_sq = SQUARE(range),
.range_sq = square_f(range),
.duplicates = duplicates,
.duplicates_found = &found,
};

View File

@ -485,7 +485,8 @@ bool BLI_listbase_link_move(ListBase *listbase, void *vlink, int step)
BLI_assert(BLI_findindex(listbase, link) != -1);
/* find link to insert before/after */
for (int i = 0; i < ABS(step); i++) {
const int abs_step = abs(step);
for (int i = 0; i < abs_step; i++) {
hook = is_up ? hook->prev : hook->next;
if (!hook) {
return false;

View File

@ -375,6 +375,72 @@ MINLINE float wrapf(float value, float max, float min)
return (range != 0.0f) ? value - (range * floorf((value - min) / range)) : min;
}
// Square.
MINLINE int square_s(short a)
{
return a * a;
}
MINLINE int square_i(int a)
{
return a * a;
}
MINLINE unsigned int square_uint(unsigned int a)
{
return a * a;
}
MINLINE int square_uchar(unsigned char a)
{
return a * a;
}
MINLINE float square_f(float a)
{
return a * a;
}
MINLINE double square_d(double a)
{
return a * a;
}
// Cube.
MINLINE int cube_s(short a)
{
return a * a * a;
}
MINLINE int cube_i(int a)
{
return a * a * a;
}
MINLINE unsigned int cube_uint(unsigned int a)
{
return a * a * a;
}
MINLINE int cube_uchar(unsigned char a)
{
return a * a * a;
}
MINLINE float cube_f(float a)
{
return a * a * a;
}
MINLINE double cube_d(double a)
{
return a * a * a;
}
// Min/max
MINLINE float min_ff(float a, float b)
{
return (a < b) ? a : b;

View File

@ -304,11 +304,11 @@ MINLINE int compare_rgb_uchar(const unsigned char col_a[3],
const int limit)
{
const int r = (int)col_a[0] - (int)col_b[0];
if (ABS(r) < limit) {
if (abs(r) < limit) {
const int g = (int)col_a[1] - (int)col_b[1];
if (ABS(g) < limit) {
if (abs(g) < limit) {
const int b = (int)col_a[2] - (int)col_b[2];
if (ABS(b) < limit) {
if (abs(b) < limit) {
return 1;
}
}

View File

@ -655,7 +655,7 @@ float dist_squared_ray_to_seg_v3(const float ray_origin[3],
*r_depth = depth;
}
return len_squared_v3(dvec) - SQUARE(depth);
return len_squared_v3(dvec) - square_f(depth);
}
/* Returns the coordinates of the nearest vertex and
@ -1311,7 +1311,7 @@ int isect_seg_seg_v2_point_ex(const float v0[2],
float u_a, u_b;
if (equals_v2v2(v0, v1)) {
if (len_squared_v2v2(v2, v3) > SQUARE(eps)) {
if (len_squared_v2v2(v2, v3) > square_f(eps)) {
/* use non-point segment as basis */
SWAP(const float *, v0, v2);
SWAP(const float *, v1, v3);

View File

@ -1953,7 +1953,7 @@ void mat4_to_dquat(DualQuat *dq, const float basemat[4][4], const float mat[4][4
copy_m3_m4(mat3, mat);
if (!is_orthonormal_m3(mat3) || (determinant_m4(mat) < 0.0f) ||
len_squared_v3(dscale) > SQUARE(1e-4f)) {
len_squared_v3(dscale) > square_f(1e-4f)) {
/* extract R and S */
float tmp[4][4];

View File

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <math.h>
#include <inttypes.h>
#include "MEM_guardedalloc.h"
@ -1119,7 +1120,7 @@ void BLI_str_format_byte_unit(char dst[15], long long int bytes, const bool base
BLI_STATIC_ASSERT(ARRAY_SIZE(units_base_2) == ARRAY_SIZE(units_base_10), "array size mismatch");
while ((ABS(bytes_converted) >= base) && ((order + 1) < tot_units)) {
while ((fabs(bytes_converted) >= base) && ((order + 1) < tot_units)) {
bytes_converted /= base;
order++;
}

View File

@ -82,7 +82,7 @@ static bool bm_loop_build(BMEdgeLoopStore *el_store, BMVert *v_prev, BMVert *v,
BMVert *v_next;
BMVert *v_first = v;
BLI_assert(ABS(dir) == 1);
BLI_assert(abs(dir) == 1);
if (!BM_elem_flag_test(v, BM_ELEM_INTERNAL_TAG)) {
return true;
@ -224,7 +224,7 @@ static bool bm_loop_path_build_step(BLI_mempool *vs_pool,
{
ListBase lb_tmp = {NULL, NULL};
struct VertStep *vs, *vs_next;
BLI_assert(ABS(dir) == 1);
BLI_assert(abs(dir) == 1);
for (vs = lb->first; vs; vs = vs_next) {
BMIter iter;

View File

@ -44,7 +44,7 @@ void bmo_planar_faces_exec(BMesh *bm, BMOperator *op)
const int faces_num = BMO_slot_buffer_count(op->slots_in, "faces");
const float eps = 0.00001f;
const float eps_sq = SQUARE(eps);
const float eps_sq = square_f(eps);
BMOIter oiter;
BMFace *f;

View File

@ -411,7 +411,7 @@ static int *bm_edge_symmetry_map(BMesh *bm, uint symmetry_axis, float limit)
BMEdge *e, **etable;
uint i;
int *edge_symmetry_map;
const float limit_sq = SQUARE(limit);
const float limit_sq = square_f(limit);
KDTree_3d *tree;
tree = BLI_kdtree_3d_new(bm->totedge);

View File

@ -272,7 +272,7 @@ static bool bm_edgexvert_isect_impl(BMVert *v,
}
if (v != e_v) {
float dist_sq_vert = SQUARE(dist_sq_vert_factor) * len_squared_v3(dir);
float dist_sq_vert = square_f(dist_sq_vert_factor) * len_squared_v3(dir);
if (dist_sq_vert < data_dist_sq) {
/* Vert x Vert is already handled elsewhere. */
return false;
@ -380,8 +380,8 @@ static bool bm_edgexedge_isect_impl(struct EDBMSplitData *data,
return false;
}
float dist_sq_va = SQUARE(dist_sq_va_factor) * len_squared_v3(dir_a);
float dist_sq_vb = SQUARE(dist_sq_vb_factor) * len_squared_v3(dir_b);
float dist_sq_va = square_f(dist_sq_va_factor) * len_squared_v3(dir_a);
float dist_sq_vb = square_f(dist_sq_vb_factor) * len_squared_v3(dir_b);
if (dist_sq_va < data->dist_sq || dist_sq_vb < data->dist_sq) {
/* Vert x Edge is already handled elsewhere. */
@ -503,7 +503,7 @@ bool BM_mesh_intersect_edges(
BLI_Stack **pair_stack_vertxvert = pair_stack;
BLI_Stack **pair_stack_edgexelem = &pair_stack[KDOP_TREE_TYPE];
const float dist_sq = SQUARE(dist);
const float dist_sq = square_f(dist);
const float dist_half = dist / 2;
struct EDBMSplitData data = {
@ -511,7 +511,7 @@ bool BM_mesh_intersect_edges(
.pair_stack = pair_stack,
.cut_edges_len = 0,
.dist_sq = dist_sq,
.dist_sq_sq = SQUARE(dist_sq),
.dist_sq_sq = square_f(dist_sq),
};
BM_mesh_elem_table_ensure(bm, BM_VERT | BM_EDGE);

View File

@ -921,6 +921,11 @@ static void bm_face_array_visit(BMFace **faces,
/* signed user id */
typedef intptr_t SUID_Int;
BLI_INLINE intptr_t abs_intptr(intptr_t a)
{
return (a < 0) ? -a : a;
}
static bool bm_edge_is_region_boundary(BMEdge *e)
{
if (e->l->radial_next != e->l) {
@ -984,7 +989,7 @@ static SUID_Int bm_face_region_vert_boundary_id(BMVert *v)
id ^= (tot * PRIME_VERT_MID_B);
return id ? ABS(id) : 1;
return id ? abs_intptr(id) : 1;
# undef PRIME_VERT_SMALL_A
# undef PRIME_VERT_SMALL_B
@ -1039,7 +1044,7 @@ static SUID_Int bm_face_region_vert_pass_id(GHash *gh, BMVert *v)
/* disallow 0 & min (since it can't be flipped) */
id = (UNLIKELY(id == 0) ? 1 : UNLIKELY(id < id_min) ? id_min : id);
return ABS(id);
return abs_intptr(id);
# undef PRIME_VERT_MID_A
# undef PRIME_VERT_MID_B

View File

@ -659,7 +659,7 @@ void zbuf_accumulate_vecblur(NodeBlurData *nbd,
dvz[1] = dvec2[-3];
div++;
}
else if ((ABS(dvec2[-4]) + ABS(dvec2[-3])) < (ABS(dvz[0]) + ABS(dvz[1]))) {
else if ((fabsf(dvec2[-4]) + fabsf(dvec2[-3])) < (fabsf(dvz[0]) + fabsf(dvz[1]))) {
dvz[0] = dvec2[-4];
dvz[1] = dvec2[-3];
}
@ -673,7 +673,7 @@ void zbuf_accumulate_vecblur(NodeBlurData *nbd,
dvz[1] = dvec1[1];
div++;
}
else if ((ABS(dvec1[0]) + ABS(dvec1[1])) < (ABS(dvz[0]) + ABS(dvz[1]))) {
else if ((fabsf(dvec1[0]) + fabsf(dvec1[1])) < (fabsf(dvz[0]) + fabsf(dvz[1]))) {
dvz[0] = dvec1[0];
dvz[1] = dvec1[1];
}
@ -683,7 +683,7 @@ void zbuf_accumulate_vecblur(NodeBlurData *nbd,
dvz[0] = dvec2[0];
dvz[1] = dvec2[1];
}
else if ((ABS(dvec2[0]) + ABS(dvec2[1])) < (ABS(dvz[0]) + ABS(dvz[1]))) {
else if ((fabsf(dvec2[0]) + fabsf(dvec2[1])) < (fabsf(dvz[0]) + fabsf(dvz[1]))) {
dvz[0] = dvec2[0];
dvz[1] = dvec2[1];
}

View File

@ -765,7 +765,7 @@ void EEVEE_lightprobes_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *ved
sldata->common_data.prb_lod_cube_max = (float)light_cache->mips_len - 1.0f;
sldata->common_data.prb_lod_planar_max = (float)MAX_PLANAR_LOD_LEVEL;
sldata->common_data.prb_irradiance_vis_size = light_cache->vis_res;
sldata->common_data.prb_irradiance_smooth = SQUARE(scene_eval->eevee.gi_irradiance_smoothing);
sldata->common_data.prb_irradiance_smooth = square_f(scene_eval->eevee.gi_irradiance_smoothing);
sldata->common_data.prb_num_render_cube = max_ii(1, light_cache->cube_len);
sldata->common_data.prb_num_render_grid = max_ii(1, light_cache->grid_len);
sldata->common_data.prb_num_planar = pinfo->num_planar;

View File

@ -140,7 +140,7 @@ extern struct DrawEngineType draw_engine_eevee_type;
BLI_INLINE int octahedral_size_from_cubesize(int cube_size)
{
int cube_pixel_count = SQUARE(cube_size) * 6.0f;
int cube_pixel_count = square_i(cube_size) * 6;
int octa_size = (int)ceilf(sqrtf(cube_pixel_count));
int lod_count = log2_floor_u(octa_size) - MIN_CUBE_LOD_LEVEL;
/* Find lowest lod size and grow back to avoid having non matching mipsizes that would

View File

@ -177,8 +177,8 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
copy_v3_v3(wd->object_outline_color, wpd->shading.object_outline_color);
wd->object_outline_color[3] = 1.0f;
wd->curvature_ridge = 0.5f / max_ff(SQUARE(wpd->shading.curvature_ridge_factor), 1e-4f);
wd->curvature_valley = 0.7f / max_ff(SQUARE(wpd->shading.curvature_valley_factor), 1e-4f);
wd->curvature_ridge = 0.5f / max_ff(square_f(wpd->shading.curvature_ridge_factor), 1e-4f);
wd->curvature_valley = 0.7f / max_ff(square_f(wpd->shading.curvature_valley_factor), 1e-4f);
/* Will be NULL when rendering. */
if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {

View File

@ -77,8 +77,9 @@ static void square_to_circle(float x, float y, float *r, float *T)
}
}
#define KERNEL_RAD 3
#define SAMP_LEN SQUARE(KERNEL_RAD * 2 + 1)
#define SQUARE_UNSAFE(a) ((a) * (a))
#define KERNEL_RAD (3)
#define SAMP_LEN SQUARE_UNSAFE(KERNEL_RAD * 2 + 1)
static void workbench_dof_setup_samples(struct GPUUniformBuffer **ubo,
float **data,

View File

@ -43,7 +43,7 @@ static void workbench_taa_jitter_init_order(float (*table)[2], int num)
float closest_squared_distance = 1.0f;
for (int index = 0; index < num; index++) {
const float squared_dist = SQUARE(table[index][0]) + SQUARE(table[index][1]);
const float squared_dist = square_f(table[index][0]) + square_f(table[index][1]);
if (squared_dist < closest_squared_distance) {
closest_squared_distance = squared_dist;
closest_index = index;
@ -66,8 +66,8 @@ static void workbench_taa_jitter_init_order(float (*table)[2], int num)
float f_squared_dist = 0.0;
int f_index = i;
for (int j = i + 1; j < num; j++) {
const float squared_dist = SQUARE(table[i][0] - table[j][0]) +
SQUARE(table[i][1] - table[j][1]);
const float squared_dist = square_f(table[i][0] - table[j][0]) +
square_f(table[i][1] - table[j][1]);
if (squared_dist > f_squared_dist) {
f_squared_dist = squared_dist;
f_index = j;

View File

@ -476,7 +476,7 @@ static bool draw_culling_sphere_test(const BoundSphere *frustum_bsphere,
/* Do a rough test first: Sphere VS Sphere intersect. */
float center_dist_sq = len_squared_v3v3(bsphere->center, frustum_bsphere->center);
float radius_sum = bsphere->radius + frustum_bsphere->radius;
if (center_dist_sq > SQUARE(radius_sum)) {
if (center_dist_sq > square_f(radius_sum)) {
return false;
}
/* TODO we could test against the inscribed sphere of the frustum to early out positively. */

View File

@ -704,7 +704,8 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm)
for (eBone = arm->edbo->first; eBone; eBone = neBone) {
float len_sq = len_squared_v3v3(eBone->head, eBone->tail);
neBone = eBone->next;
if (len_sq <= SQUARE(0.000001f)) { /* FLT_EPSILON is too large? */
/* TODO(sergey): How to ensure this is a constexpr? */
if (len_sq <= square_f(0.000001f)) { /* FLT_EPSILON is too large? */
EditBone *fBone;
/* Find any bones that refer to this bone */

View File

@ -481,7 +481,7 @@ static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
if (cdd->sample.use_substeps && cdd->prev.selem) {
const struct StrokeElem selem_target = *selem;
struct StrokeElem *selem_new_last = selem;
if (len_sq >= SQUARE(STROKE_SAMPLE_DIST_MAX_PX)) {
if (len_sq >= square_f(STROKE_SAMPLE_DIST_MAX_PX)) {
int n = (int)ceil(sqrt((double)len_sq)) / STROKE_SAMPLE_DIST_MAX_PX;
for (int i = 1; i < n; i++) {
@ -685,7 +685,7 @@ static void curve_draw_exec_precalc(wmOperator *op)
}
if (len_squared_v2v2(selem_first->mval, selem_last->mval) <=
SQUARE(STROKE_CYCLIC_DIST_PX * U.pixelsize)) {
square_f(STROKE_CYCLIC_DIST_PX * U.pixelsize)) {
use_cyclic = true;
}
}
@ -1167,7 +1167,7 @@ static int curve_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
if (cdd->state == CURVE_DRAW_PAINTING) {
const float mval_fl[2] = {UNPACK2(event->mval)};
if (len_squared_v2v2(mval_fl, cdd->prev.mouse) > SQUARE(STROKE_SAMPLE_DIST_MIN_PX)) {
if (len_squared_v2v2(mval_fl, cdd->prev.mouse) > square_f(STROKE_SAMPLE_DIST_MIN_PX)) {
curve_draw_event_add(op, event);
}
}

View File

@ -242,7 +242,7 @@ static int gizmo_arrow_test_select(bContext *UNUSED(C), wmGizmo *gz, const int m
const float arrow_head_threshold_px = 12 * UI_DPI_FAC;
/* Distance to arrow head. */
if (len_squared_v2v2(mval_fl, arrow_end) < SQUARE(arrow_head_threshold_px)) {
if (len_squared_v2v2(mval_fl, arrow_end) < square_f(arrow_head_threshold_px)) {
return 0;
}
@ -252,7 +252,7 @@ static int gizmo_arrow_test_select(bContext *UNUSED(C), wmGizmo *gz, const int m
/* Clamp inside the line, to avoid overlapping with other gizmos,
* especially around the start of the arrow. */
if (lambda >= 0.0 && lambda <= 1.0) {
if (len_squared_v2v2(mval_fl, co_isect) < SQUARE(arrow_stem_threshold_px)) {
if (len_squared_v2v2(mval_fl, co_isect) < square_f(arrow_stem_threshold_px)) {
return 0;
}
}

View File

@ -905,7 +905,7 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
}
/* exponential value */
const float exfactor = SQUARE(brush->gpencil_settings->draw_jitter + 2.0f);
const float exfactor = square_f(brush->gpencil_settings->draw_jitter + 2.0f);
const float fac = p2d->rnd[0] * exfactor * jitter;
/* vector */

View File

@ -479,7 +479,7 @@ void ui_pan_to_scroll(const wmEvent *event, int *type, int *val)
else {
lastdy += dy;
if (ABS(lastdy) > (int)UI_UNIT_Y) {
if (abs(lastdy) > (int)UI_UNIT_Y) {
if (U.uiflag2 & USER_TRACKPAD_NATURAL) {
dy = -dy;
}
@ -568,7 +568,7 @@ static bool ui_but_dragedit_update_mval(uiHandleButtonData *data, int mx)
}
if (data->draglock) {
if (ABS(mx - data->dragstartx) <= BUTTON_DRAGLOCK_THRESH) {
if (abs(mx - data->dragstartx) <= BUTTON_DRAGLOCK_THRESH) {
return false;
}
#ifdef USE_DRAG_MULTINUM
@ -1855,7 +1855,7 @@ static bool ui_but_drag_init(bContext *C,
WM_event_drag_threshold(event),
(int)((UI_UNIT_Y / 2) * ui_block_to_window_scale(data->region, but->block)));
if (ABS(data->dragstartx - event->x) + ABS(data->dragstarty - event->y) > drag_threshold) {
if (abs(data->dragstartx - event->x) + abs(data->dragstarty - event->y) > drag_threshold) {
button_activate_state(C, but, BUTTON_STATE_EXIT);
data->cancel = true;
#ifdef USE_DRAG_TOGGLE
@ -6554,7 +6554,7 @@ static int ui_do_but_COLORBAND(
/* activate new key when mouse is close */
for (a = 0, cbd = coba->data; a < coba->tot; a++, cbd++) {
xco = but->rect.xmin + (cbd->pos * BLI_rctf_size_x(&but->rect));
xco = ABS(xco - mx);
xco = abs(xco - mx);
if (a == coba->cur) {
/* Selected one disadvantage. */
xco += 5;
@ -6739,7 +6739,7 @@ static int ui_do_but_CURVE(
CurveMap *cuma = cumap->cm + cumap->cur;
CurveMapPoint *cmp;
const float m_xy[2] = {mx, my};
float dist_min_sq = SQUARE(U.dpi_fac * 14.0f); /* 14 pixels radius */
float dist_min_sq = square_f(U.dpi_fac * 14.0f); /* 14 pixels radius */
int sel = -1;
if (event->ctrl) {
@ -6774,7 +6774,7 @@ static int ui_do_but_CURVE(
BLI_rctf_transform_pt_v(&but->rect, &cumap->curr, f_xy, &cmp[0].x);
/* with 160px height 8px should translate to the old 0.05 coefficient at no zoom */
dist_min_sq = SQUARE(U.dpi_fac * 8.0f);
dist_min_sq = square_f(U.dpi_fac * 8.0f);
/* loop through the curve segment table and find what's near the mouse. */
for (i = 1; i <= CM_TABLE; i++) {
@ -7046,7 +7046,7 @@ static int ui_do_but_CURVEPROFILE(
}
/* Check for selecting of a point by finding closest point in radius. */
dist_min_sq = SQUARE(U.dpi_fac * 14.0f); /* 14 pixels radius for selecting points. */
dist_min_sq = square_f(U.dpi_fac * 14.0f); /* 14 pixels radius for selecting points. */
pts = profile->path;
for (i = 0; i < profile->path_len; i++) {
float f_xy[2];
@ -7064,7 +7064,7 @@ static int ui_do_but_CURVEPROFILE(
pts = profile->table;
BLI_rctf_transform_pt_v(&but->rect, &profile->view_rect, f_xy, &pts[0].x);
dist_min_sq = SQUARE(U.dpi_fac * 8.0f); /* 8 pixel radius from each table point. */
dist_min_sq = square_f(U.dpi_fac * 8.0f); /* 8 pixel radius from each table point. */
/* Loop through the path's high resolution table and find what's near the click. */
for (i = 1; i <= PROF_N_TABLE(profile->path_len); i++) {

View File

@ -525,7 +525,7 @@ int UI_calc_float_precision(int prec, double value)
* this is so 0.00001 is not displayed as 0.00,
* _but_, this is only for small values si 10.0001 will not get the same treatment.
*/
value = ABS(value);
value = fabs(value);
if ((value < pow10_neg[prec]) && (value > (1.0 / max_pow))) {
int value_i = (int)((value * max_pow) + 0.5);
if (value_i != 0) {

View File

@ -614,7 +614,7 @@ static bool spline_under_mouse_get(const bContext *C,
}
}
}
if (closest_dist_squared < SQUARE(threshold) && closest_spline != NULL) {
if (closest_dist_squared < square_f(threshold) && closest_spline != NULL) {
float diff_score;
if (ED_mask_find_nearest_diff_point(C,
mask,
@ -629,7 +629,7 @@ static bool spline_under_mouse_get(const bContext *C,
NULL,
NULL,
&diff_score)) {
if (SQUARE(diff_score) < closest_dist_squared) {
if (square_f(diff_score) < closest_dist_squared) {
return false;
}
}

View File

@ -1079,7 +1079,7 @@ void EDBM_verts_mirror_cache_begin_ex(BMEditMesh *em,
BMVert *v;
int cd_vmirr_offset = 0;
int i;
const float maxdist_sq = SQUARE(maxdist);
const float maxdist_sq = square_f(maxdist);
/* one or the other is used depending if topo is enabled */
KDTree_3d *tree = NULL;

View File

@ -615,7 +615,7 @@ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect,
if (rv && rv->rectf) {
if (ABS(rres.rectx - newx) < 2 && ABS(rres.recty - newy) < 2) {
if (abs(rres.rectx - newx) < 2 && abs(rres.recty - newy) < 2) {
newrect->xmax = max_ii(newrect->xmax, rect->xmin + rres.rectx + offx);
newrect->ymax = max_ii(newrect->ymax, rect->ymin + rres.recty);
@ -694,7 +694,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, r
* or if the job is running and the size of preview changed */
if ((sbuts != NULL && sbuts->preview) ||
(!ok && !WM_jobs_test(wm, sa, WM_JOB_TYPE_RENDER_PREVIEW)) ||
(sp && (ABS(sp->sizex - newx) >= 2 || ABS(sp->sizey - newy) > 2))) {
(sp && (abs(sp->sizex - newx) >= 2 || abs(sp->sizey - newy) > 2))) {
if (sbuts != NULL) {
sbuts->preview = 0;
}

View File

@ -2533,7 +2533,7 @@ void ED_region_panels_layout_ex(const bContext *C,
region->sizey = size_dyn[1];
sa->flag |= AREA_FLAG_REGION_SIZE_UPDATE;
}
y = ABS(region->sizey * UI_DPI_FAC - 1);
y = fabsf(region->sizey * UI_DPI_FAC - 1);
}
}
else if (vertical) {
@ -3390,21 +3390,21 @@ static void region_visible_rect_calc(ARegion *region, rcti *rect)
if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
/* Overlap left, also check 1 pixel offset (2 regions on one side). */
if (ABS(rect->xmin - arn->winrct.xmin) < 2) {
if (abs(rect->xmin - arn->winrct.xmin) < 2) {
rect->xmin = arn->winrct.xmax;
}
/* Overlap right. */
if (ABS(rect->xmax - arn->winrct.xmax) < 2) {
if (abs(rect->xmax - arn->winrct.xmax) < 2) {
rect->xmax = arn->winrct.xmin;
}
}
else if (ELEM(alignment, RGN_ALIGN_TOP, RGN_ALIGN_BOTTOM)) {
/* Same logic as above for vertical regions. */
if (ABS(rect->ymin - arn->winrct.ymin) < 2) {
if (abs(rect->ymin - arn->winrct.ymin) < 2) {
rect->ymin = arn->winrct.ymax;
}
if (ABS(rect->ymax - arn->winrct.ymax) < 2) {
if (abs(rect->ymax - arn->winrct.ymax) < 2) {
rect->ymax = arn->winrct.ymin;
}
}

View File

@ -81,7 +81,7 @@ int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, in
if (size <= snap_units[ARRAY_SIZE(snap_units) - 1]) {
for (uint i = 0; i < ARRAY_SIZE(snap_units); i += 1) {
const int test_size = snap_units[i];
const int test_diff = ABS(test_size - size);
const int test_diff = abs(test_size - size);
if (test_diff < best_diff) {
best_size = test_size;
best_diff = test_diff;

View File

@ -307,26 +307,26 @@ int area_getorientation(ScrArea *sa, ScrArea *sb)
int tolerance = U.pixelsize * 4;
if (saBL->vec.x == sbBR->vec.x && saTL->vec.x == sbTR->vec.x) { /* sa to right of sb = W */
if ((ABS(saBL->vec.y - sbBR->vec.y) <= tolerance) &&
(ABS(saTL->vec.y - sbTR->vec.y) <= tolerance)) {
if ((abs(saBL->vec.y - sbBR->vec.y) <= tolerance) &&
(abs(saTL->vec.y - sbTR->vec.y) <= tolerance)) {
return 0;
}
}
else if (saTL->vec.y == sbBL->vec.y && saTR->vec.y == sbBR->vec.y) { /* sa to bottom of sb = N */
if ((ABS(saTL->vec.x - sbBL->vec.x) <= tolerance) &&
(ABS(saTR->vec.x - sbBR->vec.x) <= tolerance)) {
if ((abs(saTL->vec.x - sbBL->vec.x) <= tolerance) &&
(abs(saTR->vec.x - sbBR->vec.x) <= tolerance)) {
return 1;
}
}
else if (saTR->vec.x == sbTL->vec.x && saBR->vec.x == sbBL->vec.x) { /* sa to left of sb = E */
if ((ABS(saTR->vec.y - sbTL->vec.y) <= tolerance) &&
(ABS(saBR->vec.y - sbBL->vec.y) <= tolerance)) {
if ((abs(saTR->vec.y - sbTL->vec.y) <= tolerance) &&
(abs(saBR->vec.y - sbBL->vec.y) <= tolerance)) {
return 2;
}
}
else if (saBL->vec.y == sbTL->vec.y && saBR->vec.y == sbTR->vec.y) { /* sa on top of sb = S*/
if ((ABS(saBL->vec.x - sbTL->vec.x) <= tolerance) &&
(ABS(saBR->vec.x - sbTR->vec.x) <= tolerance)) {
if ((abs(saBL->vec.x - sbTL->vec.x) <= tolerance) &&
(abs(saBR->vec.x - sbTR->vec.x) <= tolerance)) {
return 3;
}
}

View File

@ -774,10 +774,10 @@ static AZone *area_actionzone_refresh_xy(ScrArea *sa, const int xy[2], const boo
az->alpha = 1.0f;
}
else {
const int mouse_sq = SQUARE(xy[0] - az->x2) + SQUARE(xy[1] - az->y2);
const int spot_sq = SQUARE(AZONESPOTW);
const int fadein_sq = SQUARE(AZONEFADEIN);
const int fadeout_sq = SQUARE(AZONEFADEOUT);
const int mouse_sq = square_i(xy[0] - az->x2) + square_i(xy[1] - az->y2);
const int spot_sq = square_i(AZONESPOTW);
const int fadein_sq = square_i(AZONEFADEIN);
const int fadeout_sq = square_i(AZONEFADEOUT);
if (mouse_sq < spot_sq) {
az->alpha = 1.0f;
@ -1014,7 +1014,7 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event)
const int delta_y = (event->y - sad->y);
/* Movement in dominant direction. */
const int delta_max = max_ii(ABS(delta_x), ABS(delta_y));
const int delta_max = max_ii(abs(delta_x), abs(delta_y));
/* Movement in dominant direction before action taken. */
const int join_threshold = (0.6 * U.widget_unit);
@ -1022,13 +1022,13 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event)
const int area_threshold = (0.1 * U.widget_unit);
/* Calculate gesture cardinal direction. */
if (delta_y > ABS(delta_x)) {
if (delta_y > abs(delta_x)) {
sad->gesture_dir = 'n';
}
else if (delta_x >= ABS(delta_y)) {
else if (delta_x >= abs(delta_y)) {
sad->gesture_dir = 'e';
}
else if (delta_y < -ABS(delta_x)) {
else if (delta_y < -abs(delta_x)) {
sad->gesture_dir = 's';
}
else {
@ -2677,7 +2677,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (rmd->region->type->snap_size) {
short sizex_test = rmd->region->type->snap_size(rmd->region, rmd->region->sizex, 0);
if (ABS(rmd->region->sizex - sizex_test) < snap_size_threshold) {
if (abs(rmd->region->sizex - sizex_test) < snap_size_threshold) {
rmd->region->sizex = sizex_test;
}
}
@ -2710,7 +2710,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (rmd->region->type->snap_size) {
short sizey_test = rmd->region->type->snap_size(rmd->region, rmd->region->sizey, 1);
if (ABS(rmd->region->sizey - sizey_test) < snap_size_threshold) {
if (abs(rmd->region->sizey - sizey_test) < snap_size_threshold) {
rmd->region->sizey = sizey_test;
}
}

View File

@ -1350,7 +1350,7 @@ static void uv_image_outset(const ProjPaintState *ps,
if (tri_ang > 0.0f) {
const float dist = ps->seam_bleed_px * tanf(tri_ang);
seam_data->corner_dist_sq[i] = SQUARE(dist);
seam_data->corner_dist_sq[i] = square_f(dist);
}
else {
seam_data->corner_dist_sq[i] = 0.0f;
@ -5886,7 +5886,7 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int
#ifndef PROJ_DEBUG_NOSEAMBLEED
/* pixel num to bleed */
ps->seam_bleed_px = settings->imapaint.seam_bleed;
ps->seam_bleed_px_sq = SQUARE(settings->imapaint.seam_bleed);
ps->seam_bleed_px_sq = square_s(settings->imapaint.seam_bleed);
#endif
if (ps->do_mask_normal) {

View File

@ -639,7 +639,7 @@ static bool paint_smooth_stroke(PaintStroke *stroke,
/* If the mouse is moving within the radius of the last move,
* don't update the mouse position. This allows sharp turns. */
if (len_squared_v2v2(stroke->last_mouse_position, sample->mouse) < SQUARE(radius)) {
if (len_squared_v2v2(stroke->last_mouse_position, sample->mouse) < square_f(radius)) {
return false;
}

View File

@ -2364,7 +2364,7 @@ static PBVHNode **sculpt_pbvh_gather_generic(Object *ob,
SculptSearchSphereData data = {
.ss = ss,
.sd = sd,
.radius_squared = SQUARE(ss->cache->radius * radius_scale),
.radius_squared = square_f(ss->cache->radius * radius_scale),
.original = use_original,
.ignore_fully_masked = brush->sculpt_tool != SCULPT_TOOL_MASK,
.center = NULL,
@ -2378,7 +2378,8 @@ static PBVHNode **sculpt_pbvh_gather_generic(Object *ob,
SculptSearchCircleData data = {
.ss = ss,
.sd = sd,
.radius_squared = ss->cache ? SQUARE(ss->cache->radius * radius_scale) : ss->cursor_radius,
.radius_squared = ss->cache ? square_f(ss->cache->radius * radius_scale) :
ss->cursor_radius,
.original = use_original,
.dist_ray_to_aabb_precalc = &dist_ray_to_aabb_precalc,
.ignore_fully_masked = brush->sculpt_tool != SCULPT_TOOL_MASK,
@ -5710,7 +5711,7 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe
SculptSearchSphereData data = {
.ss = ss,
.sd = sd,
.radius_squared = SQUARE(ss->cache->radius * (1.0 + brush->cloth_sim_limit)),
.radius_squared = square_f(ss->cache->radius * (1.0 + brush->cloth_sim_limit)),
.original = false,
.ignore_fully_masked = false,
.center = ss->cache->initial_location,
@ -6795,7 +6796,7 @@ static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Bru
if ((normalize_v3(v2) > eps) && (normalize_v3(v1) > eps) &&
(len_squared_v3v3(v1, v2) > eps)) {
const float rake_dist_sq = len_squared_v3v3(cache->rake_data.follow_co, grab_location);
const float rake_fade = (rake_dist_sq > SQUARE(cache->rake_data.follow_dist)) ?
const float rake_fade = (rake_dist_sq > square_f(cache->rake_data.follow_dist)) ?
1.0f :
sqrtf(rake_dist_sq) / cache->rake_data.follow_dist;
@ -9780,7 +9781,7 @@ static int sculpt_mask_expand_modal(bContext *C, wmOperator *op, const wmEvent *
copy_v2_v2(prevclick_f, op->customdata);
int prevclick[2] = {(int)prevclick_f[0], (int)prevclick_f[1]};
int len = (int)len_v2v2_int(prevclick, event->mval);
len = ABS(len);
len = abs(len);
int mask_speed = RNA_int_get(op->ptr, "mask_speed");
int mask_expand_update_it = len / mask_speed;
mask_expand_update_it = mask_expand_update_it + 1;

View File

@ -454,7 +454,7 @@ static float mouse_to_slide_zone_distance_squared(const float co[2],
{
const float pixel_co[2] = {co[0] * width, co[1] * height},
pixel_slide_zone[2] = {slide_zone[0] * width, slide_zone[1] * height};
return SQUARE(pixel_co[0] - pixel_slide_zone[0]) + SQUARE(pixel_co[1] - pixel_slide_zone[1]);
return square_f(pixel_co[0] - pixel_slide_zone[0]) + square_f(pixel_co[1] - pixel_slide_zone[1]);
}
static float mouse_to_search_corner_distance_squared(

View File

@ -117,7 +117,7 @@ static float mouse_to_plane_slide_zone_distance_squared(const float co[2],
{
const float pixel_co[2] = {co[0] * width, co[1] * height},
pixel_slide_zone[2] = {slide_zone[0] * width, slide_zone[1] * height};
return SQUARE(pixel_co[0] - pixel_slide_zone[0]) + SQUARE(pixel_co[1] - pixel_slide_zone[1]);
return square_f(pixel_co[0] - pixel_slide_zone[0]) + square_f(pixel_co[1] - pixel_slide_zone[1]);
}
static MovieTrackingPlaneTrack *tracking_plane_marker_check_slide(bContext *C,

View File

@ -161,7 +161,7 @@ void *ED_image_paint_tile_find(ListBase *paint_tiles,
if (r_mask) {
/* allocate mask if requested. */
if (!ptile->mask) {
ptile->mask = MEM_callocN(sizeof(ushort) * SQUARE(ED_IMAGE_UNDO_TILE_SIZE),
ptile->mask = MEM_callocN(sizeof(ushort) * square_i(ED_IMAGE_UNDO_TILE_SIZE),
"UndoImageTile.mask");
}
*r_mask = ptile->mask;
@ -216,12 +216,12 @@ void *ED_image_paint_tile_push(ListBase *paint_tiles,
/* add mask explicitly here */
if (r_mask) {
*r_mask = ptile->mask = MEM_callocN(sizeof(ushort) * SQUARE(ED_IMAGE_UNDO_TILE_SIZE),
*r_mask = ptile->mask = MEM_callocN(sizeof(ushort) * square_i(ED_IMAGE_UNDO_TILE_SIZE),
"PaintTile.mask");
}
ptile->rect.pt = MEM_mapallocN((ibuf->rect_float ? sizeof(float[4]) : sizeof(char[4])) *
SQUARE(ED_IMAGE_UNDO_TILE_SIZE),
square_i(ED_IMAGE_UNDO_TILE_SIZE),
"PaintTile.rect");
ptile->use_float = has_float;
@ -333,10 +333,10 @@ static UndoImageTile *utile_alloc(bool has_float)
{
UndoImageTile *utile = MEM_callocN(sizeof(*utile), "ImageUndoTile");
if (has_float) {
utile->rect.fp = MEM_mallocN(sizeof(float[4]) * SQUARE(ED_IMAGE_UNDO_TILE_SIZE), __func__);
utile->rect.fp = MEM_mallocN(sizeof(float[4]) * square_i(ED_IMAGE_UNDO_TILE_SIZE), __func__);
}
else {
utile->rect.uint = MEM_mallocN(sizeof(uint) * SQUARE(ED_IMAGE_UNDO_TILE_SIZE), __func__);
utile->rect.uint = MEM_mallocN(sizeof(uint) * square_i(ED_IMAGE_UNDO_TILE_SIZE), __func__);
}
return utile;
}

View File

@ -651,7 +651,7 @@ static void node_draw_reroute(const bContext *C,
static int node_tweak_area_reroute(bNode *node, int x, int y)
{
/* square of tweak radius */
const float tweak_radius_sq = SQUARE(24);
const float tweak_radius_sq = square_f(24.0f);
bNodeSocket *sock = node->inputs.first;
float dx = sock->locx - x;
@ -3656,7 +3656,7 @@ static bool node_link_bezier_handles(View2D *v2d,
deltay = vec[3][1] - vec[0][1];
/* check direction later, for top sockets */
if (fromreroute) {
if (ABS(deltax) > ABS(deltay)) {
if (fabsf(deltax) > fabsf(deltay)) {
vec[1][1] = vec[0][1];
vec[1][0] = vec[0][0] + (deltax > 0 ? dist : -dist);
}
@ -3670,7 +3670,7 @@ static bool node_link_bezier_handles(View2D *v2d,
vec[1][1] = vec[0][1];
}
if (toreroute) {
if (ABS(deltax) > ABS(deltay)) {
if (fabsf(deltax) > fabsf(deltay)) {
vec[2][1] = vec[3][1];
vec[2][0] = vec[3][0] + (deltax > 0 ? -dist : dist);
}

View File

@ -211,11 +211,11 @@ static void calctrackballvec(const rcti *rect, const int event_xy[2], float r_di
const float d = len_v2(r_dir);
if (d < t) {
/* Inside sphere. */
r_dir[2] = sqrtf(SQUARE(radius) - SQUARE(d));
r_dir[2] = sqrtf(square_f(radius) - square_f(d));
}
else {
/* On hyperbola. */
r_dir[2] = SQUARE(t) / d;
r_dir[2] = square_f(t) / d;
}
}

View File

@ -1509,7 +1509,7 @@ static short snap_mesh_polygon(SnapObjectContext *sctx,
BVHTreeNearest nearest = {
.index = -1,
.dist_sq = SQUARE(*dist_px),
.dist_sq = square_f(*dist_px),
};
SnapObjectData *sod = snap_object_data_lookup(sctx, ob);
@ -1674,7 +1674,7 @@ static short snap_mesh_edge_verts_mixed(SnapObjectContext *sctx,
BVHTreeNearest nearest = {
.index = -1,
.dist_sq = SQUARE(original_dist_px),
.dist_sq = square_f(original_dist_px),
};
float lambda;
@ -1807,7 +1807,7 @@ static short snapArmature(SnapData *snapdata,
return retval;
}
float lpmat[4][4], dist_px_sq = SQUARE(*dist_px);
float lpmat[4][4], dist_px_sq = square_f(*dist_px);
mul_m4_m4m4(lpmat, snapdata->pmat, obmat);
struct DistProjectedAABBPrecalc neasrest_precalc;
@ -1954,7 +1954,7 @@ static short snapCurve(SnapData *snapdata,
}
Curve *cu = ob->data;
float dist_px_sq = SQUARE(*dist_px);
float dist_px_sq = square_f(*dist_px);
float lpmat[4][4];
mul_m4_m4m4(lpmat, snapdata->pmat, obmat);
@ -2115,7 +2115,7 @@ static short snapEmpty(SnapData *snapdata,
}
bool is_persp = snapdata->view_proj == VIEW_PROJ_PERSP;
float dist_px_sq = SQUARE(*dist_px);
float dist_px_sq = square_f(*dist_px);
float co[3];
copy_v3_v3(co, obmat[3]);
if (test_projected_vert_dist(&neasrest_precalc,
@ -2157,7 +2157,7 @@ static short snapCamera(const SnapObjectContext *sctx,
Scene *scene = sctx->scene;
bool is_persp = snapdata->view_proj == VIEW_PROJ_PERSP;
float dist_px_sq = SQUARE(*dist_px);
float dist_px_sq = square_f(*dist_px);
float orig_camera_mat[4][4], orig_camera_imat[4][4], imat[4][4];
MovieClip *clip = BKE_object_movieclip_get(scene, object, false);
@ -2268,7 +2268,7 @@ static short snapMesh(SnapObjectContext *sctx,
float lpmat[4][4];
mul_m4_m4m4(lpmat, snapdata->pmat, obmat);
float dist_px_sq = SQUARE(*dist_px);
float dist_px_sq = square_f(*dist_px);
/* Test BoundBox */
BoundBox *bb = BKE_mesh_boundbox_get(ob);
@ -2506,7 +2506,7 @@ static short snapEditMesh(SnapObjectContext *sctx,
float lpmat[4][4];
mul_m4_m4m4(lpmat, snapdata->pmat, obmat);
float dist_px_sq = SQUARE(*dist_px);
float dist_px_sq = square_f(*dist_px);
SnapObjectData *sod = snap_object_data_editmesh_get(sctx, ob, em);

View File

@ -971,7 +971,7 @@ bool uv_find_nearest_vert(Scene *scene,
MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
if (penalty_dist != 0.0f && uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
dist_test_sq = len_v2v2(co, luv->uv) + penalty_dist;
dist_test_sq = SQUARE(dist_test_sq);
dist_test_sq = square_f(dist_test_sq);
}
else {
dist_test_sq = len_squared_v2v2(co, luv->uv);

View File

@ -224,7 +224,7 @@ static void deformStroke(GpencilModifierData *md,
tData.curfalloff = mmd->curfalloff;
tData.falloff_type = mmd->falloff_type;
tData.falloff = (mmd->falloff_type == eHook_Falloff_None) ? 0.0f : mmd->falloff;
tData.falloff_sq = SQUARE(tData.falloff);
tData.falloff_sq = square_f(tData.falloff);
tData.fac_orig = mmd->force;
tData.use_falloff = (tData.falloff_sq != 0.0f);
tData.use_uniform = (mmd->flag & GP_HOOK_UNIFORM_SPACE) != 0;

View File

@ -569,7 +569,7 @@ static void gpu_pbvh_grid_fill_index_buffers(
}
else {
uint offset = 0;
const uint grid_vert_len = SQUARE(gridsize - 1) * 4;
const uint grid_vert_len = square_uint(gridsize - 1) * 4;
for (int i = 0; i < totgrid; i++, offset += grid_vert_len) {
bool grid_visible = false;
@ -668,7 +668,7 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
buffers->smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
uint vert_per_grid = (buffers->smooth) ? key->grid_area : (SQUARE(key->grid_size - 1) * 4);
uint vert_per_grid = (buffers->smooth) ? key->grid_area : (square_i(key->grid_size - 1) * 4);
uint vert_count = totgrid * vert_per_grid;
if (buffers->index_buf == NULL) {
@ -784,7 +784,7 @@ void GPU_pbvh_grid_buffers_update(GPU_PBVH_Buffers *buffers,
vbo_index += 4;
}
}
vbo_index_offset += SQUARE(key->grid_size - 1) * 4;
vbo_index_offset += square_i(key->grid_size - 1) * 4;
}
}

View File

@ -394,7 +394,7 @@ static void execute_posetree(struct Depsgraph *depsgraph,
IK_SetStiffness(seg, IK_Z, pchan->stiffness[2]);
if (tree->stretch && (pchan->ikstretch > 0.0f)) {
const float ikstretch_sq = SQUARE(pchan->ikstretch);
const float ikstretch_sq = square_f(pchan->ikstretch);
/* this function does its own clamping */
IK_SetStiffness(seg, IK_TRANS_Y, 1.0f - ikstretch_sq);
IK_SetLimit(seg, IK_TRANS_Y, IK_STRETCH_STIFF_MIN, IK_STRETCH_STIFF_MAX);

View File

@ -21,6 +21,7 @@
#include <inttypes.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -588,7 +589,7 @@ static void rna_float_print(FILE *f, float num)
else if (num == FLT_MAX) {
fprintf(f, "FLT_MAX");
}
else if ((ABS(num) < INT64_MAX) && ((int64_t)num == num)) {
else if ((fabsf(num) < INT64_MAX) && ((int64_t)num == num)) {
fprintf(f, "%.1ff", num);
}
else {

View File

@ -281,7 +281,7 @@ static void deformVerts_do(HookModifierData *hmd,
hd.falloff_type = hmd->falloff_type;
hd.falloff = (hmd->falloff_type == eHook_Falloff_None) ? 0.0f : hmd->falloff;
hd.falloff_sq = SQUARE(hd.falloff);
hd.falloff_sq = square_f(hd.falloff);
hd.fac_orig = hmd->force;
hd.use_falloff = (hd.falloff_sq != 0.0f);

View File

@ -112,7 +112,7 @@ static Mesh *mesh_remove_doubles_on_axis(Mesh *result,
const float axis_offset[3],
const float merge_threshold)
{
const float merge_threshold_sq = SQUARE(merge_threshold);
const float merge_threshold_sq = square_f(merge_threshold);
const bool use_offset = axis_offset != NULL;
uint tot_doubles = 0;
for (uint i = 0; i < totvert; i += 1) {

View File

@ -169,7 +169,7 @@ static void warpModifier_do(WarpModifierData *wmd,
float tmat[4][4];
const float falloff_radius_sq = SQUARE(wmd->falloff_radius);
const float falloff_radius_sq = square_f(wmd->falloff_radius);
float strength = wmd->strength;
float fac = 1.0f, weight;
int i;

View File

@ -1663,7 +1663,7 @@ static Mesh *weldModifier_doWeld(WeldModifierData *wmd, const ModifierEvalContex
struct WeldOverlapData data;
data.mvert = mvert;
data.merge_dist_sq = SQUARE(wmd->merge_dist);
data.merge_dist_sq = square_f(wmd->merge_dist);
uint overlap_len;
BVHTreeOverlap *overlap = BLI_bvhtree_overlap_ex(bvhtree,

View File

@ -493,7 +493,7 @@ static PyObject *py_bvhtree_find_nearest_range(PyBVHTree *self, PyObject *args)
struct PyBVH_RangeData data = {
.self = self,
.result = ret,
.dist_sq = SQUARE(max_dist),
.dist_sq = square_f(max_dist),
};
BLI_bvhtree_range_query(self->tree, co, max_dist, py_bvhtree_nearest_point_range_cb, &data);

View File

@ -129,7 +129,7 @@ float RE_filter_value(int type, float x)
{
float gaussfac = 1.6f;
x = ABS(x);
x = fabsf(x);
switch (type) {
case R_FILTER_BOX: