diff --git a/libs/kimath/include/geometry/seg.h b/libs/kimath/include/geometry/seg.h index 323b198546..a373ac76bb 100644 --- a/libs/kimath/include/geometry/seg.h +++ b/libs/kimath/include/geometry/seg.h @@ -33,7 +33,6 @@ #include // for swap #include -#include // for rescale #include typedef OPT OPT_VECTOR2I; @@ -406,22 +405,6 @@ private: int m_index; }; -inline VECTOR2I SEG::LineProject( const VECTOR2I& aP ) const -{ - VECTOR2I d = B - A; - ecoord l_squared = d.Dot( d ); - - if( l_squared == 0 ) - return A; - - ecoord t = d.Dot( aP - A ); - - int xp = rescale( t, ecoord{ d.x }, l_squared ); - int yp = rescale( t, ecoord{ d.y }, l_squared ); - - return A + VECTOR2I( xp, yp ); -} - inline int SEG::LineDistance( const VECTOR2I& aP, bool aDetermineSide ) const { ecoord p = ecoord{ A.y } - B.y; @@ -439,45 +422,6 @@ inline SEG::ecoord SEG::TCoef( const VECTOR2I& aP ) const return d.Dot( aP - A); } -inline const VECTOR2I SEG::NearestPoint( const VECTOR2I& aP ) const -{ - VECTOR2I d = B - A; - ecoord l_squared = d.Dot( d ); - - if( l_squared == 0 ) - return A; - - ecoord t = d.Dot( aP - A ); - - if( t < 0 ) - return A; - else if( t > l_squared ) - return B; - - int xp = rescale( t, (ecoord)d.x, l_squared ); - int yp = rescale( t, (ecoord)d.y, l_squared ); - - return A + VECTOR2I( xp, yp ); -} - -inline const VECTOR2I SEG::ReflectPoint( const VECTOR2I& aP ) const -{ - VECTOR2I d = B - A; - VECTOR2I::extended_type l_squared = d.Dot( d ); - VECTOR2I::extended_type t = d.Dot( aP - A ); - VECTOR2I c; - - if( !l_squared ) - c = aP; - else - { - c.x = A.x + rescale( t, static_cast( d.x ), l_squared ); - c.y = A.y + rescale( t, static_cast( d.y ), l_squared ); - } - - return 2 * c - aP; -} - inline std::ostream& operator<<( std::ostream& aStream, const SEG& aSeg ) { aStream << "[ " << aSeg.A << " - " << aSeg.B << " ]"; diff --git a/libs/kimath/src/geometry/seg.cpp b/libs/kimath/src/geometry/seg.cpp index f875b70fdc..5e369e20b6 100644 --- a/libs/kimath/src/geometry/seg.cpp +++ b/libs/kimath/src/geometry/seg.cpp @@ -222,3 +222,61 @@ bool SEG::Contains( const VECTOR2I& aP ) const { return Distance( aP ) <= 1; } + + +const VECTOR2I SEG::NearestPoint( const VECTOR2I& aP ) const +{ + VECTOR2I d = B - A; + ecoord l_squared = d.Dot( d ); + + if( l_squared == 0 ) + return A; + + ecoord t = d.Dot( aP - A ); + + if( t < 0 ) + return A; + else if( t > l_squared ) + return B; + + int xp = rescale( t, (ecoord) d.x, l_squared ); + int yp = rescale( t, (ecoord) d.y, l_squared ); + + return A + VECTOR2I( xp, yp ); +} + + +const VECTOR2I SEG::ReflectPoint( const VECTOR2I& aP ) const +{ + VECTOR2I d = B - A; + VECTOR2I::extended_type l_squared = d.Dot( d ); + VECTOR2I::extended_type t = d.Dot( aP - A ); + VECTOR2I c; + + if( !l_squared ) + c = aP; + else + { + c.x = A.x + rescale( t, static_cast( d.x ), l_squared ); + c.y = A.y + rescale( t, static_cast( d.y ), l_squared ); + } + + return 2 * c - aP; +} + + +VECTOR2I SEG::LineProject( const VECTOR2I& aP ) const +{ + VECTOR2I d = B - A; + ecoord l_squared = d.Dot( d ); + + if( l_squared == 0 ) + return A; + + ecoord t = d.Dot( aP - A ); + + int xp = rescale( t, ecoord{ d.x }, l_squared ); + int yp = rescale( t, ecoord{ d.y }, l_squared ); + + return A + VECTOR2I( xp, yp ); +} \ No newline at end of file