FindLineSegmentIntersection() was refactored in 2012 but there are a few
uses that didn't get updated.  This finalizes the cleanup

Fixes https://gitlab.com/kicad/code/kicad/issues/7365
This commit is contained in:
Seth Hillbrand 2021-01-31 15:55:05 -08:00
parent ae5d2efe07
commit 1a3ab551cf
3 changed files with 20 additions and 49 deletions

View File

@ -1008,15 +1008,15 @@ void ZONE::HatchBorder()
// Iterate through all vertices
for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
{
double x, y, x2, y2;
int ok;
double x, y;
bool ok;
SEG segment = *iterator;
ok = FindLineSegmentIntersection( a, slope,
segment.A.x, segment.A.y,
segment.B.x, segment.B.y,
&x, &y, &x2, &y2 );
x, y );
if( ok )
{
@ -1024,12 +1024,6 @@ void ZONE::HatchBorder()
pointbuffer.push_back( point );
}
if( ok == 2 )
{
VECTOR2I point( KiROUND( x2 ), KiROUND( y2 ) );
pointbuffer.push_back( point );
}
if( pointbuffer.size() >= MAXPTS ) // overflow
{
wxASSERT( 0 );

View File

@ -13,24 +13,6 @@
static bool InRange( double x, double xi, double xf );
/* Function FindSegmentIntersections
* find intersections between line segment (xi,yi) to (xf,yf)
* and line segment (xi2,yi2) to (xf2,yf2)
* returns true if intersection found
*/
bool FindSegmentIntersections( int xi, int yi, int xf, int yf,
int xi2, int yi2, int xf2, int yf2 )
{
if( std::max( xi, xf ) < std::min( xi2, xf2 )
|| std::min( xi, xf ) > std::max( xi2, xf2 )
|| std::max( yi, yf ) < std::min( yi2, yf2 )
|| std::min( yi, yf ) > std::max( yi2, yf2 ) )
return false;
return TestForIntersectionOfStraightLineSegments( xi, yi, xf, yf,
xi2, yi2, xf2, yf2 );
}
/* Function FindLineSegmentIntersection
* find intersection between line y = a + bx and line segment (xi,yi) to (xf,yf)
@ -40,8 +22,7 @@ bool FindSegmentIntersections( int xi, int yi, int xf, int yf,
* if no intersection, returns min distance in dist
*/
bool FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int yf,
double* x1, double* y1, double* x2, double* y2,
double* dist )
double& x1, double& y1, double* dist )
{
double xx = 0, yy = 0; // Init made to avoid C compil "uninitialized" warning
bool bVert = false;
@ -61,8 +42,8 @@ bool FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, in
// if vertical line, easy
if( InRange( a, xi, xf ) )
{
*x1 = a;
*y1 = c + d * a;
x1 = a;
y1 = c + d * a;
return 1;
}
else
@ -117,8 +98,8 @@ bool FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, in
return 0;
}
*x1 = xx;
*y1 = yy;
x1 = xx;
y1 = yy;
return true;
}
@ -188,9 +169,9 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
b = double( y2f - y2i ) / (x2f - x2i);
a = (double) y2i - b * x2i;
double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x1i, y1i, x1f, y1f,
&x1, &y1, &x2, &y2 );
double x1, y1;
bool test = FindLineSegmentIntersection( a, b, x1i, y1i, x1f, y1f,
x1, y1 );
if( test )
{
@ -216,9 +197,8 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
b = double( y2f - y2i ) / (x2f - x2i);
a = (double) y2i - b * x2i;
double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x1i, y1i, x1f, y1f,
&x1, &y1, &x2, &y2 );
double x1, y1;
bool test = FindLineSegmentIntersection( a, b, x1i, y1i, x1f, y1f, x1, y1 );
if( test )
{
@ -245,8 +225,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
a = (double) y1i - b * x1i;
double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f,
&x1, &y1, &x2, &y2 );
bool test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f, x1, y1 );
if( test )
{
@ -272,9 +251,8 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
b = double( y1f - y1i ) / (x1f - x1i);
a = (double) y1i - b * x1i;
double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f,
&x1, &y1, &x2, &y2 );
double x1, y1;
bool test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f, x1, y1 );
if( test )
{
@ -302,9 +280,8 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
b = double( y1f - y1i ) / (x1f - x1i);
a = (double) y1i - b * x1i;
double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f,
&x1, &y1, &x2, &y2 );
double x1, y1;
bool test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f, x1, y1 );
// both segments oblique
if( test )

View File

@ -6,11 +6,11 @@
* find intersection between line y = a + bx and line segment (xi,yi) to (xf,yf)
* if b > DBL_MAX/10, assume vertical line at x = a
* return false if no intersection or true if intersect
* return coords of intersections in *x1, *y1, *x2, *y2
* return coords of intersections in x1, y1
* if no intersection, returns min distance in dist
*/
bool FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int yf,
double * x1, double * y1, double * x2, double * y2, double * dist=NULL );
double& x1, double& y1, double * dist=NULL );
/* Function FindSegmentIntersections
* find intersections between line segment (xi,yi) to (xf,yf)