Skip to content

Commit 39c728b

Browse files
committed
[pal] Fix test for polygon boundary obstacles (followup 3a44e29)
Test was incorrectly checking for intersection of the candidate and polygon obstacle, when it should have been checking for overlapping or touching obstacles.
1 parent 9508f8b commit 39c728b

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/core/pal/costcalculator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace pal
5252
case GEOS_LINESTRING:
5353

5454
// Is one of label's borders crossing the line ?
55-
n = ( lp->isBorderCrossingLine( obstacle ) ? 1 : 0 );
55+
n = ( lp->crossesLine( obstacle ) ? 1 : 0 );
5656
break;
5757

5858
case GEOS_POLYGON:
@@ -65,7 +65,7 @@ namespace pal
6565
break;
6666
case PolygonBoundary:
6767
// penalty may need tweaking, given that interior mode ranges up to 12
68-
n = ( lp->isBorderCrossingLine( obstacle ) ? 6 : 0 );
68+
n = ( lp->crossesBoundary( obstacle ) ? 6 : 0 );
6969
break;
7070
}
7171

src/core/pal/labelposition.cpp

+25-3
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ namespace pal
500500
return distance;
501501
}
502502

503-
bool LabelPosition::isBorderCrossingLine( PointSet* line ) const
503+
bool LabelPosition::crossesLine( PointSet* line ) const
504504
{
505505
if ( !mGeos )
506506
createGeosGeom();
@@ -509,13 +509,35 @@ namespace pal
509509
line->createGeosGeom();
510510

511511
GEOSContextHandle_t geosctxt = geosContext();
512-
if ( GEOSPreparedIntersects_r( geosctxt, preparedGeom(), line->mGeos ) == 1 )
512+
if ( GEOSPreparedIntersects_r( geosctxt, line->preparedGeom(), mGeos ) == 1 )
513513
{
514514
return true;
515515
}
516516
else if ( nextPart )
517517
{
518-
return nextPart->isBorderCrossingLine( line );
518+
return nextPart->crossesLine( line );
519+
}
520+
521+
return false;
522+
}
523+
524+
bool LabelPosition::crossesBoundary( PointSet *polygon ) const
525+
{
526+
if ( !mGeos )
527+
createGeosGeom();
528+
529+
if ( !polygon->mGeos )
530+
polygon->createGeosGeom();
531+
532+
GEOSContextHandle_t geosctxt = geosContext();
533+
if ( GEOSPreparedOverlaps_r( geosctxt, polygon->preparedGeom(), mGeos ) == 1
534+
|| GEOSPreparedTouches_r( geosctxt, polygon->preparedGeom(), mGeos ) == 1 )
535+
{
536+
return true;
537+
}
538+
else if ( nextPart )
539+
{
540+
return nextPart->crossesBoundary( polygon );
519541
}
520542

521543
return false;

src/core/pal/labelposition.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ namespace pal
128128
double getDistanceToPoint( double xp, double yp ) const;
129129

130130
/** Returns true if this label crosses the specified line */
131-
bool isBorderCrossingLine( PointSet* line ) const;
131+
bool crossesLine( PointSet* line ) const;
132+
133+
/** Returns true if this label crosses the boundary of the specified polygon */
134+
bool crossesBoundary( PointSet* polygon ) const;
132135

133136
/** Returns number of intersections with polygon (testing border and center) */
134137
int getNumPointsInPolygon( PointSet* polygon ) const;

0 commit comments

Comments
 (0)