Add viaroute suport for new API

This commit is contained in:
Patrick Niklaus
2016-01-28 16:28:44 +01:00
parent 26ffdf2dcb
commit 8b2b153465
87 changed files with 3352 additions and 2098 deletions
+7 -4
View File
@@ -35,7 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace osrm
{
constexpr const double COORDINATE_PRECISION = 1000000.0;
constexpr const double COORDINATE_PRECISION = 1e6;
namespace util
{
@@ -52,6 +52,7 @@ struct FixedPointCoordinate
FixedPointCoordinate(const T &coordinate)
: lat(coordinate.lat), lon(coordinate.lon)
{
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<decltype(lon), decltype(coordinate.lon)>::value,
@@ -59,11 +60,13 @@ struct FixedPointCoordinate
}
bool IsValid() const;
bool operator==(const FixedPointCoordinate &other) const;
friend std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate &coordinate);
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);
};
std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate &coordinate);
bool operator==(const FixedPointCoordinate lhs, const FixedPointCoordinate rhs);
std::ostream &operator<<(std::ostream &out, const FixedPointCoordinate coordinate);
}
}
+1 -1
View File
@@ -59,7 +59,7 @@ template <> Array make_array(const std::vector<bool> &vector)
}
// Easy acces to object hierachies
Value &get(Value &value) { return value; }
inline Value &get(Value &value) { return value; }
template <typename... Keys> Value &get(Value &value, const char *key, Keys... keys)
{
+85
View File
@@ -0,0 +1,85 @@
#ifndef UTIL_TILES_HPP
#define UTIL_TILES_HPP
#include <boost/assert.hpp>
#include <cmath>
#include <tuple>
// This is a port of the tilebelt algorithm https://github.com/mapbox/tilebelt
namespace osrm
{
namespace util
{
namespace tiles
{
struct Tile
{
unsigned x;
unsigned y;
unsigned z;
};
namespace detail
{
// optimized for 32bit integers
static constexpr unsigned MAX_ZOOM = 32;
// Returns 1-indexed 1..32 of MSB if value > 0 or 0 if value == 0
inline unsigned getMSBPosition(std::uint32_t value)
{
if (value == 0)
return 0;
std::uint8_t pos = 1;
while (value >>= 1)
pos++;
return pos;
}
inline unsigned getBBMaxZoom(const Tile top_left, const Tile bottom_left)
{
auto x_xor = top_left.x ^ bottom_left.x;
auto y_xor = top_left.y ^ bottom_left.y;
auto lon_msb = detail::getMSBPosition(x_xor);
auto lat_msb = detail::getMSBPosition(y_xor);
return MAX_ZOOM - std::max(lon_msb, lat_msb);
}
}
inline Tile pointToTile(const double lon, const double lat)
{
auto sin_lat = std::sin(lat * M_PI / 180.);
auto p2z = std::pow(2, detail::MAX_ZOOM);
unsigned x = p2z * (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)
{
const auto top_left = pointToTile(min_lon, min_lat);
const auto bottom_left = pointToTile(max_lon, max_lat);
BOOST_ASSERT(top_left.z == detail::MAX_ZOOM);
BOOST_ASSERT(bottom_left.z == detail::MAX_ZOOM);
const auto max_zoom = detail::getBBMaxZoom(top_left, bottom_left);
if (max_zoom == 0)
{
return Tile{0, 0, 0};
}
auto x = top_left.x >> (detail::MAX_ZOOM - max_zoom);
auto y = top_left.y >> (detail::MAX_ZOOM - max_zoom);
return Tile{x, y, max_zoom};
}
}
}
}
#endif