From 059f79dfdbdc28438e7018b205e2e6156ca451ea Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 2 Jun 2021 17:12:33 -0700 Subject: [PATCH] Re-remove KiROUND from header Moves routines requiring KiROUND (and util.h by extension) to the cpp file --- libs/kimath/include/geometry/seg.h | 21 ++------------------- libs/kimath/src/geometry/seg.cpp | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/libs/kimath/include/geometry/seg.h b/libs/kimath/include/geometry/seg.h index 74ed021a25..da536f7c1c 100644 --- a/libs/kimath/include/geometry/seg.h +++ b/libs/kimath/include/geometry/seg.h @@ -237,10 +237,7 @@ public: * @param aSeg other segment * @return minimum distance */ - int Distance( const SEG& aSeg ) const - { - return KiROUND( sqrt( SquaredDistance( aSeg ) ) ); - } + int Distance( const SEG& aSeg ) const; ecoord SquaredDistance( const VECTOR2I& aP ) const { @@ -253,10 +250,7 @@ public: * @param aP the point * @return minimum distance */ - int Distance( const VECTOR2I& aP ) const - { - return KiROUND( sqrt( SquaredDistance( aP ) ) ); - } + int Distance( const VECTOR2I& aP ) const; void CanonicalCoefs( ecoord& qA, ecoord& qB, ecoord& qC ) const { @@ -405,17 +399,6 @@ private: int m_index; }; -inline int SEG::LineDistance( const VECTOR2I& aP, bool aDetermineSide ) const -{ - ecoord p = ecoord{ A.y } - B.y; - ecoord q = ecoord{ B.x } - A.x; - ecoord r = -p * A.x - q * A.y; - - ecoord dist = KiROUND( ( p * aP.x + q * aP.y + r ) / sqrt( p * p + q * q ) ); - - return aDetermineSide ? dist : std::abs( dist ); -} - inline SEG::ecoord SEG::TCoef( const VECTOR2I& aP ) const { VECTOR2I d = B - A; diff --git a/libs/kimath/src/geometry/seg.cpp b/libs/kimath/src/geometry/seg.cpp index 5e369e20b6..ac0ad156bb 100644 --- a/libs/kimath/src/geometry/seg.cpp +++ b/libs/kimath/src/geometry/seg.cpp @@ -279,4 +279,29 @@ VECTOR2I SEG::LineProject( const VECTOR2I& aP ) const int yp = rescale( t, ecoord{ d.y }, l_squared ); return A + VECTOR2I( xp, yp ); -} \ No newline at end of file +} + + +int SEG::Distance( const SEG& aSeg ) const +{ + return KiROUND( sqrt( SquaredDistance( aSeg ) ) ); +} + + +int SEG::Distance( const VECTOR2I& aP ) const +{ + return KiROUND( sqrt( SquaredDistance( aP ) ) ); +} + + +int SEG::LineDistance( const VECTOR2I& aP, bool aDetermineSide ) const +{ + ecoord p = ecoord{ A.y } - B.y; + ecoord q = ecoord{ B.x } - A.x; + ecoord r = -p * A.x - q * A.y; + + ecoord dist = KiROUND( ( p * aP.x + q * aP.y + r ) / sqrt( p * p + q * q ) ); + + return aDetermineSide ? dist : std::abs( dist ); +} +