Skip to content

Commit

Permalink
More minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 27, 2019
1 parent cb62685 commit f9cfa4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/core/pal/costcalculator.cpp
Expand Up @@ -151,12 +151,12 @@ double CostCalculator::calculatePolygonRingDistance( LabelPosition *candidate, P
// distance to the polygon boundary is being considered as the best placement. That's clearly wrong --
// if any part of label candidate sits outside the polygon, we should first prefer candidates which sit
// entirely WITHIN the polygon, or failing that, candidates which are CLOSER to the polygon boundary, not further from it!
ringDistanceCalculator.update( candidate->feature );
ringDistanceCalculator.addRing( candidate->feature );

// prefer candidates further from the outside of map rather then those close to the outside of the map
// TODO 3: should be using the actual map boundary here, not the bounding box
PointSet extent( 4, bbx, bby );
ringDistanceCalculator.update( &extent );
ringDistanceCalculator.addRing( &extent );

// prefer candidates which further from interior rings (holes) of the polygon
obstacles->intersects( candidate->feature->boundingBox(), [&ringDistanceCalculator, candidate]( const FeaturePart * obstacle )->bool
Expand All @@ -171,12 +171,12 @@ double CostCalculator::calculatePolygonRingDistance( LabelPosition *candidate, P
return true;
}

ringDistanceCalculator.update( obstacle );
ringDistanceCalculator.addRing( obstacle );

return true;
} );

return ringDistanceCalculator.getCost();
return ringDistanceCalculator.minimumDistance();
}

void CostCalculator::finalizeCandidatesCosts( Feats *feat, PalRtree<FeaturePart> *obstacles, double bbx[4], double bby[4] )
Expand All @@ -198,16 +198,16 @@ CandidatePolygonRingDistanceCalculator::CandidatePolygonRingDistanceCalculator(
{
}

void CandidatePolygonRingDistanceCalculator::update( const pal::PointSet *pset )
void CandidatePolygonRingDistanceCalculator::addRing( const pal::PointSet *ring )
{
double d = pset->minDistanceToPoint( mPx, mPy );
double d = ring->minDistanceToPoint( mPx, mPy );
if ( d < mMinDistance )
{
mMinDistance = d;
}
}

double CandidatePolygonRingDistanceCalculator::getCost()
double CandidatePolygonRingDistanceCalculator::minimumDistance() const
{
return ( 4 * mMinDistance );
return mMinDistance;
}
11 changes: 7 additions & 4 deletions src/core/pal/costcalculator.h
Expand Up @@ -74,18 +74,21 @@ namespace pal
explicit CandidatePolygonRingDistanceCalculator( LabelPosition *candidate );

/**
* Updates distance.
* Adds a \a ring to the calculation, updating the minimumDistance() value if
* the rings is closer to the candidate then previously added rings.
*/
void update( const pal::PointSet *pset );
void addRing( const pal::PointSet *ring );

double getCost();
/**
* Returns the minimum distance between the candidate and all added rings.
*/
double minimumDistance() const;

private:

double mPx;
double mPy;
double mMinDistance = std::numeric_limits<double>::max();
bool mOk = false;
};
}

Expand Down

0 comments on commit f9cfa4b

Please sign in to comment.