Skip to content
Permalink
Browse files

Revert 3fdef5e

Was causing too many issues for the small perfomance gain it may
have gained
  • Loading branch information
nyalldawson committed Aug 14, 2015
1 parent fec5d5e commit 9f10dbebb4360d4db0f4e3da9ce061e3d631a9a7
Showing with 58 additions and 53 deletions.
  1. +28 −3 src/core/pal/feature.cpp
  2. +26 −48 src/core/pal/pointset.cpp
  3. +4 −2 src/core/pal/pointset.h
@@ -504,6 +504,9 @@ namespace pal
double xrm = mFeature->label_x;
double yrm = mFeature->label_y;

double *d; // segments lengths distance bw pt[i] && pt[i+1]
double *ad; // absolute distance bw pt[0] and pt[i] along the line
double ll; // line length
double dist;
double bx, by, ex, ey;
int nbls;
@@ -529,7 +532,24 @@ namespace pal
x = line->x;
y = line->y;

double ll = line->length(); // line length
d = new double[nbPoints-1];
ad = new double[nbPoints];

ll = 0.0; // line length
for ( i = 0; i < line->nbPoints - 1; i++ )
{
if ( i == 0 )
ad[i] = 0;
else
ad[i] = ad[i-1] + d[i-1];

d[i] = dist_euc2d( x[i], y[i], x[i+1], y[i+1] );
ll += d[i];
}

ad[line->nbPoints-1] = ll;


nbls = ( int )( ll / xrm ); // ratio bw line length and label width

#ifdef _DEBUG_FULL_
@@ -564,9 +584,9 @@ namespace pal
while ( l < ll - xrm )
{
// => bx, by
line->getPointByDistance( l, &bx, &by );
line->getPointByDistance( d, ad, l, &bx, &by );
// same but l = l+xrm
line->getPointByDistance( l + xrm, &ex, &ey );
line->getPointByDistance( d, ad, l + xrm, &ex, &ey );

// Label is bigger than line ...
if ( l < 0 )
@@ -633,6 +653,11 @@ namespace pal
break;
}

//delete line;

delete[] d;
delete[] ad;

int nbp = positions.size();
*lPos = new LabelPosition *[nbp];
i = 0;
@@ -987,64 +987,42 @@ namespace pal
}
}

void PointSet::getPointByDistance( double distance, double *px, double *py ) const
void PointSet::getPointByDistance( double *d, double *ad, double dl, double *px, double *py )
{
//if anything fails, return the first point
*px = x[0];
*py = y[0];
int i;
double dx, dy, di;
double distr;

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

if ( !mGeos )
return;
while ( i < nbPoints && ad[i] <= dl ) i++;
i--;
}

GEOSContextHandle_t geosctxt = geosContext();
try
if ( i < nbPoints - 1 )
{
if ( dl < 0 )
{
int type = GEOSGeomTypeId_r( geosctxt, mGeos );
const GEOSGeometry* lineString = 0;
if ( type != GEOS_POLYGON )
{
lineString = mGeos;
}
else
{
//for polygons, we need exterior ring
lineString = GEOSGetExteriorRing_r( geosctxt, mGeos );
}

GEOSGeometry *point = GEOSInterpolate_r( geosctxt, lineString, 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 );
dx = x[nbPoints-1] - x[0];
dy = y[nbPoints-1] - y[0];
di = sqrt( dx * dx + dy * dy );
}
catch ( GEOSException &e )
else
{
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
return;
dx = x[i+1] - x[i];
dy = y[i+1] - y[i];
di = d[i];
}

distr = dl - ad[i];
*px = x[i] + dx * distr / di;
*py = y[i] + dy * distr / di;
}
else
else // just select last point...
{
//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;
}
*px = x[i];
*py = y[i];
}
}

@@ -124,11 +124,13 @@ namespace pal
int getNumPoints() const { return nbPoints; }

/** Get a point a set distance along a line geometry.
* @param distance distance to traverse along line
* @param d array of distances between points
* @param ad cumulative total distance from pt0 to each point (ad0 = pt0->pt0)
* @param dl distance to traverse along line
* @param px final x coord on line
* @param py final y coord on line
*/
void getPointByDistance( double distance, double *px, double *py ) const;
void getPointByDistance( double *d, double *ad, double dl, double *px, double *py );

/** Returns the point set's GEOS geometry.
*/

0 comments on commit 9f10dbe

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