[Bf-blender-cvs] [fb5e2f56109] master: Cleanup: Clang-Tidy bugprone-incorrect-roundings fixes
Sybren A. Stüvel
noreply at git.blender.org
Fri Sep 4 16:24:14 CEST 2020
Commit: fb5e2f56109e825ce3c446f80e075ee3dde81c3d
Author: Sybren A. Stüvel
Date: Fri Sep 4 16:23:00 2020 +0200
Branches: master
https://developer.blender.org/rBfb5e2f56109e825ce3c446f80e075ee3dde81c3d
Cleanup: Clang-Tidy bugprone-incorrect-roundings fixes
Should cause no noticeable difference.
===================================================================
M .clang-tidy
M source/blender/blenkernel/intern/colortools.c
M source/blender/blenkernel/intern/sequencer.c
M source/blender/blenkernel/intern/subdiv_ccg_mask.c
M source/blender/blenkernel/intern/subdiv_displacement_multires.c
M source/blender/compositor/operations/COM_WrapOperation.cpp
M source/blender/editors/screen/screen_ops.c
M source/blender/editors/space_graph/graph_draw.c
M source/blender/editors/space_sequencer/sequencer_draw.c
M source/blender/editors/space_sequencer/space_sequencer.c
M source/blender/freestyle/intern/stroke/StrokeRep.cpp
M source/blender/ikplugin/intern/itasc_plugin.cpp
M source/blender/imbuf/intern/bmp.c
M source/blender/imbuf/intern/filter.c
M source/blender/imbuf/intern/imageprocess.c
M source/blender/imbuf/intern/scaling.c
M source/blender/windowmanager/intern/wm_event_system.c
===================================================================
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 <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);
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 <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];
}
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 <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;
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 <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();
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 <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;
}
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 <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
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 <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->armat
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list