Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 e991b64
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions src/core/pal/pointset.cpp
Expand Up @@ -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
Expand Down

0 comments on commit e991b64

Please sign in to comment.