Skip to content
Permalink
Browse files

[pal] Optimise LabelPosition::getDistanceToPoint for horizontal labels

  • Loading branch information
nyalldawson committed Apr 30, 2020
1 parent faffae5 commit ba7df722339d8fa359c4e89a9e30e6d09f7c3125
Showing with 25 additions and 2 deletions.
  1. +25 −2 src/core/pal/labelposition.cpp
@@ -432,8 +432,31 @@ void LabelPosition::insertIntoIndex( PalRtree<LabelPosition> &index )
double LabelPosition::getDistanceToPoint( double xp, double yp ) const
{
//first check if inside, if so then distance is -1
double distance = ( containsPoint( xp, yp ) ? -1
: std::sqrt( minDistanceToPoint( xp, yp ) ) );
bool contains = false;
if ( alpha == 0 )
{
// easy case -- horizontal label
contains = x[0] <= xp && x[1] >= xp && y[0] <= yp && y[2] >= yp;
}
else
{
contains = containsPoint( xp, yp );
}

double distance = -1;
if ( !contains )
{
if ( alpha == 0 )
{
const double dx = std::max( std::max( x[0] - xp, 0.0 ), xp - x[1] );
const double dy = std::max( std::max( y[0] - yp, 0.0 ), yp - y[2] );
distance = std::sqrt( dx * dx + dy * dy );
}
else
{
distance = std::sqrt( minDistanceToPoint( xp, yp ) );
}
}

if ( mNextPart && distance > 0 )
return std::min( distance, mNextPart->getDistanceToPoint( xp, yp ) );

0 comments on commit ba7df72

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