| 1221 | } |
| 1222 | |
| 1223 | MapCoordVector::size_type PathObject::findClosestCoordinate(const MapCoordF& coord) const |
| 1224 | { |
| 1225 | update(); |
| 1226 | |
| 1227 | auto coords_size = coords.size(); |
| 1228 | if (coords_size == 0) |
| 1229 | return std::numeric_limits<MapCoordVector::size_type>::max(); |
| 1230 | |
| 1231 | // NOTE: do not try to optimize this by starting with index 1, it will overlook curve starts this way |
| 1232 | auto min_distance_sq = 999999.9; |
| 1233 | MapCoordVector::size_type out_index = 0; |
| 1234 | for (MapCoordVector::size_type i = 0; i < coords_size; ++i) |
| 1235 | { |
| 1236 | double length_sq = (coord - MapCoordF(coords[i])).lengthSquared(); |
| 1237 | if (length_sq < min_distance_sq) |
| 1238 | { |
| 1239 | min_distance_sq = length_sq; |
| 1240 | out_index = i; |
| 1241 | } |
| 1242 | |
| 1243 | if (coords[i].isCurveStart()) |
| 1244 | i += 2; |
| 1245 | } |
| 1246 | return out_index; |
| 1247 | } |
| 1248 | |
| 1249 | MapCoordVector::size_type PathObject::subdivide(const PathCoord& path_coord) |
| 1250 | { |
no test coverage detected