First round of lat,lng -> lng,lat switcheroo
This commit is contained in:
+45
-17
@@ -28,9 +28,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#ifndef COORDINATE_HPP_
|
||||
#define COORDINATE_HPP_
|
||||
|
||||
#include "util/strong_typedef.hpp"
|
||||
|
||||
#include <iosfwd> //for std::ostream
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
@@ -40,35 +43,60 @@ constexpr const double COORDINATE_PRECISION = 1e6;
|
||||
namespace util
|
||||
{
|
||||
|
||||
struct FixedPointCoordinate
|
||||
OSRM_STRONG_TYPEDEF(int32_t, FixedLatitude)
|
||||
OSRM_STRONG_TYPEDEF(int32_t, FixedLongitude)
|
||||
OSRM_STRONG_TYPEDEF(double, FloatLatitude)
|
||||
OSRM_STRONG_TYPEDEF(double, FloatLongitude)
|
||||
|
||||
inline FixedLatitude toFixed(const FloatLatitude floating)
|
||||
{
|
||||
int lat;
|
||||
int lon;
|
||||
return FixedLatitude(static_cast<double>(floating) * COORDINATE_PRECISION);
|
||||
}
|
||||
|
||||
FixedPointCoordinate();
|
||||
FixedPointCoordinate(int lat, int lon);
|
||||
inline FixedLongitude toFixed(const FloatLongitude floating)
|
||||
{
|
||||
return FixedLongitude(static_cast<double>(floating) * COORDINATE_PRECISION);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
FixedPointCoordinate(const T &coordinate)
|
||||
: lat(coordinate.lat), lon(coordinate.lon)
|
||||
inline FloatLatitude toFloating(const FixedLatitude fixed)
|
||||
{
|
||||
return FloatLatitude(static_cast<int32_t>(fixed) / COORDINATE_PRECISION);
|
||||
}
|
||||
|
||||
inline FloatLongitude toFloating(const FixedLongitude fixed)
|
||||
{
|
||||
return FloatLongitude(static_cast<int32_t>(fixed) / COORDINATE_PRECISION);
|
||||
}
|
||||
|
||||
// Coordinate encoded as longitude, latitude
|
||||
struct Coordinate
|
||||
{
|
||||
FixedLongitude lon;
|
||||
FixedLatitude lat;
|
||||
|
||||
Coordinate();
|
||||
Coordinate(const FixedLongitude lon_, const FixedLatitude lat_);
|
||||
Coordinate(const FloatLongitude lon_, const FloatLatitude lat_);
|
||||
|
||||
template <class T> Coordinate(const T &coordinate) : lon(coordinate.lon), lat(coordinate.lat)
|
||||
{
|
||||
static_assert(!std::is_same<T, FixedPointCoordinate>::value, "This constructor should not be used for FixedPointCoordinates");
|
||||
static_assert(std::is_same<decltype(lat), decltype(coordinate.lat)>::value,
|
||||
"coordinate types incompatible");
|
||||
static_assert(!std::is_same<T, Coordinate>::value,
|
||||
"This constructor should not be used for Coordinates");
|
||||
static_assert(std::is_same<decltype(lon), decltype(coordinate.lon)>::value,
|
||||
"coordinate types incompatible");
|
||||
static_assert(std::is_same<decltype(lat), decltype(coordinate.lat)>::value,
|
||||
"coordinate types incompatible");
|
||||
}
|
||||
|
||||
bool IsValid() const;
|
||||
friend bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs);
|
||||
friend bool operator!=(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs);
|
||||
friend std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate);
|
||||
friend bool operator==(const Coordinate lhs, const Coordinate rhs);
|
||||
friend bool operator!=(const Coordinate lhs, const Coordinate rhs);
|
||||
friend std::ostream &operator<<(std::ostream &out, const Coordinate coordinate);
|
||||
};
|
||||
|
||||
bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs);
|
||||
std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate);
|
||||
bool operator==(const Coordinate lhs, const Coordinate rhs);
|
||||
std::ostream &operator<<(std::ostream &out, const Coordinate coordinate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* COORDINATE_HPP_ */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef COORDINATE_CALCULATION
|
||||
#define COORDINATE_CALCULATION
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -18,55 +18,47 @@ const constexpr long double EARTH_RADIUS = 6372797.560856;
|
||||
|
||||
namespace coordinate_calculation
|
||||
{
|
||||
double haversineDistance(const int lat1, const int lon1, const int lat2, const int lon2);
|
||||
|
||||
double haversineDistance(const FixedPointCoordinate first_coordinate,
|
||||
const FixedPointCoordinate second_coordinate);
|
||||
double haversineDistance(const Coordinate first_coordinate, const Coordinate second_coordinate);
|
||||
|
||||
double greatCircleDistance(const FixedPointCoordinate first_coordinate,
|
||||
const FixedPointCoordinate second_coordinate);
|
||||
double greatCircleDistance(const Coordinate first_coordinate, const Coordinate second_coordinate);
|
||||
|
||||
double greatCircleDistance(const int lat1, const int lon1, const int lat2, const int lon2);
|
||||
double perpendicularDistance(const Coordinate segment_source,
|
||||
const Coordinate segment_target,
|
||||
const Coordinate query_location);
|
||||
|
||||
double perpendicularDistance(const FixedPointCoordinate segment_source,
|
||||
const FixedPointCoordinate segment_target,
|
||||
const FixedPointCoordinate query_location);
|
||||
|
||||
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);
|
||||
|
||||
double
|
||||
perpendicularDistanceFromProjectedCoordinate(const FixedPointCoordinate segment_source,
|
||||
const FixedPointCoordinate segment_target,
|
||||
const FixedPointCoordinate query_location,
|
||||
const std::pair<double, double> projected_coordinate);
|
||||
double perpendicularDistanceFromProjectedCoordinate(
|
||||
const Coordinate segment_source,
|
||||
const Coordinate segment_target,
|
||||
const Coordinate query_location,
|
||||
const std::pair<double, double> projected_xy_coordinate);
|
||||
|
||||
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);
|
||||
|
||||
double degToRad(const double degree);
|
||||
double radToDeg(const double radian);
|
||||
|
||||
double bearing(const FixedPointCoordinate first_coordinate,
|
||||
const FixedPointCoordinate second_coordinate);
|
||||
double bearing(const Coordinate first_coordinate, const Coordinate second_coordinate);
|
||||
|
||||
// Get angle of line segment (A,C)->(C,B)
|
||||
double computeAngle(const FixedPointCoordinate first,
|
||||
const FixedPointCoordinate second,
|
||||
const FixedPointCoordinate third);
|
||||
double computeAngle(const Coordinate first, const Coordinate second, const Coordinate third);
|
||||
|
||||
namespace mercator
|
||||
{
|
||||
double yToLat(const double value);
|
||||
double latToY(const double latitude);
|
||||
FloatLatitude yToLat(const double value);
|
||||
double latToY(const FloatLatitude latitude);
|
||||
} // ns mercator
|
||||
} // ns coordinate_calculation
|
||||
} // ns util
|
||||
|
||||
@@ -86,7 +86,7 @@ NodeID loadNodesFromFile(std::istream &input_stream,
|
||||
{
|
||||
input_stream.read(reinterpret_cast<char *>(¤t_node),
|
||||
sizeof(extractor::ExternalMemoryNode));
|
||||
node_array.emplace_back(current_node.lat, current_node.lon, current_node.node_id);
|
||||
node_array.emplace_back(current_node.lon, current_node.lat, current_node.node_id);
|
||||
if (current_node.barrier)
|
||||
{
|
||||
barrier_node_list.emplace_back(i);
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace util
|
||||
{
|
||||
|
||||
// Computes a 64 bit value that corresponds to the hilbert space filling curve
|
||||
std::uint64_t hilbertCode(const FixedPointCoordinate coordinate);
|
||||
std::uint64_t hilbertCode(const Coordinate coordinate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ struct MatchingDebugInfo
|
||||
{
|
||||
json::Object state;
|
||||
state.values["transitions"] = json::Array();
|
||||
state.values["coordinate"] =
|
||||
json::make_array(elem_s.phantom_node.location.lat / COORDINATE_PRECISION,
|
||||
elem_s.phantom_node.location.lon / COORDINATE_PRECISION);
|
||||
state.values["coordinate"] = json::make_array(
|
||||
static_cast<double>(toFloating(elem_s.phantom_node.location.lat)),
|
||||
static_cast<double>(toFloating(elem_s.phantom_node.location.lon)));
|
||||
state.values["viterbi"] =
|
||||
json::clamp_float(engine::map_matching::IMPOSSIBLE_LOG_PROB);
|
||||
state.values["pruned"] = 0u;
|
||||
@@ -124,8 +124,10 @@ struct MatchingDebugInfo
|
||||
json::Array a;
|
||||
for (const bool v : breakage)
|
||||
{
|
||||
if (v) a.values.emplace_back(json::True());
|
||||
else a.values.emplace_back(json::False());
|
||||
if (v)
|
||||
a.values.emplace_back(json::True());
|
||||
else
|
||||
a.values.emplace_back(json::False());
|
||||
}
|
||||
|
||||
json::get(*object, "breakage") = std::move(a);
|
||||
|
||||
+44
-35
@@ -29,16 +29,25 @@ struct RectangleInt2D
|
||||
{
|
||||
}
|
||||
|
||||
RectangleInt2D(std::int32_t min_lon_,
|
||||
std::int32_t max_lon_,
|
||||
std::int32_t min_lat_,
|
||||
std::int32_t max_lat_)
|
||||
RectangleInt2D(FixedLongitude min_lon_,
|
||||
FixedLongitude max_lon_,
|
||||
FixedLatitude min_lat_,
|
||||
FixedLatitude max_lat_)
|
||||
: min_lon(min_lon_), max_lon(max_lon_), min_lat(min_lat_), max_lat(max_lat_)
|
||||
{
|
||||
}
|
||||
|
||||
std::int32_t min_lon, max_lon;
|
||||
std::int32_t min_lat, max_lat;
|
||||
RectangleInt2D(FloatLongitude min_lon_,
|
||||
FloatLongitude max_lon_,
|
||||
FloatLatitude min_lat_,
|
||||
FloatLatitude max_lat_)
|
||||
: min_lon(toFixed(min_lon_)), max_lon(toFixed(max_lon_)), min_lat(toFixed(min_lat_)),
|
||||
max_lat(toFixed(max_lat_))
|
||||
{
|
||||
}
|
||||
|
||||
FixedLongitude min_lon, max_lon;
|
||||
FixedLatitude min_lat, max_lat;
|
||||
|
||||
void MergeBoundingBoxes(const RectangleInt2D &other)
|
||||
{
|
||||
@@ -46,19 +55,19 @@ struct RectangleInt2D
|
||||
max_lon = std::max(max_lon, other.max_lon);
|
||||
min_lat = std::min(min_lat, other.min_lat);
|
||||
max_lat = std::max(max_lat, other.max_lat);
|
||||
BOOST_ASSERT(min_lat != std::numeric_limits<std::int32_t>::min());
|
||||
BOOST_ASSERT(min_lon != std::numeric_limits<std::int32_t>::min());
|
||||
BOOST_ASSERT(max_lat != std::numeric_limits<std::int32_t>::min());
|
||||
BOOST_ASSERT(max_lon != std::numeric_limits<std::int32_t>::min());
|
||||
BOOST_ASSERT(min_lon != FixedLongitude(std::numeric_limits<std::int32_t>::min()));
|
||||
BOOST_ASSERT(min_lat != FixedLatitude(std::numeric_limits<std::int32_t>::min()));
|
||||
BOOST_ASSERT(max_lon != FixedLongitude(std::numeric_limits<std::int32_t>::min()));
|
||||
BOOST_ASSERT(max_lat != FixedLatitude(std::numeric_limits<std::int32_t>::min()));
|
||||
}
|
||||
|
||||
FixedPointCoordinate Centroid() const
|
||||
Coordinate Centroid() const
|
||||
{
|
||||
FixedPointCoordinate centroid;
|
||||
Coordinate centroid;
|
||||
// The coordinates of the midpoints are given by:
|
||||
// x = (x1 + x2) /2 and y = (y1 + y2) /2.
|
||||
centroid.lon = (min_lon + max_lon) / 2;
|
||||
centroid.lat = (min_lat + max_lat) / 2;
|
||||
centroid.lon = (min_lon + max_lon) / FixedLongitude(2);
|
||||
centroid.lat = (min_lat + max_lat) / FixedLatitude(2);
|
||||
return centroid;
|
||||
}
|
||||
|
||||
@@ -70,7 +79,7 @@ struct RectangleInt2D
|
||||
min_lat > other.max_lat);
|
||||
}
|
||||
|
||||
double GetMinDist(const FixedPointCoordinate location) const
|
||||
double GetMinDist(const Coordinate location) const
|
||||
{
|
||||
const bool is_contained = Contains(location);
|
||||
if (is_contained)
|
||||
@@ -108,35 +117,35 @@ struct RectangleInt2D
|
||||
{
|
||||
case NORTH:
|
||||
min_dist = coordinate_calculation::greatCircleDistance(
|
||||
location, FixedPointCoordinate(max_lat, location.lon));
|
||||
location, Coordinate(location.lon, max_lat));
|
||||
break;
|
||||
case SOUTH:
|
||||
min_dist = coordinate_calculation::greatCircleDistance(
|
||||
location, FixedPointCoordinate(min_lat, location.lon));
|
||||
location, Coordinate(location.lon, min_lat));
|
||||
break;
|
||||
case WEST:
|
||||
min_dist = coordinate_calculation::greatCircleDistance(
|
||||
location, FixedPointCoordinate(location.lat, min_lon));
|
||||
location, Coordinate(min_lon, location.lat));
|
||||
break;
|
||||
case EAST:
|
||||
min_dist = coordinate_calculation::greatCircleDistance(
|
||||
location, FixedPointCoordinate(location.lat, max_lon));
|
||||
location, Coordinate(max_lon, location.lat));
|
||||
break;
|
||||
case NORTH_EAST:
|
||||
min_dist = coordinate_calculation::greatCircleDistance(
|
||||
location, FixedPointCoordinate(max_lat, max_lon));
|
||||
min_dist =
|
||||
coordinate_calculation::greatCircleDistance(location, Coordinate(max_lon, max_lat));
|
||||
break;
|
||||
case NORTH_WEST:
|
||||
min_dist = coordinate_calculation::greatCircleDistance(
|
||||
location, FixedPointCoordinate(max_lat, min_lon));
|
||||
min_dist =
|
||||
coordinate_calculation::greatCircleDistance(location, Coordinate(min_lon, max_lat));
|
||||
break;
|
||||
case SOUTH_EAST:
|
||||
min_dist = coordinate_calculation::greatCircleDistance(
|
||||
location, FixedPointCoordinate(min_lat, max_lon));
|
||||
min_dist =
|
||||
coordinate_calculation::greatCircleDistance(location, Coordinate(max_lon, min_lat));
|
||||
break;
|
||||
case SOUTH_WEST:
|
||||
min_dist = coordinate_calculation::greatCircleDistance(
|
||||
location, FixedPointCoordinate(min_lat, min_lon));
|
||||
min_dist =
|
||||
coordinate_calculation::greatCircleDistance(location, Coordinate(min_lon, min_lat));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -147,14 +156,14 @@ struct RectangleInt2D
|
||||
return min_dist;
|
||||
}
|
||||
|
||||
double GetMinMaxDist(const FixedPointCoordinate location) const
|
||||
double GetMinMaxDist(const Coordinate location) const
|
||||
{
|
||||
double min_max_dist = std::numeric_limits<double>::max();
|
||||
// Get minmax distance to each of the four sides
|
||||
const FixedPointCoordinate upper_left(max_lat, min_lon);
|
||||
const FixedPointCoordinate upper_right(max_lat, max_lon);
|
||||
const FixedPointCoordinate lower_right(min_lat, max_lon);
|
||||
const FixedPointCoordinate lower_left(min_lat, min_lon);
|
||||
const Coordinate upper_left(min_lon, max_lat);
|
||||
const Coordinate upper_right(max_lon, max_lat);
|
||||
const Coordinate lower_right(max_lon, min_lat);
|
||||
const Coordinate lower_left(min_lon, min_lat);
|
||||
|
||||
min_max_dist =
|
||||
std::min(min_max_dist,
|
||||
@@ -178,11 +187,11 @@ struct RectangleInt2D
|
||||
return min_max_dist;
|
||||
}
|
||||
|
||||
bool Contains(const FixedPointCoordinate location) const
|
||||
bool Contains(const Coordinate location) const
|
||||
{
|
||||
const bool lats_contained = (location.lat >= min_lat) && (location.lat <= max_lat);
|
||||
const bool lons_contained = (location.lon >= min_lon) && (location.lon <= max_lon);
|
||||
return lats_contained && lons_contained;
|
||||
const bool lats_contained = (location.lat >= min_lat) && (location.lat <= max_lat);
|
||||
return lons_contained && lats_contained;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace util
|
||||
|
||||
// Static RTree for serving nearest neighbour queries
|
||||
template <class EdgeDataT,
|
||||
class CoordinateListT = std::vector<FixedPointCoordinate>,
|
||||
class CoordinateListT = std::vector<Coordinate>,
|
||||
bool UseSharedMemory = false,
|
||||
std::uint32_t BRANCHING_FACTOR = 64,
|
||||
std::uint32_t LEAF_NODE_SIZE = 1024>
|
||||
@@ -122,8 +122,8 @@ class StaticRTree
|
||||
// generate auxiliary vector of hilbert-values
|
||||
tbb::parallel_for(
|
||||
tbb::blocked_range<uint64_t>(0, m_element_count),
|
||||
[&input_data_vector, &input_wrapper_vector, &coordinate_list](
|
||||
const tbb::blocked_range<uint64_t> &range)
|
||||
[&input_data_vector, &input_wrapper_vector,
|
||||
&coordinate_list](const tbb::blocked_range<uint64_t> &range)
|
||||
{
|
||||
for (uint64_t element_counter = range.begin(), end = range.end();
|
||||
element_counter != end; ++element_counter)
|
||||
@@ -137,14 +137,14 @@ class StaticRTree
|
||||
BOOST_ASSERT(current_element.u < coordinate_list.size());
|
||||
BOOST_ASSERT(current_element.v < coordinate_list.size());
|
||||
|
||||
FixedPointCoordinate current_centroid = EdgeDataT::Centroid(
|
||||
FixedPointCoordinate(coordinate_list[current_element.u].lat,
|
||||
coordinate_list[current_element.u].lon),
|
||||
FixedPointCoordinate(coordinate_list[current_element.v].lat,
|
||||
coordinate_list[current_element.v].lon));
|
||||
current_centroid.lat =
|
||||
COORDINATE_PRECISION * coordinate_calculation::mercator::latToY(
|
||||
current_centroid.lat / COORDINATE_PRECISION);
|
||||
Coordinate current_centroid =
|
||||
EdgeDataT::Centroid(Coordinate(coordinate_list[current_element.u].lon,
|
||||
coordinate_list[current_element.u].lat),
|
||||
Coordinate(coordinate_list[current_element.v].lon,
|
||||
coordinate_list[current_element.v].lat));
|
||||
current_centroid.lat = FixedLatitude(
|
||||
COORDINATE_PRECISION *
|
||||
coordinate_calculation::mercator::latToY(toFloating(current_centroid.lat)));
|
||||
|
||||
current_wrapper.m_hilbert_value = hilbertCode(current_centroid);
|
||||
}
|
||||
@@ -377,8 +377,7 @@ class StaticRTree
|
||||
}
|
||||
|
||||
// Override filter and terminator for the desired behaviour.
|
||||
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate,
|
||||
const std::size_t max_results)
|
||||
std::vector<EdgeDataT> Nearest(const Coordinate input_coordinate, const std::size_t max_results)
|
||||
{
|
||||
return Nearest(input_coordinate,
|
||||
[](const EdgeDataT &)
|
||||
@@ -393,14 +392,13 @@ class StaticRTree
|
||||
|
||||
// Override filter and terminator for the desired behaviour.
|
||||
template <typename FilterT, typename TerminationT>
|
||||
std::vector<EdgeDataT> Nearest(const FixedPointCoordinate input_coordinate,
|
||||
const FilterT filter,
|
||||
const TerminationT terminate)
|
||||
std::vector<EdgeDataT>
|
||||
Nearest(const Coordinate input_coordinate, const FilterT filter, const TerminationT terminate)
|
||||
{
|
||||
std::vector<EdgeDataT> results;
|
||||
std::pair<double, double> projected_coordinate = {
|
||||
coordinate_calculation::mercator::latToY(input_coordinate.lat / COORDINATE_PRECISION),
|
||||
input_coordinate.lon / COORDINATE_PRECISION};
|
||||
static_cast<double>(toFloating(input_coordinate.lon)),
|
||||
coordinate_calculation::mercator::latToY(toFloating(input_coordinate.lat))};
|
||||
|
||||
// initialize queue with root element
|
||||
std::priority_queue<QueryCandidate> traversal_queue;
|
||||
@@ -462,7 +460,7 @@ class StaticRTree
|
||||
private:
|
||||
template <typename QueueT>
|
||||
void ExploreLeafNode(const std::uint32_t leaf_id,
|
||||
const FixedPointCoordinate input_coordinate,
|
||||
const Coordinate input_coordinate,
|
||||
const std::pair<double, double> &projected_coordinate,
|
||||
QueueT &traversal_queue)
|
||||
{
|
||||
@@ -487,7 +485,7 @@ class StaticRTree
|
||||
|
||||
template <class QueueT>
|
||||
void ExploreTreeNode(const TreeNode &parent,
|
||||
const FixedPointCoordinate input_coordinate,
|
||||
const Coordinate input_coordinate,
|
||||
QueueT &traversal_queue)
|
||||
{
|
||||
for (std::uint32_t i = 0; i < parent.child_count; ++i)
|
||||
@@ -542,10 +540,10 @@ class StaticRTree
|
||||
std::max(rectangle.max_lat, std::max(coordinate_list[objects[i].u].lat,
|
||||
coordinate_list[objects[i].v].lat));
|
||||
}
|
||||
BOOST_ASSERT(rectangle.min_lat != std::numeric_limits<int>::min());
|
||||
BOOST_ASSERT(rectangle.min_lon != std::numeric_limits<int>::min());
|
||||
BOOST_ASSERT(rectangle.max_lat != std::numeric_limits<int>::min());
|
||||
BOOST_ASSERT(rectangle.max_lon != std::numeric_limits<int>::min());
|
||||
BOOST_ASSERT(rectangle.min_lon != FixedLongitude(std::numeric_limits<int>::min()));
|
||||
BOOST_ASSERT(rectangle.min_lat != FixedLatitude(std::numeric_limits<int>::min()));
|
||||
BOOST_ASSERT(rectangle.max_lon != FixedLongitude(std::numeric_limits<int>::min()));
|
||||
BOOST_ASSERT(rectangle.max_lat != FixedLatitude(std::numeric_limits<int>::min()));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,21 +18,30 @@ namespace osrm
|
||||
{ \
|
||||
static_assert(std::is_arithmetic<From>(), ""); \
|
||||
From x; \
|
||||
friend std::ostream& operator<<(std::ostream& stream, const To& inst); \
|
||||
friend std::ostream &operator<<(std::ostream &stream, const To &inst); \
|
||||
\
|
||||
public: \
|
||||
To() = default; \
|
||||
explicit To(const From x_) : x(x_) {} \
|
||||
explicit operator From &() { return x; } \
|
||||
explicit operator const From &() const { return x; } \
|
||||
bool operator<(const To &z_) const { return x < static_cast<const From>(z_); } \
|
||||
bool operator>(const To &z_) const { return x > static_cast<const From>(z_); } \
|
||||
bool operator<=(const To &z_) const { return x <= static_cast<const From>(z_); } \
|
||||
bool operator>=(const To &z_) const { return x >= static_cast<const From>(z_); } \
|
||||
bool operator==(const To &z_) const { return x == static_cast<const From>(z_); } \
|
||||
bool operator!=(const To &z_) const { return x != static_cast<const From>(z_); } \
|
||||
explicit operator From() const { return x; } \
|
||||
To operator+(const To rhs_) const { return To(x + static_cast<const From>(rhs_)); } \
|
||||
To operator-(const To rhs_) const { return To(x - static_cast<const From>(rhs_)); } \
|
||||
To operator*(const To rhs_) const { return To(x * static_cast<const From>(rhs_)); } \
|
||||
To operator/(const To rhs_) const { return To(x / static_cast<const From>(rhs_)); } \
|
||||
bool operator<(const To z_) const { return x < static_cast<const From>(z_); } \
|
||||
bool operator>(const To z_) const { return x > static_cast<const From>(z_); } \
|
||||
bool operator<=(const To z_) const { return x <= static_cast<const From>(z_); } \
|
||||
bool operator>=(const To z_) const { return x >= static_cast<const From>(z_); } \
|
||||
bool operator==(const To z_) const { return x == static_cast<const From>(z_); } \
|
||||
bool operator!=(const To z_) const { return x != static_cast<const From>(z_); } \
|
||||
}; \
|
||||
inline From To##_to_##From(To to) { return static_cast<From>(to); } \
|
||||
inline std::ostream &operator<<(std::ostream &stream, const To &inst) \
|
||||
{ \
|
||||
return stream << #To << '(' << inst.x << ')'; \
|
||||
}
|
||||
|
||||
#define OSRM_STRONG_TYPEDEF_HASHABLE(From, To) \
|
||||
namespace std \
|
||||
{ \
|
||||
template <> struct hash<To> \
|
||||
@@ -42,9 +51,6 @@ namespace osrm
|
||||
return std::hash<From>()(static_cast<const From>(k)); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
inline std::ostream& operator<<(std::ostream& stream, const To& inst) { \
|
||||
return stream << #To << '(' << inst.x << ')'; \
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef UTIL_TILES_HPP
|
||||
#define UTIL_TILES_HPP
|
||||
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cmath>
|
||||
@@ -46,20 +48,20 @@ inline unsigned getBBMaxZoom(const Tile top_left, const Tile bottom_left)
|
||||
}
|
||||
}
|
||||
|
||||
inline Tile pointToTile(const double lon, const double lat)
|
||||
inline Tile pointToTile(const FloatLongitude lon, const FloatLatitude lat)
|
||||
{
|
||||
auto sin_lat = std::sin(lat * M_PI / 180.);
|
||||
auto sin_lat = std::sin(static_cast<double>(lat) * M_PI / 180.);
|
||||
auto p2z = std::pow(2, detail::MAX_ZOOM);
|
||||
unsigned x = p2z * (lon / 360. + 0.5);
|
||||
unsigned x = p2z * (static_cast<double>(lon) / 360. + 0.5);
|
||||
unsigned y = p2z * (0.5 - 0.25 * std::log((1 + sin_lat) / (1 - sin_lat)) / M_PI);
|
||||
|
||||
return Tile{x, y, detail::MAX_ZOOM};
|
||||
}
|
||||
|
||||
inline Tile getBBMaxZoomTile(const double min_lon,
|
||||
const double min_lat,
|
||||
const double max_lon,
|
||||
const double max_lat)
|
||||
inline Tile getBBMaxZoomTile(const FloatLongitude min_lon,
|
||||
const FloatLatitude min_lat,
|
||||
const FloatLongitude max_lon,
|
||||
const FloatLatitude max_lat)
|
||||
{
|
||||
const auto top_left = pointToTile(min_lon, min_lat);
|
||||
const auto bottom_left = pointToTile(max_lon, max_lat);
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
|
||||
// OpenStreetMap node ids are higher than 2^32
|
||||
OSRM_STRONG_TYPEDEF(uint64_t, OSMNodeID)
|
||||
OSRM_STRONG_TYPEDEF_HASHABLE(uint64_t, OSMNodeID)
|
||||
|
||||
OSRM_STRONG_TYPEDEF(uint32_t, OSMWayID)
|
||||
OSRM_STRONG_TYPEDEF_HASHABLE(uint32_t, OSMWayID)
|
||||
|
||||
static const OSMNodeID SPECIAL_OSM_NODEID = OSMNodeID(std::numeric_limits<std::uint64_t>::max());
|
||||
static const OSMWayID SPECIAL_OSM_WAYID = OSMWayID(std::numeric_limits<std::uint32_t>::max());
|
||||
|
||||
Reference in New Issue
Block a user