From fb5e2f56109e825ce3c446f80e075ee3dde81c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 4 Sep 2020 16:23:00 +0200 Subject: [PATCH] Cleanup: Clang-Tidy bugprone-incorrect-roundings fixes Should cause no noticeable difference. --- .clang-tidy | 1 - source/blender/blenkernel/intern/colortools.c | 8 +++--- source/blender/blenkernel/intern/sequencer.c | 5 ++-- .../blenkernel/intern/subdiv_ccg_mask.c | 6 +++-- .../intern/subdiv_displacement_multires.c | 6 +++-- .../operations/COM_WrapOperation.cpp | 6 +++-- source/blender/editors/screen/screen_ops.c | 2 +- .../blender/editors/space_graph/graph_draw.c | 2 +- .../editors/space_sequencer/sequencer_draw.c | 6 ++--- .../editors/space_sequencer/space_sequencer.c | 3 ++- .../freestyle/intern/stroke/StrokeRep.cpp | 4 ++- .../blender/ikplugin/intern/itasc_plugin.cpp | 3 ++- source/blender/imbuf/intern/bmp.c | 6 +++-- source/blender/imbuf/intern/filter.c | 4 ++- source/blender/imbuf/intern/imageprocess.c | 9 ++++--- source/blender/imbuf/intern/scaling.c | 26 ++++++++++--------- .../windowmanager/intern/wm_event_system.c | 3 ++- 17 files changed, 59 insertions(+), 41 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 2f1c82e31f5..2a4d4f3135c 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -25,7 +25,6 @@ Checks: > -bugprone-sizeof-expression, -bugprone-integer-division, - -bugprone-incorrect-roundings, -bugprone-copy-constructor-init, WarningsAsErrors: '*' diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 6fb2df04b3c..09731c15c0a 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -1320,10 +1320,10 @@ void BKE_histogram_update_sample_line(Histogram *hist, const float *fp; unsigned char *cp; - int x1 = 0.5f + hist->co[0][0] * ibuf->x; - int x2 = 0.5f + hist->co[1][0] * ibuf->x; - int y1 = 0.5f + hist->co[0][1] * ibuf->y; - int y2 = 0.5f + hist->co[1][1] * ibuf->y; + int x1 = roundf(hist->co[0][0] * ibuf->x); + int x2 = roundf(hist->co[1][0] * ibuf->x); + int y1 = roundf(hist->co[0][1] * ibuf->y); + int y2 = roundf(hist->co[1][1] * ibuf->y); struct ColormanageProcessor *cm_processor = NULL; diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 630c5f9fb1f..7897d2bb66e 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -24,6 +24,7 @@ * \ingroup bke */ +#include #include #include #include @@ -2204,8 +2205,8 @@ void BKE_sequencer_proxy_rebuild(SeqIndexBuildContext *context, BKE_sequencer_new_render_data(bmain, context->depsgraph, context->scene, - (scene->r.size * (float)scene->r.xsch) / 100.0f + 0.5f, - (scene->r.size * (float)scene->r.ysch) / 100.0f + 0.5f, + roundf((scene->r.size * (float)scene->r.xsch) / 100.0f), + roundf((scene->r.size * (float)scene->r.ysch) / 100.0f), 100, false, &render_context); diff --git a/source/blender/blenkernel/intern/subdiv_ccg_mask.c b/source/blender/blenkernel/intern/subdiv_ccg_mask.c index 0c02303dc2f..10cd7039948 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg_mask.c +++ b/source/blender/blenkernel/intern/subdiv_ccg_mask.c @@ -21,6 +21,8 @@ * \ingroup bke */ +#include + #include "BKE_subdiv_ccg.h" #include "DNA_mesh_types.h" @@ -87,8 +89,8 @@ BLI_INLINE float read_mask_grid(const GridPaintMask *mask_grid, return 0; } const int grid_size = BKE_subdiv_grid_size_from_level(mask_grid->level); - const int x = (grid_u * (grid_size - 1) + 0.5f); - const int y = (grid_v * (grid_size - 1) + 0.5f); + const int x = roundf(grid_u * (grid_size - 1)); + const int y = roundf(grid_v * (grid_size - 1)); return mask_grid->data[y * grid_size + x]; } diff --git a/source/blender/blenkernel/intern/subdiv_displacement_multires.c b/source/blender/blenkernel/intern/subdiv_displacement_multires.c index a63c2994687..69cac840276 100644 --- a/source/blender/blenkernel/intern/subdiv_displacement_multires.c +++ b/source/blender/blenkernel/intern/subdiv_displacement_multires.c @@ -21,6 +21,8 @@ * \ingroup bke */ +#include + #include "BKE_subdiv.h" #include "DNA_mesh_types.h" @@ -122,8 +124,8 @@ BLI_INLINE eAverageWith read_displacement_grid(const MDisps *displacement_grid, zero_v3(r_tangent_D); return AVERAGE_WITH_NONE; } - const int x = (grid_u * (grid_size - 1) + 0.5f); - const int y = (grid_v * (grid_size - 1) + 0.5f); + const int x = roundf(grid_u * (grid_size - 1)); + const int y = roundf(grid_v * (grid_size - 1)); copy_v3_v3(r_tangent_D, displacement_grid->disps[y * grid_size + x]); if (x == 0 && y == 0) { return AVERAGE_WITH_ALL; diff --git a/source/blender/compositor/operations/COM_WrapOperation.cpp b/source/blender/compositor/operations/COM_WrapOperation.cpp index c25e8ba897c..952f69c3787 100644 --- a/source/blender/compositor/operations/COM_WrapOperation.cpp +++ b/source/blender/compositor/operations/COM_WrapOperation.cpp @@ -16,6 +16,8 @@ * Copyright 2011, Blender Foundation. */ +#include + #include "COM_WrapOperation.h" WrapOperation::WrapOperation(DataType datatype) : ReadBufferOperation(datatype) @@ -90,7 +92,7 @@ bool WrapOperation::determineDependingAreaOfInterest(rcti *input, if (m_wrappingType == CMP_NODE_WRAP_X || m_wrappingType == CMP_NODE_WRAP_XY) { // wrap only on the x-axis if tile is wrapping newInput.xmin = getWrappedOriginalXPos(input->xmin); - newInput.xmax = getWrappedOriginalXPos(input->xmax) + 0.5f; + newInput.xmax = roundf(getWrappedOriginalXPos(input->xmax)); if (newInput.xmin >= newInput.xmax) { newInput.xmin = 0; newInput.xmax = this->getWidth(); @@ -99,7 +101,7 @@ bool WrapOperation::determineDependingAreaOfInterest(rcti *input, if (m_wrappingType == CMP_NODE_WRAP_Y || m_wrappingType == CMP_NODE_WRAP_XY) { // wrap only on the y-axis if tile is wrapping newInput.ymin = getWrappedOriginalYPos(input->ymin); - newInput.ymax = getWrappedOriginalYPos(input->ymax) + 0.5f; + newInput.ymax = roundf(getWrappedOriginalYPos(input->ymax)); if (newInput.ymin >= newInput.ymax) { newInput.ymin = 0; newInput.ymax = this->getHeight(); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index d9ca008ff81..6c3b47db155 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -4475,7 +4475,7 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv scene->r.cfra++; } else { - scene->r.cfra = max_ii(scene->r.cfra, newfra + 0.5); + scene->r.cfra = max_ii(scene->r.cfra, round(newfra)); } #ifdef PROFILE_AUDIO_SYNCH diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index ac860b72e84..70d29b52630 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -567,7 +567,7 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu_, View2D *v2 * the displayed values appear correctly in the viewport */ - n = (etime - stime) / samplefreq + 0.5f; + n = roundf((etime - stime) / samplefreq); if (n > 0) { immBegin(GPU_PRIM_LINE_STRIP, (n + 1)); diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 6cfd33df7bf..298ed927b44 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -1262,8 +1262,8 @@ ImBuf *sequencer_ibuf_get(struct Main *bmain, render_size = BKE_sequencer_rendersize_to_scale_factor(sseq->render_size); } - rectx = render_size * scene->r.xsch + 0.5; - recty = render_size * scene->r.ysch + 0.5; + rectx = roundf(render_size * scene->r.xsch); + recty = roundf(render_size * scene->r.ysch); BKE_sequencer_new_render_data( bmain, depsgraph, scene, rectx, recty, sseq->render_size, false, &context); @@ -1800,7 +1800,7 @@ void sequencer_draw_preview(const bContext *C, /* Setup view. */ sequencer_display_size(scene, viewrect); - UI_view2d_totRect_set(v2d, viewrect[0] + 0.5f, viewrect[1] + 0.5f); + UI_view2d_totRect_set(v2d, roundf(viewrect[0] + 0.5f), roundf(viewrect[1] + 0.5f)); UI_view2d_curRect_validate(v2d); UI_view2d_view_ortho(v2d); diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index 4a6bd0de60c..cce99cd9f08 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -21,6 +21,7 @@ * \ingroup spseq */ +#include #include #include @@ -304,7 +305,7 @@ static void sequencer_refresh(const bContext *C, ScrArea *area) /* Final check that both preview and main height are reasonable. */ if (region_preview->sizey < 10 || region_main->sizey < 10 || region_preview->sizey + region_main->sizey > height) { - region_preview->sizey = (int)(height * 0.4f + 0.5f); + region_preview->sizey = roundf(height * 0.4f); region_main->sizey = (int)(height - region_preview->sizey); view_changed = true; } diff --git a/source/blender/freestyle/intern/stroke/StrokeRep.cpp b/source/blender/freestyle/intern/stroke/StrokeRep.cpp index 661c144476c..fe12727b0c0 100644 --- a/source/blender/freestyle/intern/stroke/StrokeRep.cpp +++ b/source/blender/freestyle/intern/stroke/StrokeRep.cpp @@ -19,6 +19,8 @@ * \brief Class to define the representation of a stroke (for display purpose) */ +#include + #include "StrokeRep.h" #include "Stroke.h" #include "StrokeAdvancedIterators.h" @@ -573,7 +575,7 @@ void Strip::computeTexCoordWithTips(const vector &iStrokeVertice v = iStrokeVertices.begin(); vend = iStrokeVertices.end(); l = (*v)->strokeLength() / spacedThickness; - tiles = int(l + 0.5); // round to the nearest + tiles = std::roundf(l); // round to the nearest fact = (float(tiles) + 0.5) / l; #if 0 diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index a5fdb9ef491..0bc73d4812b 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -22,6 +22,7 @@ * \ingroup ikplugin */ +#include #include #include #include @@ -1765,7 +1766,7 @@ static void execute_scene(struct Depsgraph *depsgraph, if (ikscene->cache && !reiterate && simulation) { iTaSC::CacheTS sts, cts; - sts = cts = (iTaSC::CacheTS)(timestamp * 1000.0 + 0.5); + sts = cts = (iTaSC::CacheTS)std::round(timestamp * 1000.0); if (ikscene->cache->getPreviousCacheItem(ikscene->armature, 0, &cts) == NULL || cts == 0) { // the cache is empty before this time, reiterate if (ikparam->flag & ITASC_INITIAL_REITERATION) { diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index 31f8b651eff..f517a3c15e8 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -21,6 +21,8 @@ * \ingroup imbuf */ +#include + #include "BLI_fileops.h" #include "BLI_utildefines.h" @@ -327,8 +329,8 @@ int imb_savebmp(ImBuf *ibuf, const char *name, int UNUSED(flags)) putShortLSB(is_grayscale ? 8 : 24, ofile); putIntLSB(0, ofile); putIntLSB(bytesize, ofile); - putIntLSB((int)(ibuf->ppm[0] + 0.5), ofile); - putIntLSB((int)(ibuf->ppm[1] + 0.5), ofile); + putIntLSB(round(ibuf->ppm[0] + 0.5), ofile); + putIntLSB(round(ibuf->ppm[1] + 0.5), ofile); putIntLSB(0, ofile); putIntLSB(0, ofile); diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 12f90f27309..cce264624ce 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -22,6 +22,8 @@ * \ingroup imbuf */ +#include + #include "MEM_guardedalloc.h" #include "BLI_math_base.h" @@ -527,7 +529,7 @@ void IMB_filter_extend(struct ImBuf *ibuf, char *mask, int filter) else { for (c = 0; c < depth; c++) { ((unsigned char *)dstbuf)[depth * index + c] = - acc[c] > 255 ? 255 : (acc[c] < 0 ? 0 : ((unsigned char)(acc[c] + 0.5f))); + acc[c] > 255 ? 255 : (acc[c] < 0 ? 0 : (unsigned char)roundf(acc[c])); } } diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c index bf58f047773..8525991aa40 100644 --- a/source/blender/imbuf/intern/imageprocess.c +++ b/source/blender/imbuf/intern/imageprocess.c @@ -27,6 +27,7 @@ * but we'll keep it here for the time being. (nzc) */ +#include #include #include "MEM_guardedalloc.h" @@ -202,10 +203,10 @@ void bilinear_interpolation_color_wrap( /* need to add 0.5 to avoid rounding down (causes darken with the smear brush) * tested with white images and this should not wrap back to zero */ - outI[0] = (ma_mb * row1I[0] + a_mb * row3I[0] + ma_b * row2I[0] + a_b * row4I[0]) + 0.5f; - outI[1] = (ma_mb * row1I[1] + a_mb * row3I[1] + ma_b * row2I[1] + a_b * row4I[1]) + 0.5f; - outI[2] = (ma_mb * row1I[2] + a_mb * row3I[2] + ma_b * row2I[2] + a_b * row4I[2]) + 0.5f; - outI[3] = (ma_mb * row1I[3] + a_mb * row3I[3] + ma_b * row2I[3] + a_b * row4I[3]) + 0.5f; + outI[0] = roundf(ma_mb * row1I[0] + a_mb * row3I[0] + ma_b * row2I[0] + a_b * row4I[0]); + outI[1] = roundf(ma_mb * row1I[1] + a_mb * row3I[1] + ma_b * row2I[1] + a_b * row4I[1]); + outI[2] = roundf(ma_mb * row1I[2] + a_mb * row3I[2] + ma_b * row2I[2] + a_b * row4I[2]); + outI[3] = roundf(ma_mb * row1I[3] + a_mb * row3I[3] + ma_b * row2I[3] + a_b * row4I[3]); } } diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index 1fd9bba68f3..fbd50374711 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -22,6 +22,8 @@ * \ingroup imbuf */ +#include + #include "BLI_math_color.h" #include "BLI_math_interp.h" #include "BLI_utildefines.h" @@ -1000,10 +1002,10 @@ static ImBuf *scaledownx(struct ImBuf *ibuf, int newx) val[3] = rect[3]; rect += 4; - newrect[0] = ((nval[0] + sample * val[0]) / add + 0.5f); - newrect[1] = ((nval[1] + sample * val[1]) / add + 0.5f); - newrect[2] = ((nval[2] + sample * val[2]) / add + 0.5f); - newrect[3] = ((nval[3] + sample * val[3]) / add + 0.5f); + newrect[0] = roundf((nval[0] + sample * val[0]) / add); + newrect[1] = roundf((nval[1] + sample * val[1]) / add); + newrect[2] = roundf((nval[2] + sample * val[2]) / add); + newrect[3] = roundf((nval[3] + sample * val[3]) / add); newrect += 4; } @@ -1142,10 +1144,10 @@ static ImBuf *scaledowny(struct ImBuf *ibuf, int newy) val[3] = rect[3]; rect += skipx; - newrect[0] = ((nval[0] + sample * val[0]) / add + 0.5f); - newrect[1] = ((nval[1] + sample * val[1]) / add + 0.5f); - newrect[2] = ((nval[2] + sample * val[2]) / add + 0.5f); - newrect[3] = ((nval[3] + sample * val[3]) / add + 0.5f); + newrect[0] = roundf((nval[0] + sample * val[0]) / add); + newrect[1] = roundf((nval[1] + sample * val[1]) / add); + newrect[2] = roundf((nval[2] + sample * val[2]) / add); + newrect[3] = roundf((nval[3] + sample * val[3]) / add); newrect += skipx; } @@ -1573,8 +1575,8 @@ static void scalefast_Z_ImBuf(ImBuf *ibuf, int newx, int newy) return; } - stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5; - stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5; + stepx = round(65536.0 * (ibuf->x - 1.0) / (newx - 1.0)); + stepy = round(65536.0 * (ibuf->y - 1.0) / (newy - 1.0)); ofsy = 32768; newzbuf = _newzbuf; @@ -1713,8 +1715,8 @@ bool IMB_scalefastImBuf(struct ImBuf *ibuf, unsigned int newx, unsigned int newy newrectf = _newrectf; } - stepx = (65536.0 * (ibuf->x - 1.0) / (newx - 1.0)) + 0.5; - stepy = (65536.0 * (ibuf->y - 1.0) / (newy - 1.0)) + 0.5; + stepx = round(65536.0 * (ibuf->x - 1.0) / (newx - 1.0)); + stepy = round(65536.0 * (ibuf->y - 1.0) / (newy - 1.0)); ofsy = 32768; for (y = newy; y > 0; y--, ofsy += stepy) { diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 6f7c074c704..c89eac815d5 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -25,6 +25,7 @@ * Also some operator reports utility functions. */ +#include #include #include @@ -3230,7 +3231,7 @@ void wm_event_do_handlers(bContext *C) if (is_playing_sound == 0) { const double time = BKE_sound_sync_scene(scene_eval); if (isfinite(time)) { - int ncfra = time * FPS + 0.5; + int ncfra = round(time * FPS); if (ncfra != scene->r.cfra) { scene->r.cfra = ncfra; ED_update_for_newframe(CTX_data_main(C), depsgraph);