Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Preserve anchor correction in PAL
To be able to reuse it for vector output like DXF
  • Loading branch information
m-kuhn committed Nov 29, 2019
1 parent 23fb486 commit 651219f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/pal/feature.cpp
Expand Up @@ -310,7 +310,7 @@ std::size_t FeaturePart::createCandidatesOverPoint( double x, double y, std::vec
}
}

lPos.emplace_back( qgis::make_unique< LabelPosition >( id, lx, ly, labelW, labelH, angle, cost, this, false, quadrantFromOffset() ) );
lPos.emplace_back( qgis::make_unique< LabelPosition >( id, lx, ly, labelW, labelH, angle, cost, this, false, quadrantFromOffset(), xdiff, ydiff ) );
return nbp;
}

Expand Down
16 changes: 15 additions & 1 deletion src/core/pal/labelposition.cpp
Expand Up @@ -40,7 +40,7 @@

using namespace pal;

LabelPosition::LabelPosition( int id, double x1, double y1, double w, double h, double alpha, double cost, FeaturePart *feature, bool isReversed, Quadrant quadrant )
LabelPosition::LabelPosition( int id, double x1, double y1, double w, double h, double alpha, double cost, FeaturePart *feature, bool isReversed, Quadrant quadrant, double dX, double dY )
: id( id )
, feature( feature )
, probFeat( 0 )
Expand All @@ -55,6 +55,8 @@ LabelPosition::LabelPosition( int id, double x1, double y1, double w, double h,
, mCost( cost )
, mHasObstacleConflict( false )
, mUpsideDownCharCount( 0 )
, mDx( dX )
, mDy( dY )
{
type = GEOS_POLYGON;
nbPoints = 4;
Expand Down Expand Up @@ -160,6 +162,8 @@ LabelPosition::LabelPosition( const LabelPosition &other )
quadrant = other.quadrant;
mHasObstacleConflict = other.mHasObstacleConflict;
mUpsideDownCharCount = other.mUpsideDownCharCount;
mDx = other.mDx;
mDy = other.mDy;
}

bool LabelPosition::isIn( double *bbox )
Expand Down Expand Up @@ -319,6 +323,16 @@ bool LabelPosition::isInConflictMultiPart( LabelPosition *lp )
return false; // no conflict found
}

double LabelPosition::dY() const
{
return mDy;
}

double LabelPosition::dX() const
{
return mDx;
}

int LabelPosition::partCount() const
{
if ( nextPart )
Expand Down
21 changes: 20 additions & 1 deletion src/core/pal/labelposition.h
Expand Up @@ -88,11 +88,14 @@ namespace pal
* \param feature labelpos owners
* \param isReversed label is reversed
* \param quadrant relative position of label to feature
* \param dx the correction of the anchor point in x direction
* \param dy the correction of the anchor point in y direction
*/
LabelPosition( int id, double x1, double y1,
double w, double h,
double alpha, double cost,
FeaturePart *feature, bool isReversed = false, Quadrant quadrant = QuadrantOver );
FeaturePart *feature, bool isReversed = false, Quadrant quadrant = QuadrantOver,
double dX = 0.0, double dy = 0.0 );

//! Copy constructor
LabelPosition( const LabelPosition &other );
Expand Down Expand Up @@ -297,6 +300,20 @@ namespace pal
// for polygon cost calculation
static bool polygonObstacleCallback( pal::FeaturePart *obstacle, void *ctx );

/**
* The offset of the anchor point in x direction.
*
* \since QGIS 3.12
*/
double dX() const;

/**
* The offset of the anchor point in y direction.
*
* \since QGIS 3.12
*/
double dY() const;

protected:

int id;
Expand Down Expand Up @@ -331,6 +348,8 @@ namespace pal
double mCost;
bool mHasObstacleConflict;
int mUpsideDownCharCount;
double mDx = 0.0;
double mDy = 0.0;

/**
* Calculates the total number of parts for this label position
Expand Down

0 comments on commit 651219f

Please sign in to comment.