@d1 start location (distance from start / total distance) @d2 end location (distance from start / total distance)
1067{
1073 int nsegs, i;
1074 double length, slength, tlength;
1075 int state = 0;
1076
1077
1078
1079
1080
1082
1083
1085
1086
1087 LWDEBUGF(3,
"Total length: %g", length);
1088
1089
1090
1091 from = length*from;
1092 to = length*to;
1093
1094
1095 LWDEBUGF(3,
"From/To: %g/%g", from, to);
1096
1097
1098 tlength = 0;
1101 for ( i = 0; i < nsegs; i++ )
1102 {
1103 double dseg;
1104
1106
1107
1108 LWDEBUGF(3 ,
"Segment %d: (%g,%g,%g,%g)-(%g,%g,%g,%g)",
1109 i, p1.
x, p1.
y, p1.
z, p1.
m, p2.
x, p2.
y, p2.
z, p2.
m);
1110
1111
1112
1114
1115
1116
1117
1118 if ( state == 0 )
1119 {
1120
1122
1123 if ( fabs ( from - ( tlength + slength ) ) <= tolerance )
1124 {
1125
1126 LWDEBUG(3,
" Second point is our start");
1127
1128
1129
1130
1132 state=1;
1133 goto END;
1134 }
1135
1136 else if ( fabs(from - tlength) <= tolerance )
1137 {
1138
1139 LWDEBUG(3,
" First point is our start");
1140
1141
1142
1143
1145
1146
1147
1148
1149
1150 state=1;
1151 }
1152
1153
1154
1155
1156
1157 else if ( from > tlength + slength ) goto END;
1158
1159 else
1160 {
1161
1162 LWDEBUG(3,
" Seg contains first point");
1163
1164
1165
1166
1167
1168 dseg = (from - tlength) / slength;
1169
1171
1173
1174
1175
1176
1177
1178 state=1;
1179 }
1180 }
1181
1182 if ( state == 1 )
1183 {
1184
1186
1187
1188
1189
1190 if ( fabs(to - ( tlength + slength ) ) <= tolerance )
1191 {
1192
1193 LWDEBUG(3,
" Second point is our end");
1194
1196 break;
1197 }
1198
1199
1200
1201
1202
1203 else if ( fabs(to - tlength) <= tolerance )
1204 {
1205
1206 LWDEBUG(3,
" First point is our end");
1207
1209
1210 break;
1211 }
1212
1213
1214
1215
1216
1217 else if ( to > tlength + slength )
1218 {
1220 goto END;
1221 }
1222
1223
1224
1225
1226
1227 else if ( to < tlength + slength )
1228 {
1229
1230 LWDEBUG(3,
" Seg contains our end");
1231
1232 dseg = (to - tlength) / slength;
1234
1236
1237 break;
1238 }
1239
1240 else
1241 {
1243 }
1244 }
1245
1246
1247END:
1248
1249 tlength += slength;
1250 memcpy(&p1, &p2,
sizeof(
POINT4D));
1251 }
1252
1254
1255 return dpa;
1256}
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,...