Skip to content
Permalink
Browse files

[pal] Followup 3fdef5e, restore previous behaviour for labels with

length greater than line length
  • Loading branch information
nyalldawson committed Aug 8, 2015
1 parent d8da4b8 commit e991b648613bbba9539fd8ff60b580209bc8c006
Showing with 34 additions and 11 deletions.
  1. +34 −11 src/core/pal/pointset.cpp
@@ -955,21 +955,44 @@ namespace pal

void PointSet::getPointByDistance( double distance, double *px, double *py ) const
{
if ( !mGeos )
createGeosGeom();
//if anything fails, return the first point
*px = x[0];
*py = y[0];

if ( !mGeos )
return;
if ( distance >= 0 )
{
//positive distance, use GEOS for interpolation
if ( !mGeos )
createGeosGeom();

GEOSContextHandle_t geosctxt = geosContext();
GEOSGeometry *point = GEOSInterpolate_r( geosctxt, mGeos, distance );
if ( point )
if ( !mGeos )
return;

GEOSContextHandle_t geosctxt = geosContext();

GEOSGeometry *point = GEOSInterpolate_r( geosctxt, mGeos, distance );
if ( point )
{
const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, point );
GEOSCoordSeq_getX_r( geosctxt, coordSeq, 0, px );
GEOSCoordSeq_getY_r( geosctxt, coordSeq, 0, py );
}
GEOSGeom_destroy_r( geosctxt, point );
}
else
{
const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, point );
GEOSCoordSeq_getX_r( geosctxt, coordSeq, 0, px );
GEOSCoordSeq_getY_r( geosctxt, coordSeq, 0, py );
//negative distance. In this case we extrapolate backward from the first point,
//using the gradient of the entire linestring
double dx = x[nbPoints-1] - x[0];
double dy = y[nbPoints-1] - y[0];
double di = sqrt( dx * dx + dy * dy );

if ( di != 0.0 )
{
*px = x[0] + distance * dx / di;
*py = y[0] + distance * dy / di;
}
}
GEOSGeom_destroy_r( geosctxt, point );
}

const GEOSGeometry *PointSet::geos() const

0 comments on commit e991b64

Please sign in to comment.
You can’t perform that action at this time.