Pick location closest to aSeg.A in SHAPE_COMPOUND and SHAPE_RECT Collide.

This commit is contained in:
Alex Shvartzkop 2023-10-05 11:10:41 +03:00
parent 92ef40327d
commit f9efed692d
2 changed files with 20 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020-2022 KiCad Developers
* Copyright (C) 2020-2023 KiCad Developers
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -134,9 +134,17 @@ bool SHAPE_COMPOUND::Collide( const SEG& aSeg, int aClearance, int* aActual,
nearest = pn;
closest_dist = actual;
if( closest_dist == 0 || !aActual )
if( !aLocation && !aActual )
break;
}
else if( aLocation && actual == closest_dist )
{
if( ( pn - aSeg.A ).SquaredEuclideanNorm()
< ( nearest - aSeg.A ).SquaredEuclideanNorm() )
{
nearest = pn;
}
}
}
}

View File

@ -76,6 +76,16 @@ bool SHAPE_RECT::Collide( const SEG& aSeg, int aClearance, int* aActual, VECTOR2
closest_dist_sq = dist_sq;
}
else if( aLocation && dist_sq == closest_dist_sq )
{
VECTOR2I near = side.NearestPoint( aSeg );
if( ( near - aSeg.A ).SquaredEuclideanNorm()
< ( nearest - aSeg.A ).SquaredEuclideanNorm() )
{
nearest = near;
}
}
}
if( closest_dist_sq == 0 || closest_dist_sq < SEG::Square( aClearance ) )