Skip to content
Permalink
Browse files

[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 39c728bbc55fa63c2897af5005cb87e290be06ac
Showing with 31 additions and 6 deletions.
  1. +2 −2 src/core/pal/costcalculator.cpp
  2. +25 −3 src/core/pal/labelposition.cpp
  3. +4 −1 src/core/pal/labelposition.h
@@ -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:
@@ -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;
}

@@ -500,7 +500,7 @@ namespace pal
return distance;
}

bool LabelPosition::isBorderCrossingLine( PointSet* line ) const
bool LabelPosition::crossesLine( PointSet* line ) const
{
if ( !mGeos )
createGeosGeom();
@@ -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;
@@ -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;

0 comments on commit 39c728b

Please sign in to comment.
You can’t perform that action at this time.