MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / findClosestCoordinate

Method findClosestCoordinate

src/core/objects/object.cpp:1223–1247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1221}
1222
1223MapCoordVector::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
1249MapCoordVector::size_type PathObject::subdivide(const PathCoord& path_coord)
1250{

Callers 1

snapToObjectMethod · 0.80

Calls 4

lengthSquaredMethod · 0.80
isCurveStartMethod · 0.80
MapCoordFClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected