diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-03-06 19:18:10 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2020-03-09 16:47:59 +0300 |
commit | 598ab525da3df3fef2033c159c570688c7282a8f (patch) | |
tree | ba2bd0b8fc6ee5d264512bf655def1a6ee5d7b31 /source/blender/editors/sculpt_paint | |
parent | ee5d7bc16b243f309c84bce5deddf3a86b7f4c14 (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/editors/sculpt_paint')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image_proj.c | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_stroke.c | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 11 |
3 files changed, 9 insertions, 8 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 0f5ebcf9f71..cac377c7e33 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -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) { diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 72422770587..ee114d5f662 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -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; } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 41bbaa94904..0fb5897628f 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -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; |