2015-05-31 08:05:53 -04:00
|
|
|
#include <boost/test/floating_point_comparison.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
2016-01-02 11:13:44 -05:00
|
|
|
#include "engine/polyline_compressor.hpp"
|
|
|
|
#include "util/coordinate_calculation.hpp"
|
2015-05-31 08:05:53 -04:00
|
|
|
|
|
|
|
#include <osrm/coordinate.hpp>
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
BOOST_AUTO_TEST_SUITE(polyline)
|
|
|
|
|
|
|
|
using namespace osrm;
|
|
|
|
using namespace osrm::engine;
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(decode)
|
2015-05-31 08:05:53 -04:00
|
|
|
{
|
|
|
|
// Polyline string for the 5 coordinates
|
2016-02-23 15:23:13 -05:00
|
|
|
const std::string polyline = "_c`|@_c`|@o}@_pRo}@_pRo}@_pRo}@_pR";
|
2016-01-28 10:28:44 -05:00
|
|
|
const auto coords = decodePolyline(polyline);
|
2015-05-31 08:05:53 -04:00
|
|
|
|
|
|
|
// Test coordinates; these would be the coordinates we give the loc parameter,
|
|
|
|
// e.g. loc=10.00,10.0&loc=10.01,10.1...
|
2016-06-24 01:01:37 -04:00
|
|
|
util::Coordinate coord1(util::FloatLongitude{10.0}, util::FloatLatitude{10.00});
|
|
|
|
util::Coordinate coord2(util::FloatLongitude{10.1}, util::FloatLatitude{10.01});
|
|
|
|
util::Coordinate coord3(util::FloatLongitude{10.2}, util::FloatLatitude{10.02});
|
|
|
|
util::Coordinate coord4(util::FloatLongitude{10.3}, util::FloatLatitude{10.03});
|
|
|
|
util::Coordinate coord5(util::FloatLongitude{10.4}, util::FloatLatitude{10.04});
|
2016-01-05 06:04:04 -05:00
|
|
|
|
2015-05-31 08:05:53 -04:00
|
|
|
// Put the test coordinates into the vector for comparison
|
2016-02-23 15:23:13 -05:00
|
|
|
std::vector<util::Coordinate> cmp_coords = {coord1, coord2, coord3, coord4, coord5};
|
2015-05-31 08:05:53 -04:00
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(cmp_coords.size(), coords.size());
|
|
|
|
|
2016-01-05 06:04:04 -05:00
|
|
|
for (unsigned i = 0; i < cmp_coords.size(); ++i)
|
2015-05-31 08:05:53 -04:00
|
|
|
{
|
2016-02-23 15:23:13 -05:00
|
|
|
BOOST_CHECK_CLOSE(static_cast<double>(util::toFloating(coords[i].lat)),
|
2016-05-27 15:05:04 -04:00
|
|
|
static_cast<double>(util::toFloating(cmp_coords[i].lat)),
|
|
|
|
0.0001);
|
2016-02-23 15:23:13 -05:00
|
|
|
BOOST_CHECK_CLOSE(static_cast<double>(util::toFloating(coords[i].lon)),
|
2016-05-27 15:05:04 -04:00
|
|
|
static_cast<double>(util::toFloating(cmp_coords[i].lon)),
|
|
|
|
0.0001);
|
2015-05-31 08:05:53 -04:00
|
|
|
}
|
|
|
|
}
|
2016-01-05 10:51:13 -05:00
|
|
|
|
2016-11-07 15:11:21 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(encode)
|
|
|
|
{
|
|
|
|
// Coordinates; these would be the coordinates we give the loc parameter,
|
|
|
|
// e.g. loc=10.00,10.0&loc=10.01,10.1...
|
|
|
|
util::Coordinate coord1(util::FloatLongitude{10.0}, util::FloatLatitude{10.00});
|
|
|
|
util::Coordinate coord2(util::FloatLongitude{10.1}, util::FloatLatitude{10.01});
|
|
|
|
util::Coordinate coord3(util::FloatLongitude{10.2}, util::FloatLatitude{10.02});
|
|
|
|
util::Coordinate coord4(util::FloatLongitude{10.3}, util::FloatLatitude{10.03});
|
|
|
|
util::Coordinate coord5(util::FloatLongitude{10.4}, util::FloatLatitude{10.04});
|
|
|
|
|
|
|
|
// Test polyline string for the 5 coordinates
|
|
|
|
const std::string polyline = "_c`|@_c`|@o}@_pRo}@_pRo}@_pRo}@_pR";
|
|
|
|
|
|
|
|
// Put the test coordinates into the vector for comparison
|
|
|
|
std::vector<util::Coordinate> cmp_coords = {coord1, coord2, coord3, coord4, coord5};
|
|
|
|
|
|
|
|
const auto encodedPolyline = encodePolyline<100000>(cmp_coords.begin(), cmp_coords.end());
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(encodedPolyline, polyline);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(encode6)
|
|
|
|
{
|
|
|
|
// Coordinates; these would be the coordinates we give the loc parameter,
|
|
|
|
// e.g. loc=10.00,10.0&loc=10.01,10.1...
|
|
|
|
util::Coordinate coord1(util::FloatLongitude{10.0}, util::FloatLatitude{10.00});
|
|
|
|
util::Coordinate coord2(util::FloatLongitude{10.1}, util::FloatLatitude{10.01});
|
|
|
|
util::Coordinate coord3(util::FloatLongitude{10.2}, util::FloatLatitude{10.02});
|
|
|
|
util::Coordinate coord4(util::FloatLongitude{10.3}, util::FloatLatitude{10.03});
|
|
|
|
util::Coordinate coord5(util::FloatLongitude{10.4}, util::FloatLatitude{10.04});
|
|
|
|
|
|
|
|
// Test polyline string for the 6 coordinates
|
|
|
|
const std::string polyline = "_gjaR_gjaR_pR_ibE_pR_ibE_pR_ibE_pR_ibE";
|
|
|
|
|
|
|
|
// Put the test coordinates into the vector for comparison
|
|
|
|
std::vector<util::Coordinate> cmp_coords = {coord1, coord2, coord3, coord4, coord5};
|
|
|
|
|
|
|
|
const auto encodedPolyline = encodePolyline<1000000>(cmp_coords.begin(), cmp_coords.end());
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(encodedPolyline, polyline);
|
|
|
|
}
|
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|