From b8b412230b1e1ed43295d5c299477a2cba73355e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 15 Jan 2014 13:00:03 +1100 Subject: Code Cleanup: use iroundf also increase precision of rctf print functions --- source/blender/blenlib/intern/rct.c | 2 +- source/blender/editors/animation/anim_markers.c | 6 +++--- source/blender/editors/animation/anim_ops.c | 7 ++++--- source/blender/editors/armature/pose_slide.c | 2 +- source/blender/editors/gpencil/drawgpencil.c | 8 ++++---- source/blender/editors/interface/interface_handlers.c | 2 +- source/blender/editors/interface/interface_panel.c | 4 ++-- source/blender/editors/screen/glutil.c | 2 +- source/blender/editors/space_action/action_edit.c | 6 +++--- source/blender/editors/space_clip/clip_ops.c | 2 +- source/blender/editors/space_graph/graph_edit.c | 6 +++--- source/blender/editors/space_graph/graph_ops.c | 3 ++- source/blender/editors/transform/transform_conversions.c | 6 +++--- source/blender/modifiers/intern/MOD_meshcache_util.c | 2 +- source/blender/render/intern/source/imagetexture.c | 4 ++-- source/blender/windowmanager/intern/wm_gesture.c | 4 ++-- 16 files changed, 34 insertions(+), 32 deletions(-) diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index c59a0195cb6..51bd9eee0a6 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -552,7 +552,7 @@ void BLI_rctf_rcti_copy(rctf *dst, const rcti *src) void print_rctf(const char *str, const rctf *rect) { - printf("%s: xmin %.3f, xmax %.3f, ymin %.3f, ymax %.3f (%.3fx%.3f)\n", str, + printf("%s: xmin %.8f, xmax %.8f, ymin %.8f, ymax %.8f (%.12fx%.12f)\n", str, rect->xmin, rect->xmax, rect->ymin, rect->ymax, BLI_rctf_size_x(rect), BLI_rctf_size_y(rect)); } diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index e65ca3d20be..f95807b55ea 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -144,7 +144,7 @@ int ED_markers_post_apply_transform(ListBase *markers, Scene *scene, int mode, f (side == 'L' && marker->frame < cfra) || (side == 'R' && marker->frame >= cfra)) { - marker->frame += (int)floorf(value + 0.5f); + marker->frame += iroundf(value); changed_tot++; } break; @@ -152,7 +152,7 @@ int ED_markers_post_apply_transform(ListBase *markers, Scene *scene, int mode, f case TFM_TIME_SCALE: { /* rescale the distance between the marker and the current frame */ - marker->frame = cfra + (int)floorf(((float)(marker->frame - cfra) * value) + 0.5f); + marker->frame = cfra + iroundf((float)(marker->frame - cfra) * value); changed_tot++; break; } @@ -190,7 +190,7 @@ TimeMarker *ED_markers_find_nearest_marker(ListBase *markers, float x) int ED_markers_find_nearest_marker_time(ListBase *markers, float x) { TimeMarker *nearest = ED_markers_find_nearest_marker(markers, x); - return (nearest) ? (nearest->frame) : (int)floor(x + 0.5f); + return (nearest) ? (nearest->frame) : iroundf(x); } diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index af9b58736ef..48b310b57ed 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -35,6 +35,7 @@ #include "BLI_sys_types.h" #include "BLI_utildefines.h" +#include "BLI_math_base.h" #include "DNA_anim_types.h" #include "DNA_scene_types.h" @@ -126,7 +127,7 @@ static int frame_from_event(bContext *C, const wmEvent *event) UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &viewx, NULL); /* round result to nearest int (frames are ints!) */ - frame = (int)floor(viewx + 0.5f); + frame = iroundf(viewx); if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) { CLAMP(frame, PSFRA, PEFRA); @@ -223,8 +224,8 @@ static int previewrange_define_exec(bContext *C, wmOperator *op) if (efra < sfra) efra = sfra; scene->r.flag |= SCER_PRV_RANGE; - scene->r.psfra = (int)floor(sfra + 0.5f); - scene->r.pefra = (int)floor(efra + 0.5f); + scene->r.psfra = iroundf(sfra); + scene->r.pefra = iroundf(efra); /* send notifiers */ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); diff --git a/source/blender/editors/armature/pose_slide.c b/source/blender/editors/armature/pose_slide.c index 82652702fe7..ec49dad69b5 100644 --- a/source/blender/editors/armature/pose_slide.c +++ b/source/blender/editors/armature/pose_slide.c @@ -1129,7 +1129,7 @@ static void pose_propagate_fcurve(wmOperator *op, Object *ob, FCurve *fcu, /* stop on matching marker if there is one */ for (ce = modeData.sel_markers.first; ce; ce = ce->next) { - if (ce->cfra == (int)(floor(bezt->vec[1][0] + 0.5f))) + if (ce->cfra == iroundf(bezt->vec[1][0])) break; } diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 294a50909cb..971ab4dbda5 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -784,10 +784,10 @@ void draw_gpencil_view3d(Scene *scene, View3D *v3d, ARegion *ar, bool only3d) rctf rectf; ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, TRUE); /* no shift */ - offsx = floorf(rectf.xmin + 0.5f); - offsy = floorf(rectf.ymin + 0.5f); - winx = floorf((rectf.xmax - rectf.xmin) + 0.5f); - winy = floorf((rectf.ymax - rectf.ymin) + 0.5f); + offsx = iroundf(rectf.xmin); + offsy = iroundf(rectf.ymin); + winx = iroundf(rectf.xmax - rectf.xmin); + winy = iroundf(rectf.ymax - rectf.ymin); } else { offsx = 0; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index ae456669257..2e02e442a66 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3660,7 +3660,7 @@ static int ui_do_but_LISTBOX(bContext *C, uiBlock *block, uiBut *but, uiHandleBu int newsize = *size; int diff = dragy - my; - diff = (int)floorf(((float)diff / (float)UI_UNIT_Y) + 0.5f); + diff = iroundf((float)diff / (float)UI_UNIT_Y); /* If we are not in autosize mode, default behavior... */ if (*size > 0) { diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index bc257e852de..054f1132d65 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -821,8 +821,8 @@ static bool uiAlignPanelStep(ScrArea *sa, ARegion *ar, const float fac, const bo for (a = 0; a < tot; a++, ps++) { if ((ps->pa->flag & PNL_SELECT) == 0) { if ((ps->orig->ofsx != ps->pa->ofsx) || (ps->orig->ofsy != ps->pa->ofsy)) { - ps->orig->ofsx = floorf(0.5f + fac * (float)ps->pa->ofsx + (1.0f - fac) * (float)ps->orig->ofsx); - ps->orig->ofsy = floorf(0.5f + fac * (float)ps->pa->ofsy + (1.0f - fac) * (float)ps->orig->ofsy); + ps->orig->ofsx = iroundf(fac * (float)ps->pa->ofsx + (1.0f - fac) * (float)ps->orig->ofsx); + ps->orig->ofsy = iroundf(fac * (float)ps->pa->ofsy + (1.0f - fac) * (float)ps->orig->ofsy); done = true; } } diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 9cdb6de99b0..123ca68992a 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -874,7 +874,7 @@ void bglBegin(int mode) glGetFloatv(GL_POINT_SIZE_RANGE, value); if (value[1] < 2.0f) { glGetFloatv(GL_POINT_SIZE, value); - pointhack = floor(value[0] + 0.5f); + pointhack = iroundf(value[0]); if (pointhack > 4) pointhack = 4; } else { diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 7142a6339a3..e2ca45bbdc9 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -337,8 +337,8 @@ static int actkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op)) /* set the range directly */ get_keyframe_extents(&ac, &min, &max, FALSE); scene->r.flag |= SCER_PRV_RANGE; - scene->r.psfra = (int)floor(min + 0.5f); - scene->r.pefra = (int)floor(max + 0.5f); + scene->r.psfra = iroundf(min); + scene->r.pefra = iroundf(max); /* set notifier that things have changed */ // XXX err... there's nothing for frame ranges yet, but this should do fine too @@ -1372,7 +1372,7 @@ static int actkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) /* set the new current frame value, based on the average time */ if (ked.i1) { Scene *scene = ac.scene; - CFRA = (int)floor((ked.f1 / ked.i1) + 0.5f); + CFRA = iroundf(ked.f1 / ked.i1); SUBFRA = 0.f; } diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 9aa6eab7fc8..e02fca80894 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -868,7 +868,7 @@ static int frame_from_event(bContext *C, const wmEvent *event) UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy); - framenr = (int) floor(viewx + 0.5f); + framenr = iroundf(viewx); } return framenr; diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 0f3ba9865c4..68d82cd2848 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -189,8 +189,8 @@ static int graphkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op)) /* set the range directly */ get_graph_keyframe_extents(&ac, &min, &max, NULL, NULL, FALSE, FALSE); scene->r.flag |= SCER_PRV_RANGE; - scene->r.psfra = (int)floor(min + 0.5f); - scene->r.pefra = (int)floor(max + 0.5f); + scene->r.psfra = iroundf(min); + scene->r.pefra = iroundf(max); /* set notifier that things have changed */ // XXX err... there's nothing for frame ranges yet, but this should do fine too @@ -1825,7 +1825,7 @@ static int graphkeys_framejump_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = ac.scene; /* take the average values, rounding to the nearest int for the current frame */ - CFRA = (int)floor((ked.f1 / ked.i1) + 0.5f); + CFRA = iroundf(ked.f1 / ked.i1); SUBFRA = 0.f; sipo->cursorVal = ked.f2 / (float)ked.i1; } diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 74114f8ca9d..4409a5b180e 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -37,6 +37,7 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" +#include "BLI_math_base.h" #include "BKE_context.h" #include "BKE_global.h" @@ -123,7 +124,7 @@ static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent /* store the values in the operator properties */ /* frame is rounded to the nearest int, since frames are ints */ - RNA_int_set(op->ptr, "frame", (int)floor(viewx + 0.5f)); + RNA_int_set(op->ptr, "frame", iroundf(viewx)); RNA_float_set(op->ptr, "value", viewy); } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 2b8e57fd284..d19bf8daedc 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2429,7 +2429,7 @@ void flushTransSeq(TransInfo *t) tdsq = (TransDataSeq *)td->extra; seq = tdsq->seq; old_start = seq->start; - new_frame = (int)floor(td2d->loc[0] + 0.5f); + new_frame = iroundf(td2d->loc[0]); switch (tdsq->sel_flag) { case SELECT: @@ -2441,7 +2441,7 @@ void flushTransSeq(TransInfo *t) seq->start = new_frame - tdsq->start_offset; #endif if (seq->depth == 0) { - seq->machine = (int)floor(td2d->loc[1] + 0.5f); + seq->machine = iroundf(td2d->loc[1]); CLAMP(seq->machine, 1, MAXSEQ); } break; @@ -3390,7 +3390,7 @@ void flushTransIntFrameActionData(TransInfo *t) /* flush data! */ for (i = 0; i < t->total; i++, tfd++) { - *(tfd->sdata) = (int)floor(tfd->val + 0.5f); + *(tfd->sdata) = iroundf(tfd->val); } } diff --git a/source/blender/modifiers/intern/MOD_meshcache_util.c b/source/blender/modifiers/intern/MOD_meshcache_util.c index 404d0538a29..10560a85a3f 100644 --- a/source/blender/modifiers/intern/MOD_meshcache_util.c +++ b/source/blender/modifiers/intern/MOD_meshcache_util.c @@ -40,7 +40,7 @@ void MOD_meshcache_calc_range(const float frame, const char interp, int r_index_range[2], float *r_factor) { if (interp == MOD_MESHCACHE_INTERP_NONE) { - r_index_range[0] = r_index_range[1] = max_ii(0, min_ii(frame_tot - 1, (int)(floorf(frame) + 0.5f))); + r_index_range[0] = r_index_range[1] = max_ii(0, min_ii(frame_tot - 1, iroundf(frame))); *r_factor = 1.0f; /* dummy */ } else { diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index 37c6a5ffdd1..716c4b8af65 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -1317,7 +1317,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex a = max_ff(a, 1.0f); b = max_ff(b, 1.0f); fProbes = 2.f*(a / b) - 1.f; - AFD.iProbes = (int)floorf(fProbes + 0.5f); + AFD.iProbes = iroundf(fProbes); AFD.iProbes = MIN2(AFD.iProbes, tex->afmax); if (AFD.iProbes < fProbes) b = 2.f*a / (float)(AFD.iProbes + 1); @@ -1420,7 +1420,7 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex b = max_ff(b, 1.0f); fProbes = 2.f*(a / b) - 1.f; /* no limit to number of Probes here */ - AFD.iProbes = (int)floorf(fProbes + 0.5f); + AFD.iProbes = iroundf(fProbes); if (AFD.iProbes < fProbes) b = 2.f*a / (float)(AFD.iProbes + 1); AFD.majrad = a/ff; AFD.minrad = b/ff; diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c index 33758d9699d..83cb6fd83d1 100644 --- a/source/blender/windowmanager/intern/wm_gesture.c +++ b/source/blender/windowmanager/intern/wm_gesture.c @@ -136,8 +136,8 @@ int wm_gesture_evaluate(wmGesture *gesture) rcti *rect = gesture->customdata; int dx = BLI_rcti_size_x(rect); int dy = BLI_rcti_size_y(rect); - if (ABS(dx) + ABS(dy) > U.tweak_threshold) { - int theta = (int)floor(4.0f * atan2f((float)dy, (float)dx) / (float)M_PI + 0.5f); + if (abs(dx) + abs(dy) > U.tweak_threshold) { + int theta = iroundf(4.0f * atan2f((float)dy, (float)dx) / (float)M_PI); int val = EVT_GESTURE_W; if (theta == 0) val = EVT_GESTURE_E; -- cgit v1.2.3