42 #define M_PI 3.1415926535897931159979634685 58 , reversed( isReversed )
60 , quadrant( quadrant )
62 , mHasObstacleConflict( false )
63 , mUpsideDownCharCount( 0 )
71 while ( this->alpha > 2*
M_PI )
72 this->alpha -= 2 *
M_PI;
74 while ( this->alpha < 0 )
75 this->alpha += 2 *
M_PI;
77 double beta = this->alpha + (
M_PI / 2 );
79 double dx1, dx2, dy1, dy2;
81 dx1 = cos( this->alpha ) *
w;
82 dy1 = sin( this->alpha ) *
w;
84 dx2 = cos( beta ) *
h;
85 dy2 = sin( beta ) *
h;
93 x[2] = x1 + dx1 + dx2;
94 y[2] = y1 + dy1 + dy2;
101 this->alpha >
M_PI / 2 && this->alpha <= 3*
M_PI / 2 )
126 if ( this->alpha <
M_PI )
137 for (
int i = 0; i <
nbPoints; ++i )
167 mHasObstacleConflict = other.mHasObstacleConflict;
168 mUpsideDownCharCount = other.mUpsideDownCharCount;
175 for ( i = 0; i < 4; i++ )
177 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
178 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
192 for ( i = 0; i < 4; i++ )
194 if (
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
195 y[i] >= bbox[1] &&
y[i] <= bbox[3] )
207 for (
int i = 0; i < 4; i++ )
209 if ( !(
x[i] >= bbox[0] &&
x[i] <= bbox[2] &&
210 y[i] >= bbox[1] &&
y[i] <= bbox[3] ) )
242 bool result = ( GEOSPreparedIntersects_r( geosctxt,
preparedGeom(), lp->
mGeos ) == 1 );
245 catch ( GEOSException &e )
272 int LabelPosition::partCount()
const 282 for (
int i = 0; i < 4; i++ )
301 return ( i >= 0 && i < 4 ?
x[i] : -1 );
306 return ( i >= 0 && i < 4 ?
y[i] : -1 );
318 mCost -= int ( mCost );
340 for (
int c = 0; c < 4; c++ )
342 if (
x[c] < amin[0] )
344 if (
x[c] > amax[0] )
346 if (
y[c] < amin[1] )
348 if (
y[c] > amax[1] )
355 mHasObstacleConflict = conflicts;
370 pCost->
update( obstacle );
380 index->Remove( amin, amax,
this );
388 index->Insert( amin, amax,
this );
428 int *nbOv = context->
nbOv;
484 catch ( GEOSException &e )
498 if ( !polygon->
mGeos )
514 catch ( GEOSException &e )
526 double totalCost = polygonIntersectionCostForParts( polygon );
528 return ceil( totalCost / n );
536 if ( !polygon->
mGeos )
547 catch ( GEOSException &e )
562 double LabelPosition::polygonIntersectionCostForParts(
PointSet *polygon )
const 567 if ( !polygon->
mGeos )
582 for (
int i = 0; i < 4; ++i )
587 for (
int a = 0; a < 2; ++a )
591 px = (
x[i] +
x[( i+1 ) %4] ) / 2.0;
592 py = (
y[i] +
y[( i+1 ) %4] ) / 2.0;
596 px = (
x[0] +
x[2] ) / 2.0;
597 py = (
y[0] +
y[2] ) / 2.0;
604 catch ( GEOSException &e )
610 cost = 12.0 * cost / 13.0;
614 cost +=
nextPart->polygonIntersectionCostForParts( polygon );
bool isInConflict(LabelPosition *ls)
Check whether or not this overlap with another labelPosition.
PointSet * getHoleOf()
Returns NULL if this isn't a hole.
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
Return bounding box - amin: xmin,ymin - amax: xmax,ymax.
bool intersectsWithPolygon(PointSet *polygon) const
Returns true if if any intersection between polygon and position exists.
double getY(int i=0) const
get 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()
return the feature corresponding to this labelposition
static bool removeOverlapCallback(LabelPosition *lp, void *ctx)
QString tr(const char *sourceText, const char *disambiguation, int n)
LabelPosition * getLabel()
void update(pal::PointSet *pset)
bool isInside(double *bbox)
Is the labelposition inside the bounding-box ?
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.
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
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
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.
GEOSContextHandle_t geosContext()
Get GEOS context handle to be used in all GEOS library calls with reentrant API.
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
return 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
get alpha
double getX(int i=0) const
get 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 isInConflictSinglePart(LabelPosition *lp)
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
Get distance from this label to a point.