Skip to content

Commit

Permalink
Add some more geometry relationship methods to LabelPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 18, 2018
1 parent dded4ab commit 2d71309
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/core/pal/labelposition.cpp
Expand Up @@ -196,6 +196,56 @@ bool LabelPosition::isIntersect( double *bbox )
return false;
}

bool LabelPosition::intersects( const GEOSPreparedGeometry *geometry )
{
if ( !mGeos )
createGeosGeom();

try
{
if ( GEOSPreparedIntersects_r( geosContext(), geometry, mGeos ) == 1 )
{
return true;
}
else if ( nextPart )
{
return nextPart->intersects( geometry );
}
}
catch ( GEOSException &e )
{
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
return false;
}

return false;
}

bool LabelPosition::within( const GEOSPreparedGeometry *geometry )
{
if ( !mGeos )
createGeosGeom();

try
{
if ( GEOSPreparedContains_r( geosContext(), geometry, mGeos ) != 1 )
{
return false;
}
else if ( nextPart )
{
return nextPart->within( geometry );
}
}
catch ( GEOSException &e )
{
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
return false;
}

return true;
}

bool LabelPosition::isInside( double *bbox )
{
for ( int i = 0; i < 4; i++ )
Expand Down
10 changes: 10 additions & 0 deletions src/core/pal/labelposition.h
Expand Up @@ -113,6 +113,16 @@ namespace pal
*/
bool isIntersect( double *bbox );

/**
* Returns true if the label position intersects a \a geometry.
*/
bool intersects( const GEOSPreparedGeometry *geometry );

/**
* Returns true if the label position is within a \a geometry.
*/
bool within( const GEOSPreparedGeometry *geometry );

/**
* \brief Is the labelposition inside the bounding-box ?
*
Expand Down

0 comments on commit 2d71309

Please sign in to comment.