Commit: 598ab525da3df3fef2033c159c570688c7282a8f Author: Sergey Sharybin Date: Fri Mar 6 17:18:10 2020 +0100 Branches: master https://developer.blender.org/rB598ab525da3df3fef2033c159c570688c7282a8f
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 =================================================================== M source/blender/blenkernel/intern/brush.c M source/blender/blenkernel/intern/bvhutils.c M source/blender/blenkernel/intern/collision.c M source/blender/blenkernel/intern/constraint.c M source/blender/blenkernel/intern/dynamicpaint.c M source/blender/blenkernel/intern/effect.c M source/blender/blenkernel/intern/fcurve.c M source/blender/blenkernel/intern/mask.c M source/blender/blenkernel/intern/mesh.c M source/blender/blenkernel/intern/multires.c M source/blender/blenkernel/intern/pbvh_bmesh.c M source/blender/blenkernel/intern/softbody.c M source/blender/blenkernel/intern/studiolight.c M source/blender/blenlib/BLI_math_base.h M source/blender/blenlib/BLI_utildefines.h M source/blender/blenlib/intern/kdtree_impl.h M source/blender/blenlib/intern/listbase.c M source/blender/blenlib/intern/math_base_inline.c M source/blender/blenlib/intern/math_color_inline.c M source/blender/blenlib/intern/math_geom.c M source/blender/blenlib/intern/math_rotation.c M source/blender/blenlib/intern/string.c M source/blender/bmesh/intern/bmesh_edgeloop.c M source/blender/bmesh/operators/bmo_planar_faces.c M source/blender/bmesh/tools/bmesh_decimate_collapse.c M source/blender/bmesh/tools/bmesh_intersect_edges.c M source/blender/bmesh/tools/bmesh_region_match.c M source/blender/compositor/operations/COM_VectorBlurOperation.cpp M source/blender/draw/engines/eevee/eevee_lightprobes.c M source/blender/draw/engines/eevee/eevee_private.h M source/blender/draw/engines/workbench/workbench_data.c M source/blender/draw/engines/workbench/workbench_effect_dof.c M source/blender/draw/engines/workbench/workbench_effect_taa.c M source/blender/draw/intern/draw_manager_exec.c M source/blender/editors/armature/armature_utils.c M source/blender/editors/curve/editcurve_paint.c M source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c M source/blender/editors/gpencil/gpencil_primitive.c M source/blender/editors/interface/interface_handlers.c M source/blender/editors/interface/interface_utils.c M source/blender/editors/mask/mask_ops.c M source/blender/editors/mesh/editmesh_utils.c M source/blender/editors/render/render_preview.c M source/blender/editors/screen/area.c M source/blender/editors/screen/area_utils.c M source/blender/editors/screen/screen_edit.c M source/blender/editors/screen/screen_ops.c M source/blender/editors/sculpt_paint/paint_image_proj.c M source/blender/editors/sculpt_paint/paint_stroke.c M source/blender/editors/sculpt_paint/sculpt.c M source/blender/editors/space_clip/tracking_ops.c M source/blender/editors/space_clip/tracking_ops_plane.c M source/blender/editors/space_image/image_undo.c M source/blender/editors/space_node/drawnode.c M source/blender/editors/space_view3d/view3d_edit.c M source/blender/editors/transform/transform_snap_object.c M source/blender/editors/uvedit/uvedit_ops.c M source/blender/gpencil_modifiers/intern/MOD_gpencilhook.c M source/blender/gpu/intern/gpu_buffers.c M source/blender/ikplugin/intern/iksolver_plugin.c M source/blender/makesrna/intern/makesrna.c M source/blender/modifiers/intern/MOD_hook.c M source/blender/modifiers/intern/MOD_screw.c M source/blender/modifiers/intern/MOD_warp.c M source/blender/modifiers/intern/MOD_weld.c M source/blender/python/mathutils/mathutils_bvhtree.c M source/blender/render/intern/source/initrender.c =================================================================== 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); + @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
