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/interface | |
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/interface')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 16 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_utils.c | 2 |
2 files changed, 9 insertions, 9 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index e2909af47f3..6a9632f54bb 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -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++) { diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 63e382e2280..034bd906add 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -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) { |