From 598ab525da3df3fef2033c159c570688c7282a8f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 6 Mar 2020 17:18:10 +0100 Subject: 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 --- source/blender/editors/armature/armature_utils.c | 3 ++- source/blender/editors/curve/editcurve_paint.c | 6 +++--- .../gizmo_library/gizmo_types/arrow3d_gizmo.c | 4 ++-- source/blender/editors/gpencil/gpencil_primitive.c | 2 +- .../blender/editors/interface/interface_handlers.c | 16 ++++++++-------- source/blender/editors/interface/interface_utils.c | 2 +- source/blender/editors/mask/mask_ops.c | 4 ++-- source/blender/editors/mesh/editmesh_utils.c | 2 +- source/blender/editors/render/render_preview.c | 4 ++-- source/blender/editors/screen/area.c | 10 +++++----- source/blender/editors/screen/area_utils.c | 2 +- source/blender/editors/screen/screen_edit.c | 16 ++++++++-------- source/blender/editors/screen/screen_ops.c | 20 ++++++++++---------- .../blender/editors/sculpt_paint/paint_image_proj.c | 4 ++-- source/blender/editors/sculpt_paint/paint_stroke.c | 2 +- source/blender/editors/sculpt_paint/sculpt.c | 11 ++++++----- source/blender/editors/space_clip/tracking_ops.c | 2 +- .../blender/editors/space_clip/tracking_ops_plane.c | 2 +- source/blender/editors/space_image/image_undo.c | 10 +++++----- source/blender/editors/space_node/drawnode.c | 6 +++--- source/blender/editors/space_view3d/view3d_edit.c | 4 ++-- .../editors/transform/transform_snap_object.c | 16 ++++++++-------- source/blender/editors/uvedit/uvedit_ops.c | 2 +- 23 files changed, 76 insertions(+), 74 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c index a291bbc66e8..76361f6785b 100644 --- a/source/blender/editors/armature/armature_utils.c +++ b/source/blender/editors/armature/armature_utils.c @@ -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 */ diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c index f97214991ef..85441c9b88d 100644 --- a/source/blender/editors/curve/editcurve_paint.c +++ b/source/blender/editors/curve/editcurve_paint.c @@ -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); } } diff --git a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c index 5a256c24c59..909be74cced 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/arrow3d_gizmo.c @@ -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; } } diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 3ec14ee43b9..ad54382dde7 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -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 */ 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) { diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index cff0bcef38b..50f7466f7ed 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -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; } } diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index e5f436bbe48..d281dc46b2c 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -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; diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index b6c588c8c33..369572a5d6d 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -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; } diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 85d84ad6864..e72818479c4 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -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; } } diff --git a/source/blender/editors/screen/area_utils.c b/source/blender/editors/screen/area_utils.c index 003ba46be4f..cacd6b1edd7 100644 --- a/source/blender/editors/screen/area_utils.c +++ b/source/blender/editors/screen/area_utils.c @@ -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; diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 2000c707b8e..d62ea73876f 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -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; } } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 74c65765cbe..a9f44f54b3a 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -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; } } 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; diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 030b0625e32..aab60f8bc6e 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -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( diff --git a/source/blender/editors/space_clip/tracking_ops_plane.c b/source/blender/editors/space_clip/tracking_ops_plane.c index ced51e4502a..00861ab0270 100644 --- a/source/blender/editors/space_clip/tracking_ops_plane.c +++ b/source/blender/editors/space_clip/tracking_ops_plane.c @@ -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, diff --git a/source/blender/editors/space_image/image_undo.c b/source/blender/editors/space_image/image_undo.c index 79aa4d2ed7f..d18eb9a5410 100644 --- a/source/blender/editors/space_image/image_undo.c +++ b/source/blender/editors/space_image/image_undo.c @@ -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; } diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 148c1669b06..beaa8c2617e 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -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); } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 415c275090d..13b38a04f63 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -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; } } diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c index 841bc11edf1..e2d97ef9a91 100644 --- a/source/blender/editors/transform/transform_snap_object.c +++ b/source/blender/editors/transform/transform_snap_object.c @@ -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); diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 7172db788f1..41bb51340fc 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -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); -- cgit v1.2.3