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

Function connectPaths_FindClosestEnd

src/gui/map/map_editor.cpp:3100–3139  ·  view source on GitHub ↗

\todo Review use of container API

Source from the content-addressed store, hash-verified

3098
3099/// \todo Review use of container API
3100float connectPaths_FindClosestEnd(const std::vector<Object*>& objects, const PathObject* a, int a_index, PathPartVector::size_type path_part_a, bool path_part_a_begin, PathObject** out_b, int* out_b_index, int* out_path_part_b, bool* out_path_part_b_begin)
3101{
3102 float best_dist_sq = std::numeric_limits<float>::max();
3103 for (int i = a_index; i < (int)objects.size(); ++i)
3104 {
3105 const auto* b = static_cast<const PathObject*>(objects[i]);
3106 if (b->getSymbol() != a->getSymbol())
3107 continue;
3108
3109 auto num_parts = b->parts().size();
3110 for (PathPartVector::size_type path_part_b = (a == b) ? path_part_a : 0; path_part_b < num_parts; ++path_part_b)
3111 {
3112 const PathPart& part = b->parts()[path_part_b];
3113 if (!part.isClosed())
3114 {
3115 for (int begin = 0; begin < 2; ++begin)
3116 {
3117 bool path_part_b_begin = (begin == 0);
3118 if (a == b && path_part_a == path_part_b && path_part_a_begin == path_part_b_begin)
3119 continue;
3120
3121 const MapCoord coord_a = a->getCoordinate(path_part_a_begin ? a->parts()[path_part_a].first_index : (a->parts()[path_part_a].last_index));
3122 const MapCoord coord_b = b->getCoordinate(path_part_b_begin ? b->parts()[path_part_b].first_index : (b->parts()[path_part_b].last_index));
3123 float distance_sq = coord_a.distanceSquaredTo(coord_b);
3124 if (distance_sq < best_dist_sq)
3125 {
3126 best_dist_sq = distance_sq;
3127 *out_b = const_cast<PathObject*>(b); // = /* non-const */ object[i]
3128 *out_b_index = i;
3129 *out_path_part_b = path_part_b;
3130 *out_path_part_b_begin = path_part_b_begin;
3131 if (distance_sq == 0)
3132 return 0;
3133 }
3134 }
3135 }
3136 }
3137 }
3138 return best_dist_sq;
3139}
3140
3141void MapEditorController::connectPathsClicked()
3142{

Callers 1

connectPathsClickedMethod · 0.85

Calls 5

getCoordinateMethod · 0.80
distanceSquaredToMethod · 0.80
sizeMethod · 0.45
getSymbolMethod · 0.45
isClosedMethod · 0.45

Tested by

no test coverage detected