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] ) )
292 bool result = ( GEOSPreparedIntersects_r( geosctxt,
preparedGeom(), lp->
mGeos ) == 1 );
295 catch ( GEOSException &e )
322 int LabelPosition::partCount()
const 332 for (
int i = 0; i < 4; i++ )
351 return ( i >= 0 && i < 4 ?
x[i] : -1 );
356 return ( i >= 0 && i < 4 ?
y[i] : -1 );
368 mCost -= int ( mCost );
385 amin[0] = std::numeric_limits<double>::max();
386 amax[0] = std::numeric_limits<double>::lowest();
387 amin[1] = std::numeric_limits<double>::max();
388 amax[1] = std::numeric_limits<double>::lowest();
390 for (
int c = 0;
c < 4;
c++ )
392 if (
x[
c] < amin[0] )
394 if (
x[
c] > amax[0] )
396 if (
y[
c] < amin[1] )
398 if (
y[
c] > amax[1] )
405 mHasObstacleConflict = conflicts;
420 pCost->
update( obstacle );
430 index->Remove( amin, amax,
this );
438 index->Insert( amin, amax,
this );
478 int *nbOv = context->
nbOv;
534 catch ( GEOSException &e )
548 if ( !polygon->
mGeos )
564 catch ( GEOSException &e )
576 double totalCost = polygonIntersectionCostForParts( polygon );
578 return std::ceil( totalCost / n );
586 if ( !polygon->
mGeos )
597 catch ( GEOSException &e )
612 double LabelPosition::polygonIntersectionCostForParts(
PointSet *polygon )
const 617 if ( !polygon->
mGeos )
632 for (
int i = 0; i < 4; ++i )
637 for (
int a = 0; a < 2; ++a )
641 px = (
x[i] +
x[( i + 1 ) % 4] ) / 2.0;
642 py = (
y[i] +
y[( i + 1 ) % 4] ) / 2.0;
646 px = (
x[0] +
x[2] ) / 2.0;
647 py = (
y[0] +
y[2] ) / 2.0;
654 catch ( GEOSException &e )
660 cost = 12.0 * cost / 13.0;
664 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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
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()
bool boundingBoxIntersects(const PointSet *other) const
Returns true if the bounding box of this pointset intersects the bounding box of another pointset...
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.