Skip to content

Commit

Permalink
[pal] Followup 3fdef5e, restore previous behaviour for labels with
Browse files Browse the repository at this point in the history
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 void PointSet::getPointByDistance( double distance, double *px, double *py ) const
{ {
if ( !mGeos ) //if anything fails, return the first point
createGeosGeom(); *px = x[0];
*py = y[0];


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


GEOSContextHandle_t geosctxt = geosContext(); if ( !mGeos )
GEOSGeometry *point = GEOSInterpolate_r( geosctxt, mGeos, distance ); return;
if ( point )
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 ); //negative distance. In this case we extrapolate backward from the first point,
GEOSCoordSeq_getX_r( geosctxt, coordSeq, 0, px ); //using the gradient of the entire linestring
GEOSCoordSeq_getY_r( geosctxt, coordSeq, 0, py ); 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 const GEOSGeometry *PointSet::geos() const
Expand Down

0 comments on commit e991b64

Please sign in to comment.