Cleanup: Clang-Tidy bugprone-incorrect-roundings fixes

Should cause no noticeable difference.
This commit is contained in:
Sybren A. Stüvel 2020-09-04 16:23:00 +02:00
parent ee49ce482a
commit fb5e2f5610
17 changed files with 59 additions and 41 deletions

View File

@ -25,7 +25,6 @@ Checks: >
-bugprone-sizeof-expression,
-bugprone-integer-division,
-bugprone-incorrect-roundings,
-bugprone-copy-constructor-init,
WarningsAsErrors: '*'

View File

@ -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;

View File

@ -24,6 +24,7 @@
* \ingroup bke
*/
#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@ -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);

View File

@ -21,6 +21,8 @@
* \ingroup bke
*/
#include <math.h>
#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];
}

View File

@ -21,6 +21,8 @@
* \ingroup bke
*/
#include <math.h>
#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;

View File

@ -16,6 +16,8 @@
* Copyright 2011, Blender Foundation.
*/
#include <math.h>
#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();

View File

@ -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

View File

@ -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));

View File

@ -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);

View File

@ -21,6 +21,7 @@
* \ingroup spseq
*/
#include <math.h>
#include <stdio.h>
#include <string.h>
@ -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;
}

View File

@ -19,6 +19,8 @@
* \brief Class to define the representation of a stroke (for display purpose)
*/
#include <cmath>
#include "StrokeRep.h"
#include "Stroke.h"
#include "StrokeAdvancedIterators.h"
@ -573,7 +575,7 @@ void Strip::computeTexCoordWithTips(const vector<StrokeVertex *> &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

View File

@ -22,6 +22,7 @@
* \ingroup ikplugin
*/
#include <cmath>
#include <stdlib.h>
#include <string.h>
#include <vector>
@ -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) {

View File

@ -21,6 +21,8 @@
* \ingroup imbuf
*/
#include <math.h>
#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);

View File

@ -22,6 +22,8 @@
* \ingroup imbuf
*/
#include <math.h>
#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]));
}
}

View File

@ -27,6 +27,7 @@
* but we'll keep it here for the time being. (nzc)
*/
#include <math.h>
#include <stdlib.h>
#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]);
}
}

View File

@ -22,6 +22,8 @@
* \ingroup imbuf
*/
#include <math.h>
#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) {

View File

@ -25,6 +25,7 @@
* Also some operator reports utility functions.
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
@ -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);