2015-01-16 11:23:29 -05:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "util/coordinate_calculation.hpp"
|
2015-01-20 10:24:49 -05:00
|
|
|
|
2015-01-15 18:49:43 -05:00
|
|
|
#include <osrm/coordinate.hpp>
|
|
|
|
|
2015-01-16 11:23:29 -05:00
|
|
|
#include <cmath>
|
2015-01-15 18:49:43 -05:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
using namespace osrm;
|
|
|
|
using namespace osrm::util;
|
|
|
|
|
2015-01-15 18:49:43 -05:00
|
|
|
// Regression test for bug captured in #1347
|
|
|
|
BOOST_AUTO_TEST_CASE(regression_test_1347)
|
|
|
|
{
|
2016-02-23 15:23:13 -05:00
|
|
|
Coordinate u(FloatLongitude(-100), FloatLatitude(10));
|
|
|
|
Coordinate v(FloatLongitude(-100.002), FloatLatitude(10.001));
|
|
|
|
Coordinate q(FloatLongitude(-100.001), FloatLatitude(10.002));
|
2015-01-15 18:49:43 -05:00
|
|
|
|
2016-01-04 07:30:03 -05:00
|
|
|
double d1 = coordinate_calculation::perpendicularDistance(u, v, q);
|
2015-01-15 18:49:43 -05:00
|
|
|
|
2015-12-26 14:12:10 -05:00
|
|
|
double ratio;
|
2016-02-23 15:23:13 -05:00
|
|
|
Coordinate nearest_location;
|
2016-01-04 07:30:03 -05:00
|
|
|
double d2 = coordinate_calculation::perpendicularDistance(u, v, q, nearest_location, ratio);
|
2015-01-15 18:49:43 -05:00
|
|
|
|
2015-12-26 14:12:10 -05:00
|
|
|
BOOST_CHECK_LE(std::abs(d1 - d2), 0.01);
|
2015-01-15 18:49:43 -05:00
|
|
|
}
|
2016-03-16 18:39:59 -04:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(lon_to_pixel)
|
|
|
|
{
|
|
|
|
using namespace coordinate_calculation;
|
|
|
|
BOOST_CHECK_CLOSE(7.416042 * mercator::DEGREE_TO_PX, 825550.019142, 0.1);
|
|
|
|
BOOST_CHECK_CLOSE(7.415892 * mercator::DEGREE_TO_PX, 825533.321218, 0.1);
|
|
|
|
BOOST_CHECK_CLOSE(7.416016 * mercator::DEGREE_TO_PX, 825547.124835, 0.1);
|
|
|
|
BOOST_CHECK_CLOSE(7.41577 * mercator::DEGREE_TO_PX, 825519.74024, 0.1);
|
|
|
|
BOOST_CHECK_CLOSE(7.415808 * mercator::DEGREE_TO_PX, 825523.970381, 0.1);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(lat_to_pixel)
|
|
|
|
{
|
|
|
|
using namespace coordinate_calculation;
|
|
|
|
BOOST_CHECK_CLOSE(mercator::latToY(util::FloatLatitude(43.733947)) * mercator::DEGREE_TO_PX,
|
|
|
|
5424361.75863, 0.1);
|
|
|
|
BOOST_CHECK_CLOSE(mercator::latToY(util::FloatLatitude(43.733799)) * mercator::DEGREE_TO_PX,
|
|
|
|
5424338.95731, 0.1);
|
|
|
|
BOOST_CHECK_CLOSE(mercator::latToY(util::FloatLatitude(43.733922)) * mercator::DEGREE_TO_PX,
|
|
|
|
5424357.90705, 0.1);
|
|
|
|
BOOST_CHECK_CLOSE(mercator::latToY(util::FloatLatitude(43.733697)) * mercator::DEGREE_TO_PX,
|
|
|
|
5424323.24293, 0.1);
|
|
|
|
BOOST_CHECK_CLOSE(mercator::latToY(util::FloatLatitude(43.733729)) * mercator::DEGREE_TO_PX,
|
|
|
|
5424328.17293, 0.1);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(xyz_to_wgs84)
|
|
|
|
{
|
|
|
|
using namespace coordinate_calculation;
|
|
|
|
|
|
|
|
double minx_1;
|
|
|
|
double miny_1;
|
|
|
|
double maxx_1;
|
|
|
|
double maxy_1;
|
|
|
|
mercator::xyzToWSG84(2, 2, 1, minx_1, miny_1, maxx_1, maxy_1);
|
|
|
|
BOOST_CHECK_CLOSE(minx_1, 180, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(miny_1, -89.786, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(maxx_1, 360, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(maxy_1, -85.0511, 0.0001);
|
|
|
|
|
|
|
|
double minx_2;
|
|
|
|
double miny_2;
|
|
|
|
double maxx_2;
|
|
|
|
double maxy_2;
|
|
|
|
mercator::xyzToWSG84(100, 0, 13, minx_2, miny_2, maxx_2, maxy_2);
|
|
|
|
BOOST_CHECK_CLOSE(minx_2, -175.6054, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(miny_2, 85.0473, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(maxx_2, -175.5615, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(maxy_2, 85.0511, 0.0001);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(xyz_to_mercator)
|
|
|
|
{
|
|
|
|
using namespace coordinate_calculation;
|
|
|
|
|
|
|
|
double minx;
|
|
|
|
double miny;
|
|
|
|
double maxx;
|
|
|
|
double maxy;
|
|
|
|
mercator::xyzToMercator(100, 0, 13, minx, miny, maxx, maxy);
|
|
|
|
|
|
|
|
BOOST_CHECK_CLOSE(minx, -19548311.361764118075, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(miny, 20032616.372979003936, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(maxx, -19543419.391953866929, 0.0001);
|
|
|
|
BOOST_CHECK_CLOSE(maxy, 20037508.342789277434, 0.0001);
|
|
|
|
}
|