2016-01-02 11:13:44 -05:00
|
|
|
#include "engine/douglas_peucker.hpp"
|
2016-04-08 18:39:20 -04:00
|
|
|
#include "util/coordinate_calculation.hpp"
|
2018-02-02 10:50:33 -05:00
|
|
|
#include "util/debug.hpp"
|
2014-10-27 19:16:03 -04:00
|
|
|
|
2016-05-27 15:05:04 -04:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2014-10-27 19:16:03 -04:00
|
|
|
|
2014-11-24 11:57:01 -05:00
|
|
|
#include <osrm/coordinate.hpp>
|
|
|
|
|
2015-09-03 05:38:35 -04:00
|
|
|
#include <vector>
|
2014-10-27 19:16:03 -04:00
|
|
|
|
2016-01-08 06:55:37 -05:00
|
|
|
BOOST_AUTO_TEST_SUITE(douglas_peucker_simplification)
|
2014-10-27 19:16:03 -04:00
|
|
|
|
2016-01-05 10:51:13 -05:00
|
|
|
using namespace osrm;
|
|
|
|
using namespace osrm::engine;
|
|
|
|
|
2016-04-08 18:39:20 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(calibrate_thresholds)
|
|
|
|
{
|
|
|
|
auto thresholds = detail::generateThreshold(5, 19);
|
|
|
|
auto z = 0;
|
|
|
|
for (auto t : thresholds)
|
|
|
|
{
|
|
|
|
BOOST_TEST_MESSAGE(t << ", // z" << z++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-28 10:28:44 -05:00
|
|
|
BOOST_AUTO_TEST_CASE(removed_middle_test)
|
2014-10-27 19:16:03 -04:00
|
|
|
{
|
|
|
|
/*
|
2016-01-08 06:55:37 -05:00
|
|
|
x
|
|
|
|
/ \
|
|
|
|
x \
|
|
|
|
/ \
|
|
|
|
x x
|
|
|
|
*/
|
2016-02-23 15:23:13 -05:00
|
|
|
std::vector<util::Coordinate> coordinates = {
|
2016-06-24 01:01:37 -04:00
|
|
|
util::Coordinate{util::FloatLongitude{5}, util::FloatLatitude{5}},
|
|
|
|
util::Coordinate{util::FloatLongitude{12.5}, util::FloatLatitude{12.6096298302}},
|
|
|
|
util::Coordinate{util::FloatLongitude{20}, util::FloatLatitude{20}},
|
|
|
|
util::Coordinate{util::FloatLongitude{25}, util::FloatLatitude{5}}};
|
2016-01-28 10:28:44 -05:00
|
|
|
|
2016-03-28 16:29:59 -04:00
|
|
|
for (unsigned z = 0; z < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE; z++)
|
2014-10-27 19:16:03 -04:00
|
|
|
{
|
2016-01-28 10:28:44 -05:00
|
|
|
auto result = douglasPeucker(coordinates, z);
|
|
|
|
BOOST_CHECK_EQUAL(result.size(), 3);
|
|
|
|
BOOST_CHECK_EQUAL(result[0], coordinates[0]);
|
|
|
|
BOOST_CHECK_EQUAL(result[1], coordinates[2]);
|
|
|
|
BOOST_CHECK_EQUAL(result[2], coordinates[3]);
|
2014-10-27 19:16:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-28 16:29:59 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(removed_middle_test_zoom_sensitive)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
x
|
|
|
|
/ \
|
|
|
|
x \
|
|
|
|
/ \
|
|
|
|
x x
|
|
|
|
*/
|
|
|
|
std::vector<util::Coordinate> coordinates = {
|
2016-06-24 01:01:37 -04:00
|
|
|
util::Coordinate{util::FloatLongitude{5}, util::FloatLatitude{5}},
|
|
|
|
util::Coordinate{util::FloatLongitude{6}, util::FloatLatitude{6}},
|
|
|
|
util::Coordinate{util::FloatLongitude{20}, util::FloatLatitude{20}},
|
|
|
|
util::Coordinate{util::FloatLongitude{25}, util::FloatLatitude{5}}};
|
2016-03-28 16:29:59 -04:00
|
|
|
|
2016-04-08 18:39:20 -04:00
|
|
|
// Coordinate 6,6 should start getting included at Z9 and higher
|
2016-03-28 16:29:59 -04:00
|
|
|
// Note that 5,5->6,6->10,10 is *not* a straight line on the surface
|
|
|
|
// of the earth
|
2016-04-08 18:39:20 -04:00
|
|
|
for (unsigned z = 0; z < 9; z++)
|
2016-03-28 16:29:59 -04:00
|
|
|
{
|
|
|
|
auto result = douglasPeucker(coordinates, z);
|
|
|
|
BOOST_CHECK_EQUAL(result.size(), 3);
|
|
|
|
}
|
2016-04-08 18:39:20 -04:00
|
|
|
// From 9 to max zoom, we should get all coordinates
|
|
|
|
for (unsigned z = 9; z < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE; z++)
|
2016-03-28 16:29:59 -04:00
|
|
|
{
|
|
|
|
auto result = douglasPeucker(coordinates, z);
|
|
|
|
BOOST_CHECK_EQUAL(result.size(), 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-27 19:16:03 -04:00
|
|
|
BOOST_AUTO_TEST_CASE(remove_second_node_test)
|
|
|
|
{
|
2016-04-08 18:39:20 -04:00
|
|
|
// derived from the degreeToPixel function
|
|
|
|
const auto delta_pixel_to_delta_degree = [](const int pixel, const unsigned zoom) {
|
|
|
|
const double shift = (1u << zoom) * 256;
|
|
|
|
const double b = shift / 2.0;
|
|
|
|
return pixel * 180. / b;
|
|
|
|
};
|
|
|
|
// For zoom level 0 all gets reduced to a line
|
|
|
|
for (unsigned z = 1; z < detail::DOUGLAS_PEUCKER_THRESHOLDS_SIZE; z++)
|
2014-10-27 19:16:03 -04:00
|
|
|
{
|
|
|
|
/*
|
2016-04-08 18:39:20 -04:00
|
|
|
x
|
|
|
|
| \
|
|
|
|
x-x x
|
|
|
|
|
|
|
|
|
x
|
2016-01-08 06:55:37 -05:00
|
|
|
*/
|
2016-02-23 15:23:13 -05:00
|
|
|
std::vector<util::Coordinate> input = {
|
2016-06-24 01:01:37 -04:00
|
|
|
util::Coordinate{util::FloatLongitude{5}, util::FloatLatitude{5}},
|
|
|
|
util::Coordinate{util::FloatLongitude{5 + delta_pixel_to_delta_degree(2, z)},
|
|
|
|
util::FloatLatitude{5}},
|
|
|
|
util::Coordinate{util::FloatLongitude{10}, util::FloatLatitude{10}},
|
|
|
|
util::Coordinate{util::FloatLongitude{5}, util::FloatLatitude{15}},
|
|
|
|
util::Coordinate{util::FloatLongitude{5},
|
|
|
|
util::FloatLatitude{15 + delta_pixel_to_delta_degree(2, z)}}};
|
2016-04-08 18:39:20 -04:00
|
|
|
BOOST_TEST_MESSAGE("Delta (" << z << "): " << delta_pixel_to_delta_degree(2, z));
|
2016-01-28 10:28:44 -05:00
|
|
|
auto result = douglasPeucker(input, z);
|
2016-04-08 18:39:20 -04:00
|
|
|
BOOST_CHECK_EQUAL(result.size(), 3);
|
2016-01-28 10:28:44 -05:00
|
|
|
BOOST_CHECK_EQUAL(input[0], result[0]);
|
|
|
|
BOOST_CHECK_EQUAL(input[2], result[1]);
|
2016-04-08 18:39:20 -04:00
|
|
|
BOOST_CHECK_EQUAL(input[4], result[2]);
|
2014-10-27 19:16:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|