Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
nyalldawson committed Aug 6, 2015
1 parent 9508f8b commit 39c728b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/core/pal/costcalculator.cpp
Expand Up @@ -52,7 +52,7 @@ namespace pal
case GEOS_LINESTRING:

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

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

Expand Down
28 changes: 25 additions & 3 deletions src/core/pal/labelposition.cpp
Expand Up @@ -500,7 +500,7 @@ namespace pal
return distance;
}

bool LabelPosition::isBorderCrossingLine( PointSet* line ) const
bool LabelPosition::crossesLine( PointSet* line ) const
{
if ( !mGeos )
createGeosGeom();
Expand All @@ -509,13 +509,35 @@ namespace pal
line->createGeosGeom();

GEOSContextHandle_t geosctxt = geosContext();
if ( GEOSPreparedIntersects_r( geosctxt, preparedGeom(), line->mGeos ) == 1 )
if ( GEOSPreparedIntersects_r( geosctxt, line->preparedGeom(), mGeos ) == 1 )
{
return true;
}
else if ( nextPart )
{
return nextPart->isBorderCrossingLine( line );
return nextPart->crossesLine( line );
}

return false;
}

bool LabelPosition::crossesBoundary( PointSet *polygon ) const
{
if ( !mGeos )
createGeosGeom();

if ( !polygon->mGeos )
polygon->createGeosGeom();

GEOSContextHandle_t geosctxt = geosContext();
if ( GEOSPreparedOverlaps_r( geosctxt, polygon->preparedGeom(), mGeos ) == 1
|| GEOSPreparedTouches_r( geosctxt, polygon->preparedGeom(), mGeos ) == 1 )
{
return true;
}
else if ( nextPart )
{
return nextPart->crossesBoundary( polygon );
}

return false;
Expand Down
5 changes: 4 additions & 1 deletion src/core/pal/labelposition.h
Expand Up @@ -128,7 +128,10 @@ namespace pal
double getDistanceToPoint( double xp, double yp ) const;

/** Returns true if this label crosses the specified line */
bool isBorderCrossingLine( PointSet* line ) const;
bool crossesLine( PointSet* line ) const;

/** Returns true if this label crosses the boundary of the specified polygon */
bool crossesBoundary( PointSet* polygon ) const;

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

0 comments on commit 39c728b

Please sign in to comment.