diff --git a/docs/http.md b/docs/http.md index e6c5da427..28601ba1b 100644 --- a/docs/http.md +++ b/docs/http.md @@ -15,7 +15,7 @@ GET /{service}/{version}/{profile}/{coordinates}[.{format}]?option=value&option= | `service` | One of the following values: [`route`](#route-service), [`nearest`](#nearest-service), [`table`](#table-service), [`match`](#match-service), [`trip`](#trip-service), [`tile`](#tile-service) | | `version` | Version of the protocol implemented by the service. `v1` for all OSRM 5.x installations | | `profile` | Mode of transportation, is determined statically by the Lua profile that is used to prepare the data using `osrm-extract`. Typically `car`, `bike` or `foot` if using one of the supplied profiles. | -| `coordinates`| String of format `{longitude},{latitude};{longitude},{latitude}[;{longitude},{latitude} ...]` or `polyline({polyline})`. | +| `coordinates`| String of format `{longitude},{latitude};{longitude},{latitude}[;{longitude},{latitude} ...]` or `polyline({polyline}) or polyline6({polyline6})`. | | `format`| Only `json` is supported at the moment. This parameter is optional and defaults to `json`. | Passing any `option=value` is optional. `polyline` follows Google's polyline format with precision 5 by default and can be generated using [this package](https://www.npmjs.com/package/polyline). diff --git a/unit_tests/engine/polyline_compressor.cpp b/unit_tests/engine/polyline_compressor.cpp new file mode 100644 index 000000000..b8c0fb49a --- /dev/null +++ b/unit_tests/engine/polyline_compressor.cpp @@ -0,0 +1,60 @@ +#include "engine/polyline_compressor.hpp" +#include "util/coordinate.hpp" + +#include +#include + +#include +#include + +BOOST_AUTO_TEST_SUITE(polyline_compression) + +BOOST_AUTO_TEST_CASE(polyline5_test_case) +{ + using namespace osrm::engine; + using namespace osrm::util; + + const std::vector coords({ + {FixedLongitude{-73990171}, FixedLatitude{40714701}}, + {FixedLongitude{-73991801}, FixedLatitude{40717571}}, + {FixedLongitude{-73985751}, FixedLatitude{40715651}} + }); + + const std::vector coords_truncated({ + {FixedLongitude{-73990170}, FixedLatitude{40714700}}, + {FixedLongitude{-73991800}, FixedLatitude{40717570}}, + {FixedLongitude{-73985750}, FixedLatitude{40715650}} + }); + + BOOST_CHECK_EQUAL(encodePolyline(coords.begin(), coords.end()), "{aowFperbM}PdI~Jyd@"); + BOOST_CHECK( + std::equal( + coords_truncated.begin(), + coords_truncated.end(), + decodePolyline(encodePolyline(coords.begin(), coords.end())).begin() + ) + ); +} + +BOOST_AUTO_TEST_CASE(polyline6_test_case) +{ + using namespace osrm::engine; + using namespace osrm::util; + + const std::vector coords({ + {FixedLongitude{-73990171}, FixedLatitude{40714701}}, + {FixedLongitude{-73991801}, FixedLatitude{40717571}}, + {FixedLongitude{-73985751}, FixedLatitude{40715651}} + }); + + BOOST_CHECK_EQUAL(encodePolyline<1000000>(coords.begin(), coords.end()), "y{_tlAt`_clCkrDzdB~vBcyJ"); + BOOST_CHECK( + std::equal( + coords.begin(), + coords.end(), + decodePolyline<1000000>(encodePolyline<1000000>(coords.begin(), coords.end())).begin() + ) + ); +} + +BOOST_AUTO_TEST_SUITE_END()