Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2020-03-06 19:18:10 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2020-03-09 16:47:59 +0300
commit598ab525da3df3fef2033c159c570688c7282a8f (patch)
treeba2bd0b8fc6ee5d264512bf655def1a6ee5d7b31 /source/blender/blenkernel
parentee5d7bc16b243f309c84bce5deddf3a86b7f4c14 (diff)
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
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/intern/brush.c2
-rw-r--r--source/blender/blenkernel/intern/bvhutils.c2
-rw-r--r--source/blender/blenkernel/intern/collision.c14
-rw-r--r--source/blender/blenkernel/intern/constraint.c2
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c2
-rw-r--r--source/blender/blenkernel/intern/effect.c4
-rw-r--r--source/blender/blenkernel/intern/fcurve.c2
-rw-r--r--source/blender/blenkernel/intern/mask.c2
-rw-r--r--source/blender/blenkernel/intern/mesh.c4
-rw-r--r--source/blender/blenkernel/intern/multires.c8
-rw-r--r--source/blender/blenkernel/intern/pbvh_bmesh.c4
-rw-r--r--source/blender/blenkernel/intern/softbody.c6
-rw-r--r--source/blender/blenkernel/intern/studiolight.c29
13 files changed, 42 insertions, 39 deletions
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 041cd0b8539..4a92f439d74 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -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;
diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c
index 0a5952e1b47..78723455f14 100644
--- a/source/blender/blenkernel/intern/bvhutils.c
+++ b/source/blender/blenkernel/intern/bvhutils.c
@@ -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];
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 987791db101..62ad361570c 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -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];
}
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index f751ccd66b0..9719704967e 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -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);
}
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index b8f9eac0f6c..7f71409a3f2 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -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) {
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 4a9efc7cac4..b12201df809 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -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;
}
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index ebc048ce286..7dfdc1e1008 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -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);
}
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index 28ed7606cbf..a6535bc9b4a 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -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];
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index c4e77b7fc80..67b94706986 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -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;
}
}
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index 3447d37f1ab..f3d65f584d1 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -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++) {
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 7e42f370e9b..e30cf9a4a80 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -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 {
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 4e75f4f0761..4eec5ac3605 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -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)));
diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c
index 4a69fcfa9d0..18d11e4d4c6 100644
--- a/source/blender/blenkernel/intern/studiolight.c
+++ b/source/blender/blenkernel/intern/studiolight.c
@@ -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)