Revert "Remove the forced ancillary grid"

This reverts commit 7b602142b12050dbc517d86d74aa87bba3e1dc5b.
This commit is contained in:
jean-pierre charras 2025-09-12 10:51:29 +02:00
parent 00ae91d6b5
commit b47f8f4504
2 changed files with 20 additions and 14 deletions

View File

@ -182,35 +182,38 @@ void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin )
VECTOR2I GRID_HELPER::AlignGrid( const VECTOR2I& aPoint ) const 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<double>( aPoint.x ) / aGrid.x ) * aGrid.x, return VECTOR2I( KiROUND( (double) ( aPoint.x - aOffset.x ) / aGrid.x ) * aGrid.x + aOffset.x,
KiROUND( static_cast<double>( aPoint.y ) / aGrid.y ) * aGrid.y ); KiROUND( (double) ( aPoint.y - aOffset.y ) / aGrid.y ) * aGrid.y + aOffset.y );
} }
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const 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() ) if( !canUseGrid() )
return aPoint; return aPoint;
VECTOR2I nearest = AlignGrid( aPoint, aGrid ); VECTOR2I nearest = AlignGrid( aPoint, aGrid, aOffset );
if( !m_auxAxis ) if( !m_auxAxis )
return nearest; return nearest;

View File

@ -64,19 +64,21 @@ public:
virtual VECTOR2I Align( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const 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 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;
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;
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. * Gets the coarsest grid that applies to a selecion of items.
@ -197,7 +199,8 @@ protected:
*/ */
bool canUseGrid() const; 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: protected:
void showConstructionGeometry( bool aShow ); void showConstructionGeometry( bool aShow );