Skip to content

Commit 9f10dbe

Browse files
committedAug 14, 2015
Revert 3fdef5e
Was causing too many issues for the small perfomance gain it may have gained
1 parent fec5d5e commit 9f10dbe

File tree

3 files changed

+58
-53
lines changed

3 files changed

+58
-53
lines changed
 

‎src/core/pal/feature.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ namespace pal
504504
double xrm = mFeature->label_x;
505505
double yrm = mFeature->label_y;
506506

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

532-
double ll = line->length(); // line length
535+
d = new double[nbPoints-1];
536+
ad = new double[nbPoints];
537+
538+
ll = 0.0; // line length
539+
for ( i = 0; i < line->nbPoints - 1; i++ )
540+
{
541+
if ( i == 0 )
542+
ad[i] = 0;
543+
else
544+
ad[i] = ad[i-1] + d[i-1];
545+
546+
d[i] = dist_euc2d( x[i], y[i], x[i+1], y[i+1] );
547+
ll += d[i];
548+
}
549+
550+
ad[line->nbPoints-1] = ll;
551+
552+
533553
nbls = ( int )( ll / xrm ); // ratio bw line length and label width
534554

535555
#ifdef _DEBUG_FULL_
@@ -564,9 +584,9 @@ namespace pal
564584
while ( l < ll - xrm )
565585
{
566586
// => bx, by
567-
line->getPointByDistance( l, &bx, &by );
587+
line->getPointByDistance( d, ad, l, &bx, &by );
568588
// same but l = l+xrm
569-
line->getPointByDistance( l + xrm, &ex, &ey );
589+
line->getPointByDistance( d, ad, l + xrm, &ex, &ey );
570590

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

656+
//delete line;
657+
658+
delete[] d;
659+
delete[] ad;
660+
636661
int nbp = positions.size();
637662
*lPos = new LabelPosition *[nbp];
638663
i = 0;

‎src/core/pal/pointset.cpp

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -987,64 +987,42 @@ namespace pal
987987
}
988988
}
989989

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

996-
if ( distance >= 0 )
996+
i = 0;
997+
if ( dl >= 0 )
997998
{
998-
//positive distance, use GEOS for interpolation
999-
if ( !mGeos )
1000-
createGeosGeom();
1001-
1002-
if ( !mGeos )
1003-
return;
999+
while ( i < nbPoints && ad[i] <= dl ) i++;
1000+
i--;
1001+
}
10041002

1005-
GEOSContextHandle_t geosctxt = geosContext();
1006-
try
1003+
if ( i < nbPoints - 1 )
1004+
{
1005+
if ( dl < 0 )
10071006
{
1008-
int type = GEOSGeomTypeId_r( geosctxt, mGeos );
1009-
const GEOSGeometry* lineString = 0;
1010-
if ( type != GEOS_POLYGON )
1011-
{
1012-
lineString = mGeos;
1013-
}
1014-
else
1015-
{
1016-
//for polygons, we need exterior ring
1017-
lineString = GEOSGetExteriorRing_r( geosctxt, mGeos );
1018-
}
1019-
1020-
GEOSGeometry *point = GEOSInterpolate_r( geosctxt, lineString, distance );
1021-
if ( point )
1022-
{
1023-
const GEOSCoordSequence *coordSeq = GEOSGeom_getCoordSeq_r( geosctxt, point );
1024-
GEOSCoordSeq_getX_r( geosctxt, coordSeq, 0, px );
1025-
GEOSCoordSeq_getY_r( geosctxt, coordSeq, 0, py );
1026-
}
1027-
GEOSGeom_destroy_r( geosctxt, point );
1007+
dx = x[nbPoints-1] - x[0];
1008+
dy = y[nbPoints-1] - y[0];
1009+
di = sqrt( dx * dx + dy * dy );
10281010
}
1029-
catch ( GEOSException &e )
1011+
else
10301012
{
1031-
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
1032-
return;
1013+
dx = x[i+1] - x[i];
1014+
dy = y[i+1] - y[i];
1015+
di = d[i];
10331016
}
1017+
1018+
distr = dl - ad[i];
1019+
*px = x[i] + dx * distr / di;
1020+
*py = y[i] + dy * distr / di;
10341021
}
1035-
else
1022+
else // just select last point...
10361023
{
1037-
//negative distance. In this case we extrapolate backward from the first point,
1038-
//using the gradient of the entire linestring
1039-
double dx = x[nbPoints-1] - x[0];
1040-
double dy = y[nbPoints-1] - y[0];
1041-
double di = sqrt( dx * dx + dy * dy );
1042-
1043-
if ( di != 0.0 )
1044-
{
1045-
*px = x[0] + distance * dx / di;
1046-
*py = y[0] + distance * dy / di;
1047-
}
1024+
*px = x[i];
1025+
*py = y[i];
10481026
}
10491027
}
10501028

‎src/core/pal/pointset.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ namespace pal
124124
int getNumPoints() const { return nbPoints; }
125125

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.