From b604f007d74b17f5689527033ae982fdec02f106 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Mon, 27 Aug 2018 15:24:08 +0200 Subject: [PATCH] eeschema-gal: don't use kiROUND in the geometry library as it brings in a s*****load of wx dependencies due to #include --- common/geometry/geometry_utils.cpp | 4 +--- common/geometry/shape_arc.cpp | 1 - common/geometry/shape_line_chain.cpp | 3 +-- common/geometry/shape_poly_set.cpp | 26 ++++++++++++++------------ include/math/math_util.h | 5 +++++ 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/common/geometry/geometry_utils.cpp b/common/geometry/geometry_utils.cpp index 03aee0eeb1..03f575c32e 100644 --- a/common/geometry/geometry_utils.cpp +++ b/common/geometry/geometry_utils.cpp @@ -27,8 +27,6 @@ * @brief a few functions useful in geometry calculations. */ -#include -#include #include int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree ) @@ -41,7 +39,7 @@ int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree ) // minimal arc increment in degrees: double step = 180 / M_PI * acos( 1.0 - rel_error ) * 2; // the minimal seg count for a arc - int segCount = KiROUND( fabs( aArcAngleDegree ) / step ); + int segCount = round_nearest( fabs( aArcAngleDegree ) / step ); // Ensure at least one segment is used return std::max( segCount, 1 ); diff --git a/common/geometry/shape_arc.cpp b/common/geometry/shape_arc.cpp index d71b4e9f98..2a596b9b9d 100644 --- a/common/geometry/shape_arc.cpp +++ b/common/geometry/shape_arc.cpp @@ -24,7 +24,6 @@ #include -#include #include #include #include diff --git a/common/geometry/shape_line_chain.cpp b/common/geometry/shape_line_chain.cpp index 8929c67ef3..d60b3bb85a 100644 --- a/common/geometry/shape_line_chain.cpp +++ b/common/geometry/shape_line_chain.cpp @@ -24,7 +24,6 @@ #include -#include #include #include #include "clipper.hpp" @@ -400,7 +399,7 @@ bool SHAPE_LINE_CHAIN::PointOnEdge( const VECTOR2I& aP ) const const VECTOR2D diff = p2 - p1; if( aP.x >= p1.x && aP.x <= p2.x ) { - if( KiROUND( p1.y + ( diff.y / diff.x ) * ( aP.x - p1.x ) ) == aP.y ) + if( round_nearest( p1.y + ( diff.y / diff.x ) * ( aP.x - p1.x ) ) == aP.y ) return true; } } diff --git a/common/geometry/shape_poly_set.cpp b/common/geometry/shape_poly_set.cpp index 38bafe35f1..5a457300a2 100644 --- a/common/geometry/shape_poly_set.cpp +++ b/common/geometry/shape_poly_set.cpp @@ -33,11 +33,13 @@ #include #include #include +#include -#include #include #include +#include + #include #include #include @@ -1707,13 +1709,13 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode, if( 0.5 * lenb < distance ) distance = 0.5 * lenb; - int nx1 = KiROUND( distance * xa / lena ); - int ny1 = KiROUND( distance * ya / lena ); + int nx1 = round_nearest( distance * xa / lena ); + int ny1 = round_nearest( distance * ya / lena ); newContour.Append( x1 + nx1, y1 + ny1 ); - int nx2 = KiROUND( distance * xb / lenb ); - int ny2 = KiROUND( distance * yb / lenb ); + int nx2 = round_nearest( distance * xb / lenb ); + int ny2 = round_nearest( distance * yb / lenb ); newContour.Append( x1 + nx2, y1 + ny2 ); } @@ -1773,11 +1775,11 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode, double nx = xc + xs; double ny = yc + ys; - newContour.Append( KiROUND( nx ), KiROUND( ny ) ); + newContour.Append( round_nearest( nx ), round_nearest( ny ) ); // Store the previous added corner to make a sanity check - int prevX = KiROUND( nx ); - int prevY = KiROUND( ny ); + int prevX = round_nearest( nx ); + int prevY = round_nearest( ny ); for( int j = 0; j < segments; j++ ) { @@ -1785,11 +1787,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( KiROUND( nx ) != prevX || KiROUND( ny ) != prevY ) + if( round_nearest( nx ) != prevX || round_nearest( ny ) != prevY ) { - newContour.Append( KiROUND( nx ), KiROUND( ny ) ); - prevX = KiROUND( nx ); - prevY = KiROUND( ny ); + newContour.Append( round_nearest( nx ), round_nearest( ny ) ); + prevX = round_nearest( nx ); + prevY = round_nearest( ny ); } } } diff --git a/include/math/math_util.h b/include/math/math_util.h index cb3ce50460..1bf61fae63 100644 --- a/include/math/math_util.h +++ b/include/math/math_util.h @@ -53,4 +53,9 @@ 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 // __MATH_UTIL_H