diff --git a/common/tool/grid_helper.cpp b/common/tool/grid_helper.cpp index 03c5fa169e..cf8bb91782 100644 --- a/common/tool/grid_helper.cpp +++ b/common/tool/grid_helper.cpp @@ -182,35 +182,38 @@ void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin ) VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint ) const { - return computeNearest( aPoint, GetGrid() ); + return computeNearest( aPoint, GetGrid(), GetOrigin() ); } -VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid ) const +VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid, + const VECTOR2D& aOffset ) const { - return computeNearest( aPoint, aGrid ); + return computeNearest( aPoint, aGrid, aOffset ); } -VECTOR2I GRID_HELPER::computeNearest( const VECTOR2I& aPoint, const VECTOR2I& aGrid ) const +VECTOR2I GRID_HELPER::computeNearest( const VECTOR2I& aPoint, const VECTOR2I& aGrid, + const VECTOR2I& aOffset ) const { - return VECTOR2I( KiROUND( static_cast( aPoint.x ) / aGrid.x ) * aGrid.x, - KiROUND( static_cast( aPoint.y ) / aGrid.y ) * aGrid.y ); + return VECTOR2I( KiROUND( (double) ( aPoint.x - aOffset.x ) / aGrid.x ) * aGrid.x + aOffset.x, + KiROUND( (double) ( aPoint.y - aOffset.y ) / aGrid.y ) * aGrid.y + aOffset.y ); } VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const { - return Align( aPoint, GetGrid() ); + return Align( aPoint, GetGrid(), GetOrigin() ); } -VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid ) const +VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid, + const VECTOR2D& aOffset ) const { if( !canUseGrid() ) return aPoint; - VECTOR2I nearest = AlignGrid( aPoint, aGrid ); + VECTOR2I nearest = AlignGrid( aPoint, aGrid, aOffset ); if( !m_auxAxis ) return nearest; diff --git a/include/tool/grid_helper.h b/include/tool/grid_helper.h index 000d848101..017d594a83 100644 --- a/include/tool/grid_helper.h +++ b/include/tool/grid_helper.h @@ -64,19 +64,21 @@ public: virtual VECTOR2I Align( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const { - return Align( aPoint, GetGridSize( aGrid ) ); + return Align( aPoint, GetGridSize( aGrid ), GetOrigin() ); } virtual VECTOR2I AlignGrid( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const { - return AlignGrid( aPoint, GetGridSize( aGrid ) ); + return AlignGrid( aPoint, GetGridSize( aGrid ), GetOrigin() ); } virtual VECTOR2I Align( const VECTOR2I& aPoint ) const; - virtual VECTOR2I Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid ) const; + virtual VECTOR2I Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid, + const VECTOR2D& aOffset ) const; VECTOR2I AlignGrid( const VECTOR2I& aPoint ) const; - VECTOR2I AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid ) const; + VECTOR2I AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid, + const VECTOR2D& aOffset ) const; /** * Gets the coarsest grid that applies to a selecion of items. @@ -197,7 +199,8 @@ protected: */ bool canUseGrid() const; - VECTOR2I computeNearest( const VECTOR2I& aPoint, const VECTOR2I& aGrid ) const; + VECTOR2I computeNearest( const VECTOR2I& aPoint, const VECTOR2I& aGrid, + const VECTOR2I& aOffset ) const; protected: void showConstructionGeometry( bool aShow );