First round of lat,lng -> lng,lat switcheroo
This commit is contained in:
@@ -93,11 +93,11 @@ std::string instructionToString(extractor::TurnInstruction instruction)
|
||||
return token;
|
||||
}
|
||||
|
||||
util::json::Array coordinateToLonLat(const FixedPointCoordinate &coordinate)
|
||||
util::json::Array coordinateToLonLat(const util::Coordinate &coordinate)
|
||||
{
|
||||
util::json::Array array;
|
||||
array.values.push_back(coordinate.lon / COORDINATE_PRECISION);
|
||||
array.values.push_back(coordinate.lat / COORDINATE_PRECISION);
|
||||
array.values.push_back(static_cast<double>(toFloating(coordinate.lon)));
|
||||
array.values.push_back(static_cast<double>(toFloating(coordinate.lat)));
|
||||
return array;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ util::json::Object makeRoute(const guidance::Route &route,
|
||||
}
|
||||
|
||||
util::json::Object
|
||||
makeWaypoint(const FixedPointCoordinate location, std::string &&name, const Hint &hint)
|
||||
makeWaypoint(const util::Coordinate location, std::string &&name, const Hint &hint)
|
||||
{
|
||||
util::json::Object waypoint;
|
||||
waypoint.values["location"] = detail::coordinateToLonLat(location);
|
||||
|
||||
@@ -24,21 +24,21 @@ namespace
|
||||
struct CoordinatePairCalculator
|
||||
{
|
||||
CoordinatePairCalculator() = delete;
|
||||
CoordinatePairCalculator(const util::FixedPointCoordinate coordinate_a,
|
||||
const util::FixedPointCoordinate coordinate_b)
|
||||
CoordinatePairCalculator(const util::Coordinate coordinate_a,
|
||||
const util::Coordinate coordinate_b)
|
||||
{
|
||||
// initialize distance calculator with two fixed coordinates a, b
|
||||
first_lat = (coordinate_a.lat / COORDINATE_PRECISION) * util::RAD;
|
||||
first_lon = (coordinate_a.lon / COORDINATE_PRECISION) * util::RAD;
|
||||
second_lat = (coordinate_b.lat / COORDINATE_PRECISION) * util::RAD;
|
||||
second_lon = (coordinate_b.lon / COORDINATE_PRECISION) * util::RAD;
|
||||
first_lon = static_cast<double>(toFloating(coordinate_a.lon)) * util::RAD;
|
||||
first_lat = static_cast<double>(toFloating(coordinate_a.lat)) * util::RAD;
|
||||
second_lon = static_cast<double>(toFloating(coordinate_b.lon)) * util::RAD;
|
||||
second_lat = static_cast<double>(toFloating(coordinate_b.lat)) * util::RAD;
|
||||
}
|
||||
|
||||
int operator()(const util::FixedPointCoordinate other) const
|
||||
int operator()(const util::Coordinate other) const
|
||||
{
|
||||
// set third coordinate c
|
||||
const float float_lat1 = (other.lat / COORDINATE_PRECISION) * util::RAD;
|
||||
const float float_lon1 = (other.lon / COORDINATE_PRECISION) * util::RAD;
|
||||
const float float_lon1 = static_cast<double>(toFloating(other.lon)) * util::RAD;
|
||||
const float float_lat1 = static_cast<double>(toFloating(other.lat)) * util::RAD;
|
||||
|
||||
// compute distance (a,c)
|
||||
const float x_value_1 = (first_lon - float_lon1) * cos((float_lat1 + first_lat) / 2.f);
|
||||
@@ -61,13 +61,12 @@ struct CoordinatePairCalculator
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<util::FixedPointCoordinate>
|
||||
douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin,
|
||||
std::vector<util::FixedPointCoordinate>::const_iterator end,
|
||||
const unsigned zoom_level)
|
||||
std::vector<util::Coordinate> douglasPeucker(std::vector<util::Coordinate>::const_iterator begin,
|
||||
std::vector<util::Coordinate>::const_iterator end,
|
||||
const unsigned zoom_level)
|
||||
{
|
||||
BOOST_ASSERT_MSG(zoom_level < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE,
|
||||
"unsupported zoom level");
|
||||
"unsupported zoom level");
|
||||
|
||||
const auto size = std::distance(begin, end);
|
||||
if (size < 2)
|
||||
@@ -83,7 +82,7 @@ douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin,
|
||||
|
||||
std::stack<GeometryRange> recursion_stack;
|
||||
|
||||
recursion_stack.emplace(0UL, size-1);
|
||||
recursion_stack.emplace(0UL, size - 1);
|
||||
|
||||
// mark locations as 'necessary' by divide-and-conquer
|
||||
while (!recursion_stack.empty())
|
||||
@@ -131,7 +130,7 @@ douglasPeucker(std::vector<util::FixedPointCoordinate>::const_iterator begin,
|
||||
}
|
||||
|
||||
auto simplified_size = std::count(is_necessary.begin(), is_necessary.end(), true);
|
||||
std::vector<util::FixedPointCoordinate> simplified_geometry;
|
||||
std::vector<util::Coordinate> simplified_geometry;
|
||||
simplified_geometry.reserve(simplified_size);
|
||||
for (auto idx : boost::irange<std::size_t>(0UL, size))
|
||||
{
|
||||
|
||||
@@ -20,10 +20,10 @@ namespace
|
||||
|
||||
unsigned calculateOverviewZoomLevel(const std::vector<LegGeometry> &leg_geometries)
|
||||
{
|
||||
int min_lon = std::numeric_limits<int>::max();
|
||||
int min_lat = std::numeric_limits<int>::max();
|
||||
int max_lon = -std::numeric_limits<int>::max();
|
||||
int max_lat = -std::numeric_limits<int>::max();
|
||||
util::FixedLongitude min_lon{std::numeric_limits<int>::max()};
|
||||
util::FixedLongitude max_lon{-std::numeric_limits<int>::max()};
|
||||
util::FixedLatitude min_lat{std::numeric_limits<int>::max()};
|
||||
util::FixedLatitude max_lat{-std::numeric_limits<int>::max()};
|
||||
|
||||
for (const auto &leg_geometry : leg_geometries)
|
||||
{
|
||||
@@ -36,12 +36,15 @@ unsigned calculateOverviewZoomLevel(const std::vector<LegGeometry> &leg_geometri
|
||||
}
|
||||
}
|
||||
|
||||
return util::tiles::getBBMaxZoomTile(min_lon, min_lat, max_lon, max_lat).z;
|
||||
return util::tiles::getBBMaxZoomTile(toFloating(min_lon), toFloating(min_lat),
|
||||
toFloating(max_lon), toFloating(max_lat))
|
||||
.z;
|
||||
}
|
||||
|
||||
std::vector<util::FixedPointCoordinate> simplifyGeometry(const std::vector<LegGeometry> &leg_geometries, const unsigned zoom_level)
|
||||
std::vector<util::Coordinate> simplifyGeometry(const std::vector<LegGeometry> &leg_geometries,
|
||||
const unsigned zoom_level)
|
||||
{
|
||||
std::vector<util::FixedPointCoordinate> overview_geometry;
|
||||
std::vector<util::Coordinate> overview_geometry;
|
||||
auto leg_index = 0UL;
|
||||
for (const auto geometry : leg_geometries)
|
||||
{
|
||||
@@ -59,8 +62,8 @@ std::vector<util::FixedPointCoordinate> simplifyGeometry(const std::vector<LegGe
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<util::FixedPointCoordinate>
|
||||
assembleOverview(const std::vector<LegGeometry> &leg_geometries, const bool use_simplification)
|
||||
std::vector<util::Coordinate> assembleOverview(const std::vector<LegGeometry> &leg_geometries,
|
||||
const bool use_simplification)
|
||||
{
|
||||
if (use_simplification)
|
||||
{
|
||||
@@ -75,7 +78,7 @@ assembleOverview(const std::vector<LegGeometry> &leg_geometries, const bool use_
|
||||
return sum + leg_geometry.locations.size();
|
||||
}) -
|
||||
leg_geometries.size() + 1;
|
||||
std::vector<util::FixedPointCoordinate> overview_geometry;
|
||||
std::vector<util::Coordinate> overview_geometry;
|
||||
overview_geometry.reserve(overview_size);
|
||||
|
||||
auto leg_index = 0UL;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace plugins
|
||||
{
|
||||
|
||||
// Filters PhantomNodes to obtain a set of viable candiates
|
||||
void filterCandidates(const std::vector<util::FixedPointCoordinate> &coordinates,
|
||||
void filterCandidates(const std::vector<util::Coordinate> &coordinates,
|
||||
MatchPlugin::CandidateLists &candidates_lists)
|
||||
{
|
||||
for (const auto current_coordinate : util::irange<std::size_t>(0, coordinates.size()))
|
||||
|
||||
@@ -57,7 +57,6 @@ std::string encode(std::vector<int> &numbers)
|
||||
}
|
||||
} // anonymous ns
|
||||
|
||||
|
||||
std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter end)
|
||||
{
|
||||
auto size = std::distance(begin, end);
|
||||
@@ -69,20 +68,22 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter
|
||||
std::vector<int> delta_numbers;
|
||||
BOOST_ASSERT(size > 0);
|
||||
delta_numbers.reserve((size - 1) * 2);
|
||||
util::FixedPointCoordinate previous_coordinate = {0, 0};
|
||||
std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const FixedPointCoordinate loc)
|
||||
{
|
||||
const int lat_diff = (loc.lat - previous_coordinate.lat) * detail::COORDINATE_TO_POLYLINE;
|
||||
const int lon_diff = (loc.lon - previous_coordinate.lon) * detail::COORDINATE_TO_POLYLINE;
|
||||
delta_numbers.emplace_back(lat_diff);
|
||||
delta_numbers.emplace_back(lon_diff);
|
||||
previous_coordinate = loc;
|
||||
});
|
||||
util::Coordinate previous_coordinate{util::FixedLongitude(0), util::FixedLatitude(0)};
|
||||
std::for_each(begin, end, [&delta_numbers, &previous_coordinate](const util::Coordinate loc)
|
||||
{
|
||||
const int lat_diff = static_cast<int>(loc.lat - previous_coordinate.lat) *
|
||||
detail::COORDINATE_TO_POLYLINE;
|
||||
const int lon_diff = static_cast<int>(loc.lon - previous_coordinate.lon) *
|
||||
detail::COORDINATE_TO_POLYLINE;
|
||||
delta_numbers.emplace_back(lat_diff);
|
||||
delta_numbers.emplace_back(lon_diff);
|
||||
previous_coordinate = loc;
|
||||
});
|
||||
return encode(delta_numbers);
|
||||
}
|
||||
std::vector<util::FixedPointCoordinate> decodePolyline(const std::string &geometry_string)
|
||||
std::vector<util::Coordinate> decodePolyline(const std::string &geometry_string)
|
||||
{
|
||||
std::vector<util::FixedPointCoordinate> new_coordinates;
|
||||
std::vector<util::Coordinate> new_coordinates;
|
||||
int index = 0, len = geometry_string.size();
|
||||
int lat = 0, lng = 0;
|
||||
|
||||
@@ -109,9 +110,9 @@ std::vector<util::FixedPointCoordinate> decodePolyline(const std::string &geomet
|
||||
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
|
||||
lng += dlng;
|
||||
|
||||
util::FixedPointCoordinate p;
|
||||
p.lat = lat * detail::POLYLINE_TO_COORDINATE;
|
||||
p.lon = lng * detail::POLYLINE_TO_COORDINATE;
|
||||
util::Coordinate p;
|
||||
p.lat = util::FixedLatitude(lat * detail::POLYLINE_TO_COORDINATE);
|
||||
p.lon = util::FixedLongitude(lng * detail::POLYLINE_TO_COORDINATE);
|
||||
new_coordinates.push_back(p);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user