From ffa30d75a35090cc1f74656c413dc1b9be08d86e Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Tue, 7 Jan 2020 23:27:29 +0000 Subject: [PATCH] Replace round_nearest with KiROUND --- libs/kimath/include/math/util.h | 5 ----- libs/kimath/src/geometry/geometry_utils.cpp | 4 ++-- libs/kimath/src/geometry/shape_poly_set.cpp | 24 ++++++++++----------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/libs/kimath/include/math/util.h b/libs/kimath/include/math/util.h index 0657aa6a61..7d13679c71 100644 --- a/libs/kimath/include/math/util.h +++ b/libs/kimath/include/math/util.h @@ -99,9 +99,4 @@ int rescale( int aNumerator, int aValue, int aDenominator ); template <> int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator ); -static inline int round_nearest( double v ) -{ - return int( v < 0 ? v - 0.5 : v + 0.5 ); -} - #endif // UTIL_H diff --git a/libs/kimath/src/geometry/geometry_utils.cpp b/libs/kimath/src/geometry/geometry_utils.cpp index d2448589a0..74625f28cc 100644 --- a/libs/kimath/src/geometry/geometry_utils.cpp +++ b/libs/kimath/src/geometry/geometry_utils.cpp @@ -32,7 +32,7 @@ #include #include -#include // for round_nearest +#include // for KiROUND // To approximate a circle by segments, a minimal seg count is mandatory #define MIN_SEGCOUNT_FOR_CIRCLE 6 @@ -51,7 +51,7 @@ int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree ) // (360.0 degrees). For very small radius values, this is mandatory. arc_increment = std::min( 360.0/MIN_SEGCOUNT_FOR_CIRCLE, arc_increment ); - int segCount = round_nearest( fabs( aArcAngleDegree ) / arc_increment ); + int segCount = KiROUND( fabs( aArcAngleDegree ) / arc_increment ); // Ensure at least one segment is used (can happen for small arcs) return std::max( segCount, 1 ); diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index 73c7a2d9aa..aab38e17d1 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -47,7 +47,7 @@ #include #include #include // for BOX2I -#include // for round_nearest, rescale +#include // for KiROUND, rescale #include // for VECTOR2I, VECTOR2D, VECTOR2 #include @@ -1723,13 +1723,13 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode, if( 0.5 * lenb < distance ) distance = 0.5 * lenb; - int nx1 = round_nearest( distance * xa / lena ); - int ny1 = round_nearest( distance * ya / lena ); + int nx1 = KiROUND( distance * xa / lena ); + int ny1 = KiROUND( distance * ya / lena ); newContour.Append( x1 + nx1, y1 + ny1 ); - int nx2 = round_nearest( distance * xb / lenb ); - int ny2 = round_nearest( distance * yb / lenb ); + int nx2 = KiROUND( distance * xb / lenb ); + int ny2 = KiROUND( distance * yb / lenb ); newContour.Append( x1 + nx2, y1 + ny2 ); } @@ -1789,11 +1789,11 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode, double nx = xc + xs; double ny = yc + ys; - newContour.Append( round_nearest( nx ), round_nearest( ny ) ); + newContour.Append( KiROUND( nx ), KiROUND( ny ) ); // Store the previous added corner to make a sanity check - int prevX = round_nearest( nx ); - int prevY = round_nearest( ny ); + int prevX = KiROUND( nx ); + int prevY = KiROUND( ny ); for( int j = 0; j < segments; j++ ) { @@ -1801,11 +1801,11 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode, ny = yc - sin( startAngle + ( j + 1 ) * deltaAngle ) * radius; // Sanity check: the rounding can produce repeated corners; do not add them. - if( round_nearest( nx ) != prevX || round_nearest( ny ) != prevY ) + if( KiROUND( nx ) != prevX || KiROUND( ny ) != prevY ) { - newContour.Append( round_nearest( nx ), round_nearest( ny ) ); - prevX = round_nearest( nx ); - prevY = round_nearest( ny ); + newContour.Append( KiROUND( nx ), KiROUND( ny ) ); + prevX = KiROUND( nx ); + prevY = KiROUND( ny ); } } }