@d1 start location (distance from start / total distance) @d2 end location (distance from start / total distance)
1212{
1218 int nsegs, i;
1219 double length, slength, tlength;
1220 int state = 0;
1221
1222
1223
1224
1225
1227
1228
1230
1231
1232 LWDEBUGF(3,
"Total length: %g", length);
1233
1234
1235
1236 from = length*from;
1237 to = length*to;
1238
1239
1240 LWDEBUGF(3,
"From/To: %g/%g", from, to);
1241
1242
1243 tlength = 0;
1246 for ( i = 0; i < nsegs; i++ )
1247 {
1248 double dseg;
1249
1251
1252
1253 LWDEBUGF(3 ,
"Segment %d: (%g,%g,%g,%g)-(%g,%g,%g,%g)",
1254 i, p1.
x, p1.
y, p1.
z, p1.
m, p2.
x, p2.
y, p2.
z, p2.
m);
1255
1256
1257
1259
1260
1261
1262
1263 if ( state == 0 )
1264 {
1265
1267
1268 if ( fabs ( from - ( tlength + slength ) ) <= tolerance )
1269 {
1270
1271 LWDEBUG(3,
" Second point is our start");
1272
1273
1274
1275
1277 state=1;
1278 goto END;
1279 }
1280
1281 else if ( fabs(from - tlength) <= tolerance )
1282 {
1283
1284 LWDEBUG(3,
" First point is our start");
1285
1286
1287
1288
1290
1291
1292
1293
1294
1295 state=1;
1296 }
1297
1298
1299
1300
1301
1302 else if ( from > tlength + slength ) goto END;
1303
1304 else
1305 {
1306
1307 LWDEBUG(3,
" Seg contains first point");
1308
1309
1310
1311
1312
1313 dseg = (from - tlength) / slength;
1314
1316
1318
1319
1320
1321
1322
1323 state=1;
1324 }
1325 }
1326
1327 if ( state == 1 )
1328 {
1329
1331
1332
1333
1334
1335 if ( fabs(to - ( tlength + slength ) ) <= tolerance )
1336 {
1337
1338 LWDEBUG(3,
" Second point is our end");
1339
1341 break;
1342 }
1343
1344
1345
1346
1347
1348 else if ( fabs(to - tlength) <= tolerance )
1349 {
1350
1351 LWDEBUG(3,
" First point is our end");
1352
1354
1355 break;
1356 }
1357
1358
1359
1360
1361
1362 else if ( to > tlength + slength )
1363 {
1365 goto END;
1366 }
1367
1368
1369
1370
1371
1372 else if ( to < tlength + slength )
1373 {
1374
1375 LWDEBUG(3,
" Seg contains our end");
1376
1377 dseg = (to - tlength) / slength;
1379
1381
1382 break;
1383 }
1384
1385 else
1386 {
1388 }
1389 }
1390
1391
1392END:
1393
1394 tlength += slength;
1395 memcpy(&p1, &p2,
sizeof(
POINT4D));
1396 }
1397
1399
1400 return dpa;
1401}
double distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2)
void interpolate_point4d(const POINT4D *A, const POINT4D *B, POINT4D *I, double F)
Find interpolation point I between point A and point B so that the len(AI) == len(AB)*F and I falls o...
#define FLAGS_GET_Z(flags)
#define FLAGS_GET_M(flags)
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
int ptarray_append_point(POINTARRAY *pa, const POINT4D *pt, int repeated_points)
Append a point to the end of an existing POINTARRAY If allow_duplicate is LW_FALSE,...