request polyline with precision of 5 or 6 positions (#3220)
This commit is contained in:
@@ -10,7 +10,7 @@ namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
{
|
||||
namespace /*detail*/ // anonymous to keep TU local
|
||||
namespace detail // anonymous to keep TU local
|
||||
{
|
||||
|
||||
std::string encode(int number_to_encode)
|
||||
@@ -55,35 +55,6 @@ std::string encode(std::vector<int> &numbers)
|
||||
}
|
||||
return output;
|
||||
}
|
||||
} // anonymous ns
|
||||
|
||||
std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end)
|
||||
{
|
||||
auto size = std::distance(begin, end);
|
||||
if (size == 0)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<int> delta_numbers;
|
||||
BOOST_ASSERT(size > 0);
|
||||
delta_numbers.reserve((size - 1) * 2);
|
||||
int current_lat = 0;
|
||||
int current_lon = 0;
|
||||
std::for_each(
|
||||
begin, end, [&delta_numbers, ¤t_lat, ¤t_lon](const util::Coordinate loc) {
|
||||
const int lat_diff =
|
||||
std::round(static_cast<int>(loc.lat) * detail::COORDINATE_TO_POLYLINE) -
|
||||
current_lat;
|
||||
const int lon_diff =
|
||||
std::round(static_cast<int>(loc.lon) * detail::COORDINATE_TO_POLYLINE) -
|
||||
current_lon;
|
||||
delta_numbers.emplace_back(lat_diff);
|
||||
delta_numbers.emplace_back(lon_diff);
|
||||
current_lat += lat_diff;
|
||||
current_lon += lon_diff;
|
||||
});
|
||||
return encode(delta_numbers);
|
||||
}
|
||||
|
||||
std::vector<util::Coordinate> decodePolyline(const std::string &geometry_string)
|
||||
|
||||
Reference in New Issue
Block a user