TestSegmentHit: add corner case for null segment (start == end)

Fixes: lp:1833059
* https://bugs.launchpad.net/kicad/+bug/1833059

(cherry picked from commit 6180687bbd)
This commit is contained in:
Tomasz Włostowski 2019-06-25 01:03:54 +02:00 committed by Wayne Stambaugh
parent e8ce0ba6ef
commit 3bf7ab910f
1 changed files with 9 additions and 0 deletions

View File

@ -151,6 +151,15 @@ bool TestSegmentHit( const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int
if( aStart.y == aEnd.y && aRefPoint.x > xmin && aRefPoint.x < xmax )
return std::abs( delta.y ) <= aDist;
// Special case for a segment with start == end (equal to a circle)
if ( aStart == aEnd )
{
long double length_square = (long double) delta.x * delta.x + (long double) delta.y * delta.y;
long double dist_square = (long double) aDist * aDist;
return ( length_square <= dist_square );
}
wxPoint len = aEnd - aStart;
// Precision note here:
// These are 32-bit integers, so squaring requires 64 bits to represent