First round of lat,lng -> lng,lat switcheroo

This commit is contained in:
Patrick Niklaus
2016-02-23 21:23:13 +01:00
parent 0fab6b7cab
commit d9d4742130
70 changed files with 893 additions and 817 deletions
+16 -19
View File
@@ -4,8 +4,7 @@
#include "engine/geospatial_query.hpp"
#include "util/timing_util.hpp"
#include "mocks/mock_datafacade.hpp"
#include "osrm/coordinate.hpp"
#include "util/coordinate.hpp"
#include <iostream>
#include <random>
@@ -25,23 +24,23 @@ constexpr int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION;
constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION;
using RTreeLeaf = extractor::EdgeBasedNode;
using FixedPointCoordinateListPtr = std::shared_ptr<std::vector<util::FixedPointCoordinate>>;
using CoordinateListPtr = std::shared_ptr<std::vector<util::Coordinate>>;
using BenchStaticRTree =
util::StaticRTree<RTreeLeaf, util::ShM<util::FixedPointCoordinate, false>::vector, false>;
util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, false>::vector, false>;
using BenchQuery = engine::GeospatialQuery<BenchStaticRTree, MockDataFacade>;
FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes_file)
CoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes_file)
{
boost::filesystem::ifstream nodes_input_stream(nodes_file, std::ios::binary);
extractor::QueryNode current_node;
unsigned coordinate_count = 0;
nodes_input_stream.read((char *)&coordinate_count, sizeof(unsigned));
auto coords = std::make_shared<std::vector<FixedPointCoordinate>>(coordinate_count);
auto coords = std::make_shared<std::vector<Coordinate>>(coordinate_count);
for (unsigned i = 0; i < coordinate_count; ++i)
{
nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode));
coords->at(i) = FixedPointCoordinate(current_node.lat, current_node.lon);
coords->at(i) = util::Coordinate(current_node.lon, current_node.lat);
BOOST_ASSERT((std::abs(coords->at(i).lat) >> 30) == 0);
BOOST_ASSERT((std::abs(coords->at(i).lon) >> 30) == 0);
}
@@ -49,7 +48,7 @@ FixedPointCoordinateListPtr loadCoordinates(const boost::filesystem::path &nodes
}
template <typename QueryT>
void benchmarkQuery(const std::vector<FixedPointCoordinate> &queries,
void benchmarkQuery(const std::vector<util::Coordinate> &queries,
const std::string &name,
QueryT query)
{
@@ -75,38 +74,35 @@ void benchmark(BenchStaticRTree &rtree, BenchQuery &geo_query, unsigned num_quer
std::mt19937 mt_rand(RANDOM_SEED);
std::uniform_int_distribution<> lat_udist(WORLD_MIN_LAT, WORLD_MAX_LAT);
std::uniform_int_distribution<> lon_udist(WORLD_MIN_LON, WORLD_MAX_LON);
std::vector<FixedPointCoordinate> queries;
std::vector<util::Coordinate> queries;
for (unsigned i = 0; i < num_queries; i++)
{
queries.emplace_back(lat_udist(mt_rand), lon_udist(mt_rand));
}
benchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const FixedPointCoordinate &q)
benchmarkQuery(queries, "raw RTree queries (1 result)", [&rtree](const util::Coordinate &q)
{
return rtree.Nearest(q, 1);
});
benchmarkQuery(queries, "raw RTree queries (10 results)",
[&rtree](const FixedPointCoordinate &q)
benchmarkQuery(queries, "raw RTree queries (10 results)", [&rtree](const util::Coordinate &q)
{
return rtree.Nearest(q, 10);
});
benchmarkQuery(queries, "big component alternative queries",
[&geo_query](const FixedPointCoordinate &q)
[&geo_query](const util::Coordinate &q)
{
return geo_query.NearestPhantomNodeWithAlternativeFromBigComponent(q);
});
benchmarkQuery(queries, "max distance 1000", [&geo_query](const FixedPointCoordinate &q)
benchmarkQuery(queries, "max distance 1000", [&geo_query](const util::Coordinate &q)
{
return geo_query.NearestPhantomNodesInRange(q, 1000);
});
benchmarkQuery(queries, "PhantomNode query (1 result)",
[&geo_query](const FixedPointCoordinate &q)
benchmarkQuery(queries, "PhantomNode query (1 result)", [&geo_query](const util::Coordinate &q)
{
return geo_query.NearestPhantomNodes(q, 1);
});
benchmarkQuery(queries, "PhantomNode query (10 result)",
[&geo_query](const FixedPointCoordinate &q)
benchmarkQuery(queries, "PhantomNode query (10 result)", [&geo_query](const util::Coordinate &q)
{
return geo_query.NearestPhantomNodes(q, 10);
});
@@ -130,7 +126,8 @@ int main(int argc, char **argv)
auto coords = osrm::benchmarks::loadCoordinates(nodes_path);
osrm::benchmarks::BenchStaticRTree rtree(ram_path, file_path, coords);
std::unique_ptr<osrm::benchmarks::MockDataFacade> mockfacade_ptr(new osrm::benchmarks::MockDataFacade);
std::unique_ptr<osrm::benchmarks::MockDataFacade> mockfacade_ptr(
new osrm::benchmarks::MockDataFacade);
osrm::benchmarks::BenchQuery query(rtree, coords, *mockfacade_ptr);
osrm::benchmarks::benchmark(rtree, query, 10000);
+74 -47
View File
@@ -37,7 +37,7 @@ template <> struct hash<std::pair<OSMNodeID, OSMNodeID>>
{
std::size_t operator()(const std::pair<OSMNodeID, OSMNodeID> &k) const
{
return OSMNodeID_to_uint64_t(k.first) ^ (OSMNodeID_to_uint64_t(k.second) << 12);
return static_cast<uint64_t>(k.first) ^ (static_cast<uint64_t>(k.second) << 12);
}
};
}
@@ -70,9 +70,8 @@ int Contractor::Run()
util::DeallocatingVector<extractor::EdgeBasedEdge> edge_based_edge_list;
std::size_t max_edge_id = LoadEdgeExpandedGraph(
config.edge_based_graph_path, edge_based_edge_list,
config.edge_segment_lookup_path, config.edge_penalty_path,
config.segment_speed_lookup_path, config.node_based_graph_path,
config.edge_based_graph_path, edge_based_edge_list, config.edge_segment_lookup_path,
config.edge_penalty_path, config.segment_speed_lookup_path, config.node_based_graph_path,
config.geometry_path, config.rtree_leaf_path);
// Contracting the edge-expanded graph
@@ -195,7 +194,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
if (!nodes_input_stream)
{
throw util::exception("Failed to open "+nodes_filename);
throw util::exception("Failed to open " + nodes_filename);
}
unsigned number_of_nodes = 0;
@@ -203,7 +202,8 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
internal_to_external_node_map.resize(number_of_nodes);
// Load all the query nodes into a vector
nodes_input_stream.read(reinterpret_cast<char *>(&(internal_to_external_node_map[0])), number_of_nodes * sizeof(extractor::QueryNode));
nodes_input_stream.read(reinterpret_cast<char *>(&(internal_to_external_node_map[0])),
number_of_nodes * sizeof(extractor::QueryNode));
}
std::vector<unsigned> m_geometry_indices;
@@ -213,7 +213,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
std::ifstream geometry_stream(geometry_filename, std::ios::binary);
if (!geometry_stream)
{
throw util::exception("Failed to open "+geometry_filename);
throw util::exception("Failed to open " + geometry_filename);
}
unsigned number_of_indices = 0;
unsigned number_of_compressed_geometries = 0;
@@ -224,18 +224,20 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
if (number_of_indices > 0)
{
geometry_stream.read((char *)&(m_geometry_indices[0]),
number_of_indices * sizeof(unsigned));
number_of_indices * sizeof(unsigned));
}
geometry_stream.read((char *)&number_of_compressed_geometries, sizeof(unsigned));
BOOST_ASSERT(m_geometry_indices.back() == number_of_compressed_geometries);
m_geometry_list.resize(number_of_compressed_geometries);
if (number_of_compressed_geometries > 0)
{
geometry_stream.read((char *)&(m_geometry_list[0]),
number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
geometry_stream.read(
(char *)&(m_geometry_list[0]),
number_of_compressed_geometries *
sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
}
}
@@ -249,7 +251,7 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
std::ifstream leaf_node_file(rtree_leaf_filename, std::ios::binary | std::ios::in);
if (!leaf_node_file)
{
throw util::exception("Failed to open "+rtree_leaf_filename);
throw util::exception("Failed to open " + rtree_leaf_filename);
}
uint64_t m_element_count;
leaf_node_file.read((char *)&m_element_count, sizeof(uint64_t));
@@ -259,90 +261,115 @@ std::size_t Contractor::LoadEdgeExpandedGraph(
{
leaf_node_file.read(reinterpret_cast<char *>(&current_node), sizeof(current_node));
for (size_t i=0; i< current_node.object_count; i++)
for (size_t i = 0; i < current_node.object_count; i++)
{
auto & leaf_object = current_node.objects[i];
auto &leaf_object = current_node.objects[i];
extractor::QueryNode *u;
extractor::QueryNode *v;
if (leaf_object.forward_packed_geometry_id != SPECIAL_EDGEID)
{
const unsigned forward_begin = m_geometry_indices.at(leaf_object.forward_packed_geometry_id);
const unsigned forward_begin =
m_geometry_indices.at(leaf_object.forward_packed_geometry_id);
if (leaf_object.fwd_segment_position == 0)
{
u = &(internal_to_external_node_map[leaf_object.u]);
v = &(internal_to_external_node_map[m_geometry_list[forward_begin].node_id]);
v = &(internal_to_external_node_map[m_geometry_list[forward_begin]
.node_id]);
}
else
{
u = &(internal_to_external_node_map[m_geometry_list[forward_begin + leaf_object.fwd_segment_position - 1].node_id]);
v = &(internal_to_external_node_map[m_geometry_list[forward_begin + leaf_object.fwd_segment_position].node_id]);
u = &(internal_to_external_node_map
[m_geometry_list[forward_begin +
leaf_object.fwd_segment_position - 1]
.node_id]);
v = &(internal_to_external_node_map
[m_geometry_list[forward_begin +
leaf_object.fwd_segment_position]
.node_id]);
}
const double segment_length =
util::coordinate_calculation::greatCircleDistance(
u->lat, u->lon, v->lat, v->lon);
util::coordinate_calculation::greatCircleDistance(
util::Coordinate{u->lon, u->lat}, util::Coordinate{v->lon, v->lat});
auto forward_speed_iter = segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id));
auto forward_speed_iter =
segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id));
if (forward_speed_iter != segment_speed_lookup.end())
{
int new_segment_weight =
std::max(1, static_cast<int>(std::floor(
(segment_length * 10.) / (forward_speed_iter->second / 3.6) + .5)));
m_geometry_list[forward_begin + leaf_object.fwd_segment_position].weight = new_segment_weight;
int new_segment_weight = std::max(
1, static_cast<int>(std::floor(
(segment_length * 10.) / (forward_speed_iter->second / 3.6) +
.5)));
m_geometry_list[forward_begin + leaf_object.fwd_segment_position]
.weight = new_segment_weight;
}
}
if (leaf_object.reverse_packed_geometry_id != SPECIAL_EDGEID)
{
const unsigned reverse_begin = m_geometry_indices.at(leaf_object.reverse_packed_geometry_id);
const unsigned reverse_end = m_geometry_indices.at(leaf_object.reverse_packed_geometry_id + 1);
const unsigned reverse_begin =
m_geometry_indices.at(leaf_object.reverse_packed_geometry_id);
const unsigned reverse_end =
m_geometry_indices.at(leaf_object.reverse_packed_geometry_id + 1);
int rev_segment_position = (reverse_end - reverse_begin) - leaf_object.fwd_segment_position - 1;
int rev_segment_position =
(reverse_end - reverse_begin) - leaf_object.fwd_segment_position - 1;
if (rev_segment_position == 0)
{
u = &(internal_to_external_node_map[leaf_object.v]);
v = &(internal_to_external_node_map[m_geometry_list[reverse_begin].node_id]);
v = &(internal_to_external_node_map[m_geometry_list[reverse_begin]
.node_id]);
}
else
{
u = &(internal_to_external_node_map[m_geometry_list[reverse_begin + rev_segment_position - 1].node_id]);
v = &(internal_to_external_node_map[m_geometry_list[reverse_begin + rev_segment_position].node_id]);
u = &(internal_to_external_node_map
[m_geometry_list[reverse_begin + rev_segment_position - 1]
.node_id]);
v = &(
internal_to_external_node_map[m_geometry_list[reverse_begin +
rev_segment_position]
.node_id]);
}
const double segment_length =
util::coordinate_calculation::greatCircleDistance(
u->lat, u->lon, v->lat, v->lon);
util::coordinate_calculation::greatCircleDistance(
util::Coordinate{u->lon, u->lat}, util::Coordinate{v->lon, v->lat});
auto reverse_speed_iter = segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id));
auto reverse_speed_iter =
segment_speed_lookup.find(std::make_pair(u->node_id, v->node_id));
if (reverse_speed_iter != segment_speed_lookup.end())
{
int new_segment_weight =
std::max(1, static_cast<int>(std::floor(
(segment_length * 10.) / (reverse_speed_iter->second / 3.6) + .5)));
m_geometry_list[reverse_begin + rev_segment_position].weight = new_segment_weight;
int new_segment_weight = std::max(
1, static_cast<int>(std::floor(
(segment_length * 10.) / (reverse_speed_iter->second / 3.6) +
.5)));
m_geometry_list[reverse_begin + rev_segment_position].weight =
new_segment_weight;
}
}
}
m_element_count -= current_node.object_count;
}
}
// Now save out the updated compressed geometries
{
std::ofstream geometry_stream(geometry_filename, std::ios::binary);
if (!geometry_stream)
{
throw util::exception("Failed to open "+geometry_filename+" for writing");
throw util::exception("Failed to open " + geometry_filename + " for writing");
}
const unsigned number_of_indices = m_geometry_indices.size();
const unsigned number_of_compressed_geometries = m_geometry_list.size();
geometry_stream.write(reinterpret_cast<const char *>(&number_of_indices), sizeof(unsigned));
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_indices[0])), number_of_indices * sizeof(unsigned));
geometry_stream.write(reinterpret_cast<const char *>(&number_of_compressed_geometries), sizeof(unsigned));
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_list[0])), number_of_compressed_geometries * sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
geometry_stream.write(reinterpret_cast<const char *>(&number_of_indices),
sizeof(unsigned));
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_indices[0])),
number_of_indices * sizeof(unsigned));
geometry_stream.write(reinterpret_cast<const char *>(&number_of_compressed_geometries),
sizeof(unsigned));
geometry_stream.write(reinterpret_cast<char *>(&(m_geometry_list[0])),
number_of_compressed_geometries *
sizeof(extractor::CompressedEdgeContainer::CompressedEdge));
}
}
// TODO: can we read this in bulk? util::DeallocatingVector isn't necessarily
+4 -4
View File
@@ -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);
+15 -16
View File
@@ -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))
{
+13 -10
View File
@@ -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;
+1 -1
View File
@@ -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()))
+16 -15
View File
@@ -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);
}
+14 -16
View File
@@ -73,10 +73,10 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector<EdgeBasedNode> &nodes)
#ifndef NDEBUG
for (const EdgeBasedNode &node : m_edge_based_node_list)
{
BOOST_ASSERT(m_node_info_list.at(node.u).lat != INT_MAX);
BOOST_ASSERT(m_node_info_list.at(node.u).lon != INT_MAX);
BOOST_ASSERT(m_node_info_list.at(node.v).lon != INT_MAX);
BOOST_ASSERT(m_node_info_list.at(node.v).lat != INT_MAX);
BOOST_ASSERT(
util::Coordinate(m_node_info_list[node.u].lon, m_node_info_list[node.u].lat).IsValid());
BOOST_ASSERT(
util::Coordinate(m_node_info_list[node.v].lon, m_node_info_list[node.v].lat).IsValid());
}
#endif
using std::swap; // Koenig swap
@@ -424,8 +424,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
const QueryNode &from = m_node_info_list[previous];
const QueryNode &to = m_node_info_list[target_node.node_id];
const double segment_length =
util::coordinate_calculation::greatCircleDistance(from.lat, from.lon,
to.lat, to.lon);
util::coordinate_calculation::greatCircleDistance(from, to);
edge_segment_file.write(reinterpret_cast<const char *>(&to.node_id),
sizeof(to.node_id));
@@ -1003,10 +1002,9 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
{
if (m_compressed_edge_container.HasEntryForID(via_eid))
{
util::FixedPointCoordinate prev = util::FixedPointCoordinate(
m_node_info_list[INVERTED ? tgt : src].lat,
m_node_info_list[INVERTED ? tgt : src].lon),
cur;
util::Coordinate prev = util::Coordinate(m_node_info_list[INVERTED ? tgt : src].lon,
m_node_info_list[INVERTED ? tgt : src].lat),
cur;
// walk along the edge for the first 5 meters
const auto &geometry = m_compressed_edge_container.GetBucketReference(via_eid);
double dist = 0;
@@ -1035,8 +1033,8 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
for (auto itr = geometry.rbegin(), end = geometry.rend(); itr != end; ++itr)
{
const auto compressed_node = *itr;
cur = util::FixedPointCoordinate(m_node_info_list[compressed_node.node_id].lat,
m_node_info_list[compressed_node.node_id].lon);
cur = util::Coordinate(m_node_info_list[compressed_node.node_id].lon,
m_node_info_list[compressed_node.node_id].lat);
this_dist = util::coordinate_calculation::haversineDistance(prev, cur);
if (dist + this_dist > DESIRED_SEGMENT_LENGTH)
{
@@ -1047,7 +1045,7 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
prev = cur;
prev_id = compressed_node.node_id;
}
cur = util::FixedPointCoordinate(m_node_info_list[src].lat, m_node_info_list[src].lon);
cur = util::Coordinate(m_node_info_list[src].lon, m_node_info_list[src].lat);
this_dist = util::coordinate_calculation::haversineDistance(prev, cur);
return selectBestCandidate(src, dist + this_dist, prev_id, dist);
}
@@ -1056,8 +1054,8 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
for (auto itr = geometry.begin(), end = geometry.end(); itr != end; ++itr)
{
const auto compressed_node = *itr;
cur = util::FixedPointCoordinate(m_node_info_list[compressed_node.node_id].lat,
m_node_info_list[compressed_node.node_id].lon);
cur = util::Coordinate(m_node_info_list[compressed_node.node_id].lon,
m_node_info_list[compressed_node.node_id].lat);
this_dist = util::coordinate_calculation::haversineDistance(prev, cur);
if (dist + this_dist > DESIRED_SEGMENT_LENGTH)
{
@@ -1068,7 +1066,7 @@ QueryNode EdgeBasedGraphFactory::getRepresentativeCoordinate(const NodeID src,
prev = cur;
prev_id = compressed_node.node_id;
}
cur = util::FixedPointCoordinate(m_node_info_list[tgt].lat, m_node_info_list[tgt].lon);
cur = util::Coordinate(m_node_info_list[tgt].lon, m_node_info_list[tgt].lat);
this_dist = util::coordinate_calculation::haversineDistance(prev, cur);
return selectBestCandidate(tgt, dist + this_dist, prev_id, dist);
}
+7 -5
View File
@@ -301,7 +301,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
{
util::SimpleLogger().Write(LogLevel::logWARNING)
<< "Found invalid node reference "
<< OSMNodeID_to_uint64_t(edge_iterator->result.osm_target_id);
<< static_cast<uint64_t>(edge_iterator->result.osm_target_id);
edge_iterator->result.target = SPECIAL_NODEID;
++edge_iterator;
continue;
@@ -314,12 +314,14 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
BOOST_ASSERT(edge_iterator->result.osm_target_id == node_iterator->node_id);
BOOST_ASSERT(edge_iterator->weight_data.speed >= 0);
BOOST_ASSERT(edge_iterator->source_coordinate.lat != std::numeric_limits<int>::min());
BOOST_ASSERT(edge_iterator->source_coordinate.lon != std::numeric_limits<int>::min());
BOOST_ASSERT(edge_iterator->source_coordinate.lat !=
util::FixedLatitude(std::numeric_limits<int>::min()));
BOOST_ASSERT(edge_iterator->source_coordinate.lon !=
util::FixedLongitude(std::numeric_limits<int>::min()));
const double distance = util::coordinate_calculation::greatCircleDistance(
edge_iterator->source_coordinate.lat, edge_iterator->source_coordinate.lon,
node_iterator->lat, node_iterator->lon);
edge_iterator->source_coordinate,
util::Coordinate(node_iterator->lon, node_iterator->lat));
if (util::lua_function_exists(segment_state, "segment_function"))
{
+2 -2
View File
@@ -39,8 +39,8 @@ void ExtractorCallbacks::ProcessNode(const osmium::Node &input_node,
const ExtractionNode &result_node)
{
external_memory.all_nodes_list.push_back(
{static_cast<int>(input_node.location().lat() * COORDINATE_PRECISION),
static_cast<int>(input_node.location().lon() * COORDINATE_PRECISION),
{util::toFixed(util::FloatLongitude(input_node.location().lon())),
util::toFixed(util::FloatLatitude(input_node.location().lat())),
OSMNodeID(input_node.id()), result_node.barrier, result_node.traffic_lights});
}
+18 -8
View File
@@ -31,6 +31,16 @@ auto get_value_by_key(T const &object, const char *key) -> decltype(object.get_v
return object.get_value_by_key(key, "");
}
template <class T> double latToDouble(T const &object)
{
return static_cast<double>(util::toFloating(object.lat));
}
template <class T> double lonToDouble(T const &object)
{
return static_cast<double>(util::toFloating(object.lon));
}
// Error handler
int luaErrorCallback(lua_State *state)
{
@@ -108,18 +118,18 @@ void ScriptingEnvironment::InitLuaState(lua_State *lua_state)
.def("get_value_by_key", &get_value_by_key<osmium::Way>)
.def("id", &osmium::Way::id),
luabind::class_<InternalExtractorEdge>("EdgeSource")
.property("source_coordinate", &InternalExtractorEdge::source_coordinate)
.property("weight_data", &InternalExtractorEdge::weight_data),
.def_readonly("source_coordinate", &InternalExtractorEdge::source_coordinate)
.def_readwrite("weight_data", &InternalExtractorEdge::weight_data),
luabind::class_<InternalExtractorEdge::WeightData>("WeightData")
.def_readwrite("speed", &InternalExtractorEdge::WeightData::speed),
luabind::class_<ExternalMemoryNode>("EdgeTarget")
.property("lat", &ExternalMemoryNode::lat)
.property("lon", &ExternalMemoryNode::lon),
luabind::class_<util::FixedPointCoordinate>("Coordinate")
.property("lat", &util::FixedPointCoordinate::lat)
.property("lon", &util::FixedPointCoordinate::lon),
.property("lon", &lonToDouble<ExternalMemoryNode>)
.property("lat", &latToDouble<ExternalMemoryNode>),
luabind::class_<util::Coordinate>("Coordinate")
.property("lon", &lonToDouble<util::Coordinate>)
.property("lat", &latToDouble<util::Coordinate>),
luabind::class_<RasterDatum>("RasterDatum")
.property("datum", &RasterDatum::datum)
.def_readonly("datum", &RasterDatum::datum)
.def("invalid_data", &RasterDatum::get_invalid)];
if (0 != luaL_dofile(lua_state, file_name.c_str()))
+3 -3
View File
@@ -47,9 +47,9 @@ struct URLGrammar : boost::spirit::qi::grammar<Iterator>
};
const auto add_coordinate = [this](const boost::fusion::vector<double, double> &lonLat)
{
parsed_url.coordinates.emplace_back(
util::FixedPointCoordinate(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION,
boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION));
parsed_url.coordinates.emplace_back(util::Coordinate(
util::FixedLongitude(boost::fusion::at_c<0>(lonLat) * COORDINATE_PRECISION),
util::FixedLatitude(boost::fusion::at_c<1>(lonLat) * COORDINATE_PRECISION)));
};
const auto polyline_to_coordinates = [this](const std::string &polyline)
{
+1 -1
View File
@@ -40,7 +40,7 @@ std::string getWrongOptionHelp(const engine::api::MatchParameters &parameters)
}
} // anon. ns
engine::Status MatchService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
engine::Status MatchService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options,
util::json::Object &result)
{
+1 -1
View File
@@ -39,7 +39,7 @@ std::string getWrongOptionHelp(const engine::api::NearestParameters &parameters)
}
} // anon. ns
engine::Status NearestService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
engine::Status NearestService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options,
util::json::Object &result)
{
+1 -1
View File
@@ -38,7 +38,7 @@ std::string getWrongOptionHelp(const engine::api::RouteParameters &parameters)
}
} // anon. ns
engine::Status RouteService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
engine::Status RouteService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options,
util::json::Object &result)
{
+1 -1
View File
@@ -57,7 +57,7 @@ std::string getWrongOptionHelp(const engine::api::TableParameters &parameters)
}
} // anon. ns
engine::Status TableService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
engine::Status TableService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options,
util::json::Object &result)
{
+3 -4
View File
@@ -38,9 +38,9 @@ std::string getWrongOptionHelp(const engine::api::TripParameters &parameters)
}
} // anon. ns
engine::Status TripService::RunQuery(std::vector<util::FixedPointCoordinate> coordinates,
std::string &options,
util::json::Object &result)
engine::Status TripService::RunQuery(std::vector<util::Coordinate> coordinates,
std::string &options,
util::json::Object &result)
{
auto options_iterator = options.begin();
auto parameters =
@@ -67,7 +67,6 @@ engine::Status TripService::RunQuery(std::vector<util::FixedPointCoordinate> coo
return BaseService::routing_machine.Trip(*parameters, result);
}
}
}
}
+9 -13
View File
@@ -17,8 +17,7 @@
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/typedefs.hpp"
#include "osrm/coordinate.hpp"
#include "util/coordinate.hpp"
#ifdef __linux__
#include <sys/mman.h>
@@ -38,11 +37,9 @@ namespace osrm
namespace storage
{
using RTreeLeaf =
typename engine::datafacade::BaseDataFacade::RTreeLeaf;
using RTreeNode = util::StaticRTree<RTreeLeaf,
util::ShM<util::FixedPointCoordinate, true>::vector,
true>::TreeNode;
using RTreeLeaf = typename engine::datafacade::BaseDataFacade::RTreeLeaf;
using RTreeNode =
util::StaticRTree<RTreeLeaf, util::ShM<util::Coordinate, true>::vector, true>::TreeNode;
using QueryGraph = util::StaticGraph<contractor::QueryEdge::EdgeData>;
// delete a shared memory region. report warning if it could not be deleted
@@ -309,8 +306,8 @@ int Storage::Run()
boost::filesystem::ifstream nodes_input_stream(nodes_data_path, std::ios::binary);
unsigned coordinate_list_size = 0;
nodes_input_stream.read((char *)&coordinate_list_size, sizeof(unsigned));
shared_layout_ptr->SetBlockSize<util::FixedPointCoordinate>(SharedDataLayout::COORDINATE_LIST,
coordinate_list_size);
shared_layout_ptr->SetBlockSize<util::Coordinate>(SharedDataLayout::COORDINATE_LIST,
coordinate_list_size);
// load geometries sizes
std::ifstream geometry_input_stream(geometries_data_path.string().c_str(), std::ios::binary);
@@ -438,15 +435,14 @@ int Storage::Run()
}
// Loading list of coordinates
util::FixedPointCoordinate *coordinates_ptr =
shared_layout_ptr->GetBlockPtr<util::FixedPointCoordinate, true>(
shared_memory_ptr, SharedDataLayout::COORDINATE_LIST);
util::Coordinate *coordinates_ptr = shared_layout_ptr->GetBlockPtr<util::Coordinate, true>(
shared_memory_ptr, SharedDataLayout::COORDINATE_LIST);
extractor::QueryNode current_node;
for (unsigned i = 0; i < coordinate_list_size; ++i)
{
nodes_input_stream.read((char *)&current_node, sizeof(extractor::QueryNode));
coordinates_ptr[i] = util::FixedPointCoordinate(current_node.lat, current_node.lon);
coordinates_ptr[i] = util::Coordinate(current_node.lon, current_node.lat);
}
nodes_input_stream.close();
+25 -22
View File
@@ -16,49 +16,52 @@ namespace osrm
namespace util
{
FixedPointCoordinate::FixedPointCoordinate()
: lat(std::numeric_limits<int>::min()), lon(std::numeric_limits<int>::min())
Coordinate::Coordinate()
: lon(std::numeric_limits<int>::min()), lat(std::numeric_limits<int>::min())
{
}
FixedPointCoordinate::FixedPointCoordinate(int lat, int lon) : lat(lat), lon(lon)
Coordinate::Coordinate(const FloatLongitude lon_, const FloatLatitude lat_)
: Coordinate(toFixed(lon_), toFixed(lat_))
{
}
Coordinate::Coordinate(const FixedLongitude lon_, const FixedLatitude lat_) : lon(lon_), lat(lat_)
{
#ifndef NDEBUG
if (0 != (std::abs(lat) >> 30))
if (0 != (std::abs(static_cast<int>(lon)) >> 30))
{
std::bitset<32> y_coordinate_vector(lat);
SimpleLogger().Write(logDEBUG) << "broken lat: " << lat
<< ", bits: " << y_coordinate_vector;
}
if (0 != (std::abs(lon) >> 30))
{
std::bitset<32> x_coordinate_vector(lon);
std::bitset<32> x_coordinate_vector(static_cast<int>(lon));
SimpleLogger().Write(logDEBUG) << "broken lon: " << lon
<< ", bits: " << x_coordinate_vector;
}
if (0 != (std::abs(static_cast<int>(lat)) >> 30))
{
std::bitset<32> y_coordinate_vector(static_cast<int>(lat));
SimpleLogger().Write(logDEBUG) << "broken lat: " << lat
<< ", bits: " << y_coordinate_vector;
}
#endif
}
bool FixedPointCoordinate::IsValid() const
bool Coordinate::IsValid() const
{
return !(lat > 90 * COORDINATE_PRECISION || lat < -90 * COORDINATE_PRECISION ||
lon > 180 * COORDINATE_PRECISION || lon < -180 * COORDINATE_PRECISION);
return !(lat > FixedLatitude(90 * COORDINATE_PRECISION) ||
lat < FixedLatitude(-90 * COORDINATE_PRECISION) ||
lon > FixedLongitude(180 * COORDINATE_PRECISION) ||
lon < FixedLongitude(-180 * COORDINATE_PRECISION));
}
bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs)
bool operator==(const Coordinate lhs, const Coordinate rhs)
{
return lhs.lat == rhs.lat && lhs.lon == rhs.lon;
}
bool operator!=(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs)
{
return !(lhs == rhs);
}
bool operator!=(const Coordinate lhs, const Coordinate rhs) { return !(lhs == rhs); }
std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate)
std::ostream &operator<<(std::ostream &out, const Coordinate coordinate)
{
out << "(" << static_cast<double>(coordinate.lat / COORDINATE_PRECISION) << ","
<< static_cast<double>(coordinate.lon / COORDINATE_PRECISION) << ")";
out << "(lon:" << toFloating(coordinate.lon) << ", lat:" << toFloating(coordinate.lat) << ")";
return out;
}
}
+62 -69
View File
@@ -17,12 +17,16 @@ namespace util
namespace coordinate_calculation
{
double haversineDistance(const int lat1, const int lon1, const int lat2, const int lon2)
double haversineDistance(const Coordinate coordinate_1, const Coordinate coordinate_2)
{
BOOST_ASSERT(lat1 != std::numeric_limits<int>::min());
auto lon1 = static_cast<int>(coordinate_1.lon);
auto lat1 = static_cast<int>(coordinate_1.lat);
auto lon2 = static_cast<int>(coordinate_2.lon);
auto lat2 = static_cast<int>(coordinate_2.lat);
BOOST_ASSERT(lon1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat2 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lon2 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat2 != std::numeric_limits<int>::min());
const double lt1 = lat1 / COORDINATE_PRECISION;
const double ln1 = lon1 / COORDINATE_PRECISION;
const double lt2 = lat2 / COORDINATE_PRECISION;
@@ -42,22 +46,12 @@ double haversineDistance(const int lat1, const int lon1, const int lat2, const i
return EARTH_RADIUS * charv;
}
double haversineDistance(const FixedPointCoordinate coordinate_1,
const FixedPointCoordinate coordinate_2)
{
return haversineDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat,
coordinate_2.lon);
}
double greatCircleDistance(const FixedPointCoordinate coordinate_1,
const FixedPointCoordinate coordinate_2)
{
return greatCircleDistance(coordinate_1.lat, coordinate_1.lon, coordinate_2.lat,
coordinate_2.lon);
}
double greatCircleDistance(const int lat1, const int lon1, const int lat2, const int lon2)
double greatCircleDistance(const Coordinate coordinate_1, const Coordinate coordinate_2)
{
auto lon1 = static_cast<int>(coordinate_1.lon);
auto lat1 = static_cast<int>(coordinate_1.lat);
auto lon2 = static_cast<int>(coordinate_2.lon);
auto lat2 = static_cast<int>(coordinate_2.lat);
BOOST_ASSERT(lat1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lon1 != std::numeric_limits<int>::min());
BOOST_ASSERT(lat2 != std::numeric_limits<int>::min());
@@ -73,65 +67,65 @@ double greatCircleDistance(const int lat1, const int lon1, const int lat2, const
return std::hypot(x_value, y_value) * EARTH_RADIUS;
}
double perpendicularDistance(const FixedPointCoordinate source_coordinate,
const FixedPointCoordinate target_coordinate,
const FixedPointCoordinate query_location)
double perpendicularDistance(const Coordinate source_coordinate,
const Coordinate target_coordinate,
const Coordinate query_location)
{
double ratio;
FixedPointCoordinate nearest_location;
Coordinate nearest_location;
return perpendicularDistance(source_coordinate, target_coordinate, query_location,
nearest_location, ratio);
}
double perpendicularDistance(const FixedPointCoordinate segment_source,
const FixedPointCoordinate segment_target,
const FixedPointCoordinate query_location,
FixedPointCoordinate &nearest_location,
double perpendicularDistance(const Coordinate segment_source,
const Coordinate segment_target,
const Coordinate query_location,
Coordinate &nearest_location,
double &ratio)
{
using namespace coordinate_calculation;
return perpendicularDistanceFromProjectedCoordinate(
segment_source, segment_target, query_location,
{mercator::latToY(query_location.lat / COORDINATE_PRECISION),
query_location.lon / COORDINATE_PRECISION},
{static_cast<double>(toFloating(query_location.lon)),
mercator::latToY(toFloating(query_location.lat))},
nearest_location, ratio);
}
double
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate source_coordinate,
const FixedPointCoordinate target_coordinate,
const FixedPointCoordinate query_location,
const std::pair<double, double> projected_coordinate)
double perpendicularDistanceFromProjectedCoordinate(
const Coordinate source_coordinate,
const Coordinate target_coordinate,
const Coordinate query_location,
const std::pair<double, double> projected_xy_coordinate)
{
double ratio;
FixedPointCoordinate nearest_location;
Coordinate nearest_location;
return perpendicularDistanceFromProjectedCoordinate(source_coordinate, target_coordinate,
query_location, projected_coordinate,
query_location, projected_xy_coordinate,
nearest_location, ratio);
}
double
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source,
const FixedPointCoordinate segment_target,
const FixedPointCoordinate query_location,
const std::pair<double, double> projected_coordinate,
FixedPointCoordinate &nearest_location,
double &ratio)
double perpendicularDistanceFromProjectedCoordinate(
const Coordinate segment_source,
const Coordinate segment_target,
const Coordinate query_location,
const std::pair<double, double> projected_xy_coordinate,
Coordinate &nearest_location,
double &ratio)
{
using namespace coordinate_calculation;
BOOST_ASSERT(query_location.IsValid());
// initialize values
const double x = projected_coordinate.first;
const double y = projected_coordinate.second;
const double a = mercator::latToY(segment_source.lat / COORDINATE_PRECISION);
const double b = segment_source.lon / COORDINATE_PRECISION;
const double c = mercator::latToY(segment_target.lat / COORDINATE_PRECISION);
const double d = segment_target.lon / COORDINATE_PRECISION;
const double x = projected_xy_coordinate.first;
const double y = projected_xy_coordinate.second;
const double a = mercator::latToY(toFloating(segment_source.lat));
const double b = static_cast<double>(toFloating(segment_source.lon));
const double c = mercator::latToY(toFloating(segment_target.lat));
const double d = static_cast<double>(toFloating(segment_target.lon));
double p, q /*,mX*/, new_y;
if (std::abs(a - c) > std::numeric_limits<double>::epsilon())
{
@@ -184,8 +178,8 @@ perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_
else
{
// point lies in between
nearest_location.lat = static_cast<int>(mercator::yToLat(p) * COORDINATE_PRECISION);
nearest_location.lon = static_cast<int>(q * COORDINATE_PRECISION);
nearest_location.lon = toFixed(FloatLongitude(q));
nearest_location.lat = toFixed(FloatLatitude(mercator::yToLat(p)));
}
BOOST_ASSERT(nearest_location.IsValid());
@@ -206,14 +200,13 @@ double radToDeg(const double radian)
return radian * (180.0 * (1. / pi<double>()));
}
double bearing(const FixedPointCoordinate first_coordinate,
const FixedPointCoordinate second_coordinate)
double bearing(const Coordinate first_coordinate, const Coordinate second_coordinate)
{
const double lon_diff =
second_coordinate.lon / COORDINATE_PRECISION - first_coordinate.lon / COORDINATE_PRECISION;
static_cast<double>(toFloating(second_coordinate.lon - first_coordinate.lon));
const double lon_delta = degToRad(lon_diff);
const double lat1 = degToRad(first_coordinate.lat / COORDINATE_PRECISION);
const double lat2 = degToRad(second_coordinate.lat / COORDINATE_PRECISION);
const double lat1 = degToRad(static_cast<double>(toFloating(first_coordinate.lat)));
const double lat2 = degToRad(static_cast<double>(toFloating(second_coordinate.lat)));
const double y = std::sin(lon_delta) * std::cos(lat2);
const double x =
std::cos(lat1) * std::sin(lat2) - std::sin(lat1) * std::cos(lat2) * std::cos(lon_delta);
@@ -230,19 +223,17 @@ double bearing(const FixedPointCoordinate first_coordinate,
return result;
}
double computeAngle(const FixedPointCoordinate first,
const FixedPointCoordinate second,
const FixedPointCoordinate third)
double computeAngle(const Coordinate first, const Coordinate second, const Coordinate third)
{
using namespace boost::math::constants;
using namespace coordinate_calculation;
const double v1x = (first.lon - second.lon) / COORDINATE_PRECISION;
const double v1y = mercator::latToY(first.lat / COORDINATE_PRECISION) -
mercator::latToY(second.lat / COORDINATE_PRECISION);
const double v2x = (third.lon - second.lon) / COORDINATE_PRECISION;
const double v2y = mercator::latToY(third.lat / COORDINATE_PRECISION) -
mercator::latToY(second.lat / COORDINATE_PRECISION);
const double v1x = static_cast<double>(toFloating(first.lon - second.lon));
const double v1y =
mercator::latToY(toFloating(first.lat)) - mercator::latToY(toFloating(second.lat));
const double v2x = static_cast<double>(toFloating(third.lon - second.lon));
const double v2y =
mercator::latToY(toFloating(third.lat)) - mercator::latToY(toFloating(second.lat));
double angle = (atan2_lookup(v2y, v2x) - atan2_lookup(v1y, v1x)) * 180. / pi<double>();
@@ -256,20 +247,22 @@ double computeAngle(const FixedPointCoordinate first,
namespace mercator
{
double yToLat(const double value)
FloatLatitude yToLat(const double value)
{
using namespace boost::math::constants;
return 180. * (1. / pi<long double>()) *
(2. * std::atan(std::exp(value * pi<double>() / 180.)) - half_pi<double>());
return FloatLatitude(
180. * (1. / pi<long double>()) *
(2. * std::atan(std::exp(value * pi<double>() / 180.)) - half_pi<double>()));
}
double latToY(const double latitude)
double latToY(const FloatLatitude latitude)
{
using namespace boost::math::constants;
return 180. * (1. / pi<double>()) *
std::log(std::tan((pi<double>() / 4.) + latitude * (pi<double>() / 180.) / 2.));
std::log(std::tan((pi<double>() / 4.) +
static_cast<double>(latitude) * (pi<double>() / 180.) / 2.));
}
} // ns mercato // ns mercatorr
} // ns coordinate_calculation
+7 -5
View File
@@ -8,7 +8,7 @@ namespace util
namespace
{
std::uint64_t bitInterleaving(const std::uint32_t latitude, const std::uint32_t longitude)
std::uint64_t bitInterleaving(const std::uint32_t longitude, const std::uint32_t latitude)
{
std::uint64_t result = 0;
for (std::int8_t index = 31; index >= 0; --index)
@@ -69,11 +69,13 @@ void transposeCoordinate(std::uint32_t *x)
}
} // anonymous ns
std::uint64_t hilbertCode(const FixedPointCoordinate coordinate)
std::uint64_t hilbertCode(const Coordinate coordinate)
{
unsigned location[2];
location[0] = coordinate.lat + static_cast<int>(90 * COORDINATE_PRECISION);
location[1] = coordinate.lon + static_cast<int>(180 * COORDINATE_PRECISION);
std::uint32_t location[2];
location[0] = static_cast<std::int32_t>(coordinate.lon) +
static_cast<std::int32_t>(180 * COORDINATE_PRECISION);
location[1] = static_cast<std::int32_t>(coordinate.lat) +
static_cast<std::int32_t>(90 * COORDINATE_PRECISION);
transposeCoordinate(location);
return bitInterleaving(location[0], location[1]);