/ pointObj *msGetMeasureUsingPoint(shapeObj *shape, pointObj */ point) */ / Calculate the intersection point betwwen the point and the */ shape and return the Measured value at the intersection. */ /
| 1174 | /* shape and return the Measured value at the intersection. */ |
| 1175 | /************************************************************************/ |
| 1176 | pointObj *msGetMeasureUsingPoint(shapeObj *shape, pointObj *point) |
| 1177 | { |
| 1178 | double dfMinDist = 1e35; |
| 1179 | double dfDist = 0; |
| 1180 | pointObj oFirst; |
| 1181 | pointObj oSecond; |
| 1182 | int i, j = 0; |
| 1183 | lineObj line; |
| 1184 | pointObj *poIntersectionPt = NULL; |
| 1185 | double dfFactor = 0; |
| 1186 | double dfDistTotal, dfDistToIntersection = 0; |
| 1187 | |
| 1188 | if (shape && point) |
| 1189 | { |
| 1190 | for (i=0; i<shape->numlines; i++) |
| 1191 | { |
| 1192 | line = shape->line[i]; |
| 1193 | /* -------------------------------------------------------------------- */ |
| 1194 | /* for each line (2 consecutive lines) get the distance between */ |
| 1195 | /* the line and the point and determine which line segment is */ |
| 1196 | /* the closeset to the point. */ |
| 1197 | /* -------------------------------------------------------------------- */ |
| 1198 | for (j=0; j<line.numpoints-1; j++) |
| 1199 | { |
| 1200 | dfDist = msDistancePointToSegment(point, &line.point[j], &line.point[j+1]); |
| 1201 | if (dfDist < dfMinDist) |
| 1202 | { |
| 1203 | oFirst.x = line.point[j].x; |
| 1204 | oFirst.y = line.point[j].y; |
| 1205 | #ifdef USE_POINT_Z_M |
| 1206 | oFirst.m = line.point[j].m; |
| 1207 | #endif |
| 1208 | |
| 1209 | oSecond.x = line.point[j+1].x; |
| 1210 | oSecond.y = line.point[j+1].y; |
| 1211 | #ifdef USE_POINT_Z_M |
| 1212 | oSecond.m = line.point[j+1].m; |
| 1213 | #endif |
| 1214 | |
| 1215 | dfMinDist = dfDist; |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | /* -------------------------------------------------------------------- */ |
| 1220 | /* once we have the nearest segment, look for the x,y location */ |
| 1221 | /* which is the nearest intersection between the line and the */ |
| 1222 | /* point. */ |
| 1223 | /* -------------------------------------------------------------------- */ |
| 1224 | poIntersectionPt = msIntersectionPointLine(point, &oFirst, &oSecond); |
| 1225 | if (poIntersectionPt) |
| 1226 | { |
| 1227 | dfDistTotal = sqrt(((oSecond.x - oFirst.x)*(oSecond.x - oFirst.x)) + |
| 1228 | ((oSecond.y - oFirst.y)*(oSecond.y - oFirst.y))); |
| 1229 | |
| 1230 | dfDistToIntersection = sqrt(((poIntersectionPt->x - oFirst.x)* |
| 1231 | (poIntersectionPt->x - oFirst.x)) + |
| 1232 | ((poIntersectionPt->y - oFirst.y)* |
| 1233 | (poIntersectionPt->y - oFirst.y))); |
no test coverage detected