Consolidate math functions
This commit is contained in:
@@ -3,20 +3,34 @@
|
||||
|
||||
#include "util/coordinate.hpp"
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
namespace coordinate_calculation
|
||||
{
|
||||
|
||||
const constexpr long double RAD = 0.017453292519943295769236907684886;
|
||||
const constexpr long double DEGREE_TO_RAD = 0.017453292519943295769236907684886;
|
||||
const constexpr long double RAD_TO_DEGREE = 1. / DEGREE_TO_RAD;
|
||||
// earth radius varies between 6,356.750-6,378.135 km (3,949.901-3,963.189mi)
|
||||
// The IUGG value for the equatorial radius is 6378.137 km (3963.19 miles)
|
||||
const constexpr long double EARTH_RADIUS = 6372797.560856;
|
||||
// radius used by WGS84
|
||||
const constexpr double EARTH_RADIUS_WGS84 = 6378137.0;
|
||||
|
||||
namespace coordinate_calculation
|
||||
namespace detail
|
||||
{
|
||||
// earth circumference devided by 2
|
||||
const constexpr double MAXEXTENT = EARTH_RADIUS_WGS84 * boost::math::constants::pi<double>();
|
||||
// ^ math functions are not constexpr since they have side-effects (setting errno) :(
|
||||
const double MAX_LATITUDE = RAD_TO_DEGREE * (2.0 * std::atan(std::exp(180.0 * DEGREE_TO_RAD)) - boost::math::constants::half_pi<double>());
|
||||
const constexpr double MAX_LONGITUDE = 180.0;
|
||||
}
|
||||
|
||||
|
||||
//! Projects both coordinates and takes the euclidean distance of the projected points
|
||||
// Does not return meters!
|
||||
@@ -50,9 +64,6 @@ double perpendicularDistanceFromProjectedCoordinate(
|
||||
Coordinate &nearest_location,
|
||||
double &ratio);
|
||||
|
||||
double degToRad(const double degree);
|
||||
double radToDeg(const double radian);
|
||||
|
||||
double bearing(const Coordinate first_coordinate, const Coordinate second_coordinate);
|
||||
|
||||
// Get angle of line segment (A,C)->(C,B)
|
||||
@@ -64,8 +75,15 @@ Coordinate interpolateLinear(double factor, const Coordinate from, const Coordin
|
||||
|
||||
namespace mercator
|
||||
{
|
||||
// This is the global default tile size for all Mapbox Vector Tiles
|
||||
const constexpr double TILE_SIZE = 256.0;
|
||||
// Converts projected mercator degrees to PX
|
||||
const constexpr double DEGREE_TO_PX = detail::MAXEXTENT / 180.0;
|
||||
|
||||
FloatLatitude yToLat(const double value);
|
||||
double latToY(const FloatLatitude latitude);
|
||||
void xyzToMercator(const int x, const int y, const int z, double &minx, double &miny, double &maxx, double &maxy);
|
||||
void xyzToWSG84(const int x, const int y, const int z, double &minx, double &miny, double &maxx, double &maxy);
|
||||
} // ns mercator
|
||||
} // ns coordinate_calculation
|
||||
} // ns util
|
||||
|
||||
Reference in New Issue
Block a user