52 , reversed( isReversed )
54 , quadrant( quadrant )
56 , mHasObstacleConflict( false )
57 , mUpsideDownCharCount( 0 )
65 while ( this->alpha > 2 * M_PI )
66 this->alpha -= 2 * M_PI;
68 while ( this->alpha < 0 )
69 this->alpha += 2 * M_PI;
71 double beta = this->alpha + M_PI_2;
73 double dx1, dx2, dy1, dy2;
75 dx1 = std::cos( this->alpha ) *
w;
76 dy1 = std::sin( this->alpha ) *
w;
78 dx2 = std::cos( beta ) *
h;
79 dy2 = std::sin( beta ) *
h;
87 x[2] = x1 + dx1 + dx2;
88 y[2] = y1 + dy1 + dy2;
95 this->alpha > M_PI_2 && this->alpha <= 3 * M_PI_2 )
120 if ( this->alpha < M_PI )
131 for (
int i = 0; i <
nbPoints; ++i )
161 mHasObstacleConflict = other.mHasObstacleConflict;
162 mUpsideDownCharCount = other.mUpsideDownCharCount;
169 for ( i = 0; i < 4; i++ )
171 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
172 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
186 for ( i = 0; i < 4; i++ )
188 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
189 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
215 catch ( GEOSException &e )
240 catch ( GEOSException &e )
251 for (
int i = 0; i < 4; i++ )
253 if ( !(
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
254 y[i] >= bbox[1] &&
y[i] <= bbox[3] ) )
286 bool result = ( GEOSPreparedIntersects_r( geosctxt,
preparedGeom(), lp->
mGeos ) == 1 );
289 catch ( GEOSException &e )
316 int LabelPosition::partCount()
const 326 for (
int i = 0; i < 4; i++ )
345 return ( i >= 0 && i < 4 ?
x[i] : -1 );
350 return ( i >= 0 && i < 4 ?
y[i] : -1 );
362 mCost -= int ( mCost );
379 amin[0] = std::numeric_limits<double>::max();
380 amax[0] = std::numeric_limits<double>::lowest();
381 amin[1] = std::numeric_limits<double>::max();
382 amax[1] = std::numeric_limits<double>::lowest();
384 for (
int c = 0;
c < 4;
c++ )
386 if (
x[
c] < amin[0] )
388 if (
x[
c] > amax[0] )
390 if (
y[
c] < amin[1] )
392 if (
y[
c] > amax[1] )
399 mHasObstacleConflict = conflicts;
414 pCost->
update( obstacle );
424 index->Remove( amin, amax,
this );
432 index->Insert( amin, amax,
this );
472 int *nbOv = context->
nbOv;
528 catch ( GEOSException &e )
542 if ( !polygon->
mGeos )
558 catch ( GEOSException &e )
570 double totalCost = polygonIntersectionCostForParts( polygon );
572 return std::ceil( totalCost / n );
580 if ( !polygon->
mGeos )
591 catch ( GEOSException &e )
606 double LabelPosition::polygonIntersectionCostForParts(
PointSet *polygon )
const 611 if ( !polygon->
mGeos )
626 for (
int i = 0; i < 4; ++i )
631 for (
int a = 0; a < 2; ++a )
635 px = (
x[i] +
x[( i + 1 ) % 4] ) / 2.0;
636 py = (
y[i] +
y[( i + 1 ) % 4] ) / 2.0;
640 px = (
x[0] +
x[2] ) / 2.0;
641 py = (
y[0] +
y[2] ) / 2.0;
648 catch ( GEOSException &e )
654 cost = 12.0 * cost / 13.0;
658 cost +=
nextPart->polygonIntersectionCostForParts( polygon );
bool isInConflict(LabelPosition *ls)
Check whether or not this overlap with another labelPosition.
PointSet * getHoleOf()
Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
bool isIntersect(double *bbox)
Is the labelposition intersect the bounding-box ?
bool containsPoint(double x, double y) const
Tests whether point set contains a specified point.
bool isInConflictMultiPart(LabelPosition *lp)
void getBoundingBox(double amin[2], double amax[2]) const
Returns bounding box - amin: xmin,ymin - amax: xmax,ymax.
bool intersectsWithPolygon(PointSet *polygon) const
Returns true if any intersection between polygon and position exists.
double getY(int i=0) const
Returns the down-left y coordinate.
void offsetPosition(double xOffset, double yOffset)
Shift the label by specified offset.
void createGeosGeom() const
static bool countFullOverlapCallback(LabelPosition *lp, void *ctx)
FeaturePart * getFeaturePart()
Returns the feature corresponding to this labelposition.
static bool removeOverlapCallback(LabelPosition *lp, void *ctx)
LabelPosition * getLabel()
static GEOSContextHandle_t getGEOSHandler()
void update(pal::PointSet *pset)
bool isInside(double *bbox)
Is the labelposition inside the bounding-box ?
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
static void addObstacleCostPenalty(LabelPosition *lp, pal::FeaturePart *obstacle)
Increase candidate's cost according to its collision with passed feature.
double cost() const
Returns the candidate label position's geographical cost.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
LabelPosition(int id, double x1, double y1, double w, double h, double alpha, double cost, FeaturePart *feature, bool isReversed=false, Quadrant quadrant=QuadrantOver)
create a new LabelPosition
Layer * layer()
Returns the layer that feature belongs to.
void insertIntoIndex(RTree< LabelPosition *, double, 2, double > *index)
void validateCost()
Make sure the cost is less than 1.
void removeFromIndex(RTree< LabelPosition *, double, 2, double > *index)
Main class to handle feature.
static bool pruneCallback(LabelPosition *candidatePosition, void *ctx)
Check whether the candidate in ctx overlap with obstacle feat.
int getId() const
Returns the id.
int polygonIntersectionCost(PointSet *polygon) const
Returns cost of position intersection with polygon (testing area of intersection and center)...
void setConflictsWithObstacle(bool conflicts)
Sets whether the position is marked as conflicting with an obstacle feature.
static bool countOverlapCallback(LabelPosition *lp, void *ctx)
static bool polygonObstacleCallback(pal::FeaturePart *obstacle, void *ctx)
bool hasSameLabelFeatureAs(FeaturePart *part) const
Tests whether this feature part belongs to the same QgsLabelFeature as another feature part...
double getAlpha() const
Returns the angle to rotate text (in rad).
double getX(int i=0) const
Returns the down-left x coordinate.
bool isIn(double *bbox)
Is the labelposition in the bounding-box ? (intersect or inside????)
LabelPosition is a candidate feature label position.
Quadrant
Position of label candidate relative to feature.
const GEOSPreparedGeometry * preparedGeom() const
bool within(const GEOSPreparedGeometry *geometry)
Returns true if the label position is within a geometry.
bool isInConflictSinglePart(LabelPosition *lp)
bool intersects(const GEOSPreparedGeometry *geometry)
Returns true if the label position intersects a geometry.
bool crossesBoundary(PointSet *polygon) const
Returns true if this label crosses the boundary of the specified polygon.
Data structure to compute polygon's candidates costs.
double minDistanceToPoint(double px, double py, double *rx=nullptr, double *ry=nullptr) const
Returns the squared minimum distance between the point set geometry and the point (px...
bool isCurved() const
Returns true if the layer has curved labels.
bool showUprightLabels() const
Returns true if feature's label must be displayed upright.
bool crossesLine(PointSet *line) const
Returns true if this label crosses the specified line.
LabelPosition::Quadrant quadrant
double getDistanceToPoint(double xp, double yp) const
Gets distance from this label to a point. If point lies inside, returns negative number.