MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / GetMinSquaredDist

Method GetMinSquaredDist

include/util/rectangle.hpp:78–153  ·  view source on GitHub ↗

This code assumes that we are operating in euclidean space! That means if you just put unprojected lat/lon in here you will get invalid results.

Source from the content-addressed store, hash-verified

76 // That means if you just put unprojected lat/lon in here you will
77 // get invalid results.
78 std::uint64_t GetMinSquaredDist(const Coordinate location) const
79 {
80 const bool is_contained = Contains(location);
81 if (is_contained)
82 {
83 return 0.0f;
84 }
85
86 enum Direction
87 {
88 INVALID = 0,
89 NORTH = 1,
90 SOUTH = 2,
91 EAST = 4,
92 NORTH_EAST = 5,
93 SOUTH_EAST = 6,
94 WEST = 8,
95 NORTH_WEST = 9,
96 SOUTH_WEST = 10
97 };
98
99 Direction d = INVALID;
100 if (location.lat > max_lat)
101 d = (Direction)(d | NORTH);
102 else if (location.lat < min_lat)
103 d = (Direction)(d | SOUTH);
104 if (location.lon > max_lon)
105 d = (Direction)(d | EAST);
106 else if (location.lon < min_lon)
107 d = (Direction)(d | WEST);
108
109 BOOST_ASSERT(d != INVALID);
110
111 std::uint64_t min_dist = std::numeric_limits<std::uint64_t>::max();
112 switch (d)
113 {
114 case NORTH:
115 min_dist = coordinate_calculation::squaredEuclideanDistance(
116 location, Coordinate(location.lon, max_lat));
117 break;
118 case SOUTH:
119 min_dist = coordinate_calculation::squaredEuclideanDistance(
120 location, Coordinate(location.lon, min_lat));
121 break;
122 case WEST:
123 min_dist = coordinate_calculation::squaredEuclideanDistance(
124 location, Coordinate(min_lon, location.lat));
125 break;
126 case EAST:
127 min_dist = coordinate_calculation::squaredEuclideanDistance(
128 location, Coordinate(max_lon, location.lat));
129 break;
130 case NORTH_EAST:
131 min_dist = coordinate_calculation::squaredEuclideanDistance(
132 location, Coordinate(max_lon, max_lat));
133 break;
134 case NORTH_WEST:
135 min_dist = coordinate_calculation::squaredEuclideanDistance(

Callers 2

BOOST_AUTO_TEST_CASEFunction · 0.80
ExploreTreeNodeMethod · 0.80

Calls 2

squaredEuclideanDistanceFunction · 0.85
CoordinateClass · 0.70

Tested by

no test coverage detected