From 9292158c76e6c8b1e2089881356613ffb759fee1 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 10 Mar 2023 13:45:11 +0000 Subject: [PATCH] kimath: Switch from INT_MAX to std::numeric_limits --- libs/kimath/src/geometry/shape_collisions.cpp | 14 +++++++------- libs/kimath/src/geometry/shape_line_chain.cpp | 8 ++++---- libs/kimath/src/math/util.cpp | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libs/kimath/src/geometry/shape_collisions.cpp b/libs/kimath/src/geometry/shape_collisions.cpp index 033d6a380d..604474b0c3 100644 --- a/libs/kimath/src/geometry/shape_collisions.cpp +++ b/libs/kimath/src/geometry/shape_collisions.cpp @@ -24,7 +24,7 @@ */ #include -#include // for INT_MAX +#include #include // for SEG #include @@ -174,8 +174,8 @@ static VECTOR2I pushoutForce( const SHAPE_CIRCLE& aA, const SEG& aB, int aCleara static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_LINE_CHAIN_BASE& aB, int aClearance, int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV ) { - int closest_dist = INT_MAX; - int closest_mtv_dist = INT_MAX; + int closest_dist = std::numeric_limits::max(); + int closest_mtv_dist = std::numeric_limits::max(); VECTOR2I nearest; int closest_mtv_seg = -1; @@ -293,7 +293,7 @@ static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_LINE_CH aA.TypeName(), aB.TypeName() ) ); - int closest_dist = INT_MAX; + int closest_dist = std::numeric_limits::max(); VECTOR2I nearest; if( aB.IsClosed() && aA.GetPointCount() > 0 && aB.PointInside( aA.GetPoint( 0 ) ) ) @@ -375,7 +375,7 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN_BASE& a aA.TypeName(), aB.TypeName() ) ); - int closest_dist = INT_MAX; + int closest_dist = std::numeric_limits::max(); VECTOR2I nearest; if( aB.IsClosed() && aB.PointInside( aA.Centre() ) ) @@ -529,7 +529,7 @@ static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_LINE_CHAIN& aB, int aA.TypeName(), aB.TypeName() ) ); - int closest_dist = INT_MAX; + int closest_dist = std::numeric_limits::max(); VECTOR2I nearest; if( aB.IsClosed() && aB.PointInside( aA.GetP0() ) ) @@ -619,7 +619,7 @@ static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_LINE_CHAIN_BASE& aB aA.TypeName(), aB.TypeName() ) ); - int closest_dist = INT_MAX; + int closest_dist = std::numeric_limits::max(); VECTOR2I nearest; if( aB.IsClosed() && aB.PointInside( aA.GetP0() ) ) diff --git a/libs/kimath/src/geometry/shape_line_chain.cpp b/libs/kimath/src/geometry/shape_line_chain.cpp index 2a2e2d6d03..2239f93581 100644 --- a/libs/kimath/src/geometry/shape_line_chain.cpp +++ b/libs/kimath/src/geometry/shape_line_chain.cpp @@ -24,7 +24,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include // for INT_MAX +#include #include // for hypot #include #include // for basic_string @@ -1884,7 +1884,7 @@ const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const VECTOR2I& aP, return { 0, 0 }; } - int min_d = INT_MAX; + int min_d = std::numeric_limits::max(); int nearest = 0; for( int i = 0; i < SegmentCount(); i++ ) @@ -1943,7 +1943,7 @@ const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const SEG& aSeg, int& dist ) cons int nearest = 0; - dist = INT_MAX; + dist = std::numeric_limits::max(); for( int i = 0; i < PointCount(); i++ ) { @@ -1962,7 +1962,7 @@ const VECTOR2I SHAPE_LINE_CHAIN::NearestPoint( const SEG& aSeg, int& dist ) cons int SHAPE_LINE_CHAIN::NearestSegment( const VECTOR2I& aP ) const { - int min_d = INT_MAX; + int min_d = std::numeric_limits::max(); int nearest = 0; for( int i = 0; i < SegmentCount(); i++ ) diff --git a/libs/kimath/src/math/util.cpp b/libs/kimath/src/math/util.cpp index 267bf2f517..6b95531fb6 100644 --- a/libs/kimath/src/math/util.cpp +++ b/libs/kimath/src/math/util.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -126,9 +126,9 @@ int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator ) r = c / 2; - if( b <= INT_MAX && c <= INT_MAX ) + if( b <= std::numeric_limits::max() && c <= std::numeric_limits::max() ) { - if( a <= INT_MAX ) + if( a <= std::numeric_limits::max() ) return sign * ( ( a * b + r ) / c ); else return sign * ( a / c * b + ( a % c * b + r ) / c);