Compare commits

..

1 Commits

Author SHA1 Message Date
Siarhei Fedartsou 96227fd475 Debug osrm-extract CI crash 2024-06-22 20:30:21 +02:00
10 changed files with 720 additions and 911 deletions
File diff suppressed because it is too large Load Diff
-2
View File
@@ -24,8 +24,6 @@
- NodeJS: - NodeJS:
- CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452) - CHANGED: Use node-api instead of NAN. [#6452](https://github.com/Project-OSRM/osrm-backend/pull/6452)
- Misc: - Misc:
- CHANGED: Optimise encodePolyline function. [#6940](https://github.com/Project-OSRM/osrm-backend/pull/6940)
- CHANGED: Avoid reallocations in base64 encoding. [#6951](https://github.com/Project-OSRM/osrm-backend/pull/6951)
- CHANGED: Get rid of unused Boost dependencies. [#6960](https://github.com/Project-OSRM/osrm-backend/pull/6960) - CHANGED: Get rid of unused Boost dependencies. [#6960](https://github.com/Project-OSRM/osrm-backend/pull/6960)
- CHANGED: Apply micro-optimisation for Table & Trip APIs. [#6949](https://github.com/Project-OSRM/osrm-backend/pull/6949) - CHANGED: Apply micro-optimisation for Table & Trip APIs. [#6949](https://github.com/Project-OSRM/osrm-backend/pull/6949)
- CHANGED: Apply micro-optimisation for Route API. [#6948](https://github.com/Project-OSRM/osrm-backend/pull/6948) - CHANGED: Apply micro-optimisation for Route API. [#6948](https://github.com/Project-OSRM/osrm-backend/pull/6948)
+11 -16
View File
@@ -47,29 +47,24 @@ namespace engine
// Encodes a chunk of memory to Base64. // Encodes a chunk of memory to Base64.
inline std::string encodeBase64(const unsigned char *first, std::size_t size) inline std::string encodeBase64(const unsigned char *first, std::size_t size)
{ {
BOOST_ASSERT(size > 0); std::vector<unsigned char> bytes{first, first + size};
BOOST_ASSERT(!bytes.empty());
std::string encoded; std::size_t bytes_to_pad{0};
encoded.reserve(((size + 2) / 3) * 4);
auto padding = (3 - size % 3) % 3; while (bytes.size() % 3 != 0)
BOOST_ASSERT(padding == 0 || padding == 1 || padding == 2);
for (auto itr = detail::Base64FromBinary(first); itr != detail::Base64FromBinary(first + size);
++itr)
{ {
encoded.push_back(*itr); bytes_to_pad += 1;
bytes.push_back(0);
} }
for (size_t index = 0; index < padding; ++index) BOOST_ASSERT(bytes_to_pad == 0 || bytes_to_pad == 1 || bytes_to_pad == 2);
{ BOOST_ASSERT_MSG(0 == bytes.size() % 3, "base64 input data size is not a multiple of 3");
encoded.push_back('=');
}
BOOST_ASSERT(encoded.size() == (size + 2) / 3 * 4); std::string encoded{detail::Base64FromBinary{bytes.data()},
detail::Base64FromBinary{bytes.data() + (bytes.size() - bytes_to_pad)}};
return encoded; return encoded.append(bytes_to_pad, '=');
} }
// C++11 standard 3.9.1/1: Plain char, signed char, and unsigned char are three distinct types // C++11 standard 3.9.1/1: Plain char, signed char, and unsigned char are three distinct types
+15 -12
View File
@@ -12,7 +12,7 @@ namespace osrm::engine
{ {
namespace detail namespace detail
{ {
void encode(int number_to_encode, std::string &output); std::string encode(std::vector<int> &numbers);
std::int32_t decode_polyline_integer(std::string::const_iterator &first, std::int32_t decode_polyline_integer(std::string::const_iterator &first,
std::string::const_iterator last); std::string::const_iterator last);
} // namespace detail } // namespace detail
@@ -30,24 +30,27 @@ std::string encodePolyline(CoordVectorForwardIter begin, CoordVectorForwardIter
return {}; return {};
} }
std::string output; std::vector<int> delta_numbers;
// just a guess that we will need ~4 bytes per coordinate to avoid reallocations BOOST_ASSERT(size > 0);
output.reserve(size * 4); delta_numbers.reserve((size - 1) * 2);
int current_lat = 0; int current_lat = 0;
int current_lon = 0; int current_lon = 0;
for (auto it = begin; it != end; ++it) std::for_each(
begin,
end,
[&delta_numbers, &current_lat, &current_lon, coordinate_to_polyline](
const util::Coordinate loc)
{ {
const int lat_diff = const int lat_diff =
std::round(static_cast<int>(it->lat) * coordinate_to_polyline) - current_lat; std::round(static_cast<int>(loc.lat) * coordinate_to_polyline) - current_lat;
const int lon_diff = const int lon_diff =
std::round(static_cast<int>(it->lon) * coordinate_to_polyline) - current_lon; std::round(static_cast<int>(loc.lon) * coordinate_to_polyline) - current_lon;
detail::encode(lat_diff, output); delta_numbers.emplace_back(lat_diff);
detail::encode(lon_diff, output); delta_numbers.emplace_back(lon_diff);
current_lat += lat_diff; current_lat += lat_diff;
current_lon += lon_diff; current_lon += lon_diff;
} });
return output; return detail::encode(delta_numbers);
} }
// Decodes geometry from polyline format // Decodes geometry from polyline format
+53 -53
View File
@@ -54,67 +54,67 @@ function run_benchmarks_for_folder {
BENCHMARKS_FOLDER="$BINARIES_FOLDER/src/benchmarks" BENCHMARKS_FOLDER="$BINARIES_FOLDER/src/benchmarks"
echo "Running match-bench MLD" echo "Running match-bench MLD"
perf stat -r 1 $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/mld/monaco.osrm" mld #> "$RESULTS_FOLDER/match_mld.bench" $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench"
# echo "Running match-bench CH" echo "Running match-bench CH"
# $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench" $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench"
# echo "Running route-bench MLD" echo "Running route-bench MLD"
# $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench"
# echo "Running route-bench CH" echo "Running route-bench CH"
# $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench"
# echo "Running alias" echo "Running alias"
# $BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench" $BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench"
# echo "Running json-render-bench" echo "Running json-render-bench"
# $BENCHMARKS_FOLDER/json-render-bench "$FOLDER/test/data/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench" $BENCHMARKS_FOLDER/json-render-bench "$FOLDER/src/benchmarks/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench"
# echo "Running packedvector-bench" echo "Running packedvector-bench"
# $BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench" $BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench"
# echo "Running rtree-bench" echo "Running rtree-bench"
# $BENCHMARKS_FOLDER/rtree-bench "$FOLDER/test/data/monaco.osrm.ramIndex" "$FOLDER/test/data/monaco.osrm.fileIndex" "$FOLDER/test/data/monaco.osrm.nbg_nodes" > "$RESULTS_FOLDER/rtree.bench" $BENCHMARKS_FOLDER/rtree-bench "$FOLDER/test/data/monaco.osrm.ramIndex" "$FOLDER/test/data/monaco.osrm.fileIndex" "$FOLDER/test/data/monaco.osrm.nbg_nodes" > "$RESULTS_FOLDER/rtree.bench"
# cp -rf $OSM_PBF $FOLDER/data.osm.pbf cp -rf $OSM_PBF $FOLDER/data.osm.pbf
# echo "Running osrm-extract" echo "Running osrm-extract"
# measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-extract -p $FOLDER/profiles/car.lua $FOLDER/data.osm.pbf" "$RESULTS_FOLDER/osrm_extract.bench" measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-extract -p $FOLDER/profiles/car.lua $FOLDER/data.osm.pbf" "$RESULTS_FOLDER/osrm_extract.bench"
# echo "Running osrm-partition" echo "Running osrm-partition"
# measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-partition $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_partition.bench" measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-partition $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_partition.bench"
# echo "Running osrm-customize" echo "Running osrm-customize"
# measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-customize $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_customize.bench" measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-customize $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_customize.bench"
# echo "Running osrm-contract" echo "Running osrm-contract"
# measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-contract $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_contract.bench" measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-contract $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_contract.bench"
# for ALGORITHM in ch mld; do for ALGORITHM in ch mld; do
# for BENCH in nearest table trip route match; do for BENCH in nearest table trip route match; do
# echo "Running random $BENCH $ALGORITHM" echo "Running random $BENCH $ALGORITHM"
# START=$(date +%s.%N) START=$(date +%s.%N)
# $BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" $ALGORITHM $GPS_TRACES ${BENCH} > "$RESULTS_FOLDER/random_${BENCH}_${ALGORITHM}.bench" 5 || true $BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" $ALGORITHM $GPS_TRACES ${BENCH} > "$RESULTS_FOLDER/random_${BENCH}_${ALGORITHM}.bench" 5 || true
# END=$(date +%s.%N) END=$(date +%s.%N)
# DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
# echo "Took: ${DIFF}s" echo "Took: ${DIFF}s"
# done done
# done done
# for ALGORITHM in ch mld; do for ALGORITHM in ch mld; do
# $BINARIES_FOLDER/osrm-routed --algorithm $ALGORITHM $FOLDER/data.osrm > /dev/null 2>&1 & $BINARIES_FOLDER/osrm-routed --algorithm $ALGORITHM $FOLDER/data.osrm > /dev/null 2>&1 &
# OSRM_ROUTED_PID=$! OSRM_ROUTED_PID=$!
# # wait for osrm-routed to start # wait for osrm-routed to start
# if ! curl --retry-delay 3 --retry 10 --retry-all-errors "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true" > /dev/null 2>&1; then if ! curl --retry-delay 3 --retry 10 --retry-all-errors "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true" > /dev/null 2>&1; then
# echo "osrm-routed failed to start for algorithm $ALGORITHM" echo "osrm-routed failed to start for algorithm $ALGORITHM"
# kill -9 $OSRM_ROUTED_PID kill -9 $OSRM_ROUTED_PID
# continue continue
# fi fi
# for METHOD in route nearest trip table match; do for METHOD in route nearest trip table match; do
# echo "Running e2e benchmark for $METHOD $ALGORITHM" echo "Running e2e benchmark for $METHOD $ALGORITHM"
# START=$(date +%s.%N) START=$(date +%s.%N)
# python3 $SCRIPTS_FOLDER/scripts/ci/e2e_benchmark.py --host http://localhost:5000 --method $METHOD --iterations 5 --num_requests 1000 --gps_traces_file_path $GPS_TRACES > $RESULTS_FOLDER/e2e_${METHOD}_${ALGORITHM}.bench python3 $SCRIPTS_FOLDER/scripts/ci/e2e_benchmark.py --host http://localhost:5000 --method $METHOD --iterations 5 --num_requests 1000 --gps_traces_file_path $GPS_TRACES > $RESULTS_FOLDER/e2e_${METHOD}_${ALGORITHM}.bench
# END=$(date +%s.%N) END=$(date +%s.%N)
# DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
# echo "Took: ${DIFF}s" echo "Took: ${DIFF}s"
# done done
# kill -9 $OSRM_ROUTED_PID kill -9 $OSRM_ROUTED_PID
# done done
} }
run_benchmarks_for_folder run_benchmarks_for_folder
+27 -12
View File
@@ -10,19 +10,9 @@
namespace osrm::engine::detail // anonymous to keep TU local namespace osrm::engine::detail // anonymous to keep TU local
{ {
void encode(int number_to_encode, std::string &output) std::string encode(int number_to_encode)
{ {
if (number_to_encode < 0) std::string output;
{
const unsigned binary = std::llabs(number_to_encode);
const unsigned twos = (~binary) + 1u;
const unsigned shl = twos << 1u;
number_to_encode = static_cast<int>(~shl);
}
else
{
number_to_encode <<= 1u;
}
while (number_to_encode >= 0x20) while (number_to_encode >= 0x20)
{ {
const int next_value = (0x20 | (number_to_encode & 0x1f)) + 63; const int next_value = (0x20 | (number_to_encode & 0x1f)) + 63;
@@ -32,6 +22,31 @@ void encode(int number_to_encode, std::string &output)
number_to_encode += 63; number_to_encode += 63;
output += static_cast<char>(number_to_encode); output += static_cast<char>(number_to_encode);
return output;
}
std::string encode(std::vector<int> &numbers)
{
std::string output;
for (auto &number : numbers)
{
if (number < 0)
{
const unsigned binary = std::llabs(number);
const unsigned twos = (~binary) + 1u;
const unsigned shl = twos << 1u;
number = static_cast<int>(~shl);
}
else
{
number <<= 1u;
}
}
for (const int number : numbers)
{
output += encode(number);
}
return output;
} }
// https://developers.google.com/maps/documentation/utilities/polylinealgorithm // https://developers.google.com/maps/documentation/utilities/polylinealgorithm
+13 -9
View File
@@ -1254,7 +1254,7 @@ void Sol2ScriptingEnvironment::ProcessSegment(ExtractionSegment &segment)
if (context.has_segment_function) if (context.has_segment_function)
{ {
sol::protected_function_result luares; std::optional<sol::protected_function_result> luares;
switch (context.api_version) switch (context.api_version)
{ {
case 4: case 4:
@@ -1274,8 +1274,8 @@ void Sol2ScriptingEnvironment::ProcessSegment(ExtractionSegment &segment)
break; break;
} }
if (!luares.valid()) if (luares && !luares->valid())
handle_lua_error(luares); handle_lua_error(*luares);
} }
} }
@@ -1285,7 +1285,7 @@ void LuaScriptingContext::ProcessNode(const osmium::Node &node,
{ {
BOOST_ASSERT(state.lua_state() != nullptr); BOOST_ASSERT(state.lua_state() != nullptr);
sol::protected_function_result luares; std::optional<sol::protected_function_result> luares;
// TODO check for api version, make sure luares is always set // TODO check for api version, make sure luares is always set
switch (api_version) switch (api_version)
@@ -1302,10 +1302,12 @@ void LuaScriptingContext::ProcessNode(const osmium::Node &node,
case 0: case 0:
luares = node_function(std::cref(node), std::ref(result)); luares = node_function(std::cref(node), std::ref(result));
break; break;
default:
BOOST_ASSERT(false && "Invalid API version");
} }
if (!luares.valid()) if (luares && !luares->valid())
handle_lua_error(luares); handle_lua_error(*luares);
} }
void LuaScriptingContext::ProcessWay(const osmium::Way &way, void LuaScriptingContext::ProcessWay(const osmium::Way &way,
@@ -1314,7 +1316,7 @@ void LuaScriptingContext::ProcessWay(const osmium::Way &way,
{ {
BOOST_ASSERT(state.lua_state() != nullptr); BOOST_ASSERT(state.lua_state() != nullptr);
sol::protected_function_result luares; std::optional<sol::protected_function_result> luares;
// TODO check for api version, make sure luares is always set // TODO check for api version, make sure luares is always set
switch (api_version) switch (api_version)
@@ -1331,10 +1333,12 @@ void LuaScriptingContext::ProcessWay(const osmium::Way &way,
case 0: case 0:
luares = way_function(std::cref(way), std::ref(result)); luares = way_function(std::cref(way), std::ref(result));
break; break;
default:
BOOST_ASSERT(false && "Invalid API version");
} }
if (!luares.valid()) if (luares && !luares->valid())
handle_lua_error(luares); handle_lua_error(*luares);
} }
} // namespace osrm::extractor } // namespace osrm::extractor
-94
View File
@@ -74,98 +74,4 @@ BOOST_AUTO_TEST_CASE(hint_encoding_decoding_roundtrip_bytewise)
reinterpret_cast<const unsigned char *>(&decoded))); reinterpret_cast<const unsigned char *>(&decoded)));
} }
BOOST_AUTO_TEST_CASE(long_string_encoding)
{
using namespace osrm::engine;
std::string long_string(1000, 'A'); // String of 1000 'A's
std::string encoded = encodeBase64(long_string);
BOOST_CHECK_EQUAL(decodeBase64(encoded), long_string);
}
BOOST_AUTO_TEST_CASE(invalid_base64_decoding)
{
using namespace osrm::engine;
BOOST_CHECK_THROW(decodeBase64("Invalid!"), std::exception);
}
BOOST_AUTO_TEST_CASE(hint_serialization_size)
{
using namespace osrm::engine;
using namespace osrm::util;
const Coordinate coordinate;
const PhantomNode phantom;
const osrm::test::MockDataFacade<osrm::engine::routing_algorithms::ch::Algorithm> facade{};
const SegmentHint hint{phantom, facade.GetCheckSum()};
const auto base64 = hint.ToBase64();
BOOST_CHECK_EQUAL(base64.size(), 112);
}
BOOST_AUTO_TEST_CASE(extended_roundtrip_tests)
{
using namespace osrm::engine;
std::vector<std::string> test_strings = {
"Hello, World!", // Simple ASCII string
"1234567890", // Numeric string
"!@#$%^&*()_+", // Special characters
std::string(1000, 'A'), // Long repeating string
"¡Hola, mundo!", // Non-ASCII characters
"こんにちは、世界!", // Unicode characters
std::string("\x00\x01\x02\x03", 4), // Binary data
"a", // Single character
"ab", // Two characters
"abc", // Three characters (no padding in Base64)
std::string(190, 'x') // String that doesn't align with Base64 padding
};
for (const auto &test_str : test_strings)
{
std::string encoded = encodeBase64(test_str);
std::string decoded = decodeBase64(encoded);
BOOST_CHECK_EQUAL(decoded, test_str);
// Additional checks
BOOST_CHECK(encoded.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=") ==
std::string::npos);
if (test_str.length() % 3 != 0)
{
BOOST_CHECK(encoded.back() == '=');
}
}
}
BOOST_AUTO_TEST_CASE(roundtrip_with_url_safe_chars)
{
using namespace osrm::engine;
std::string original = "Hello+World/Nothing?Is:Impossible";
std::string encoded = encodeBase64(original);
// Replace '+' with '-' and '/' with '_'
std::replace(encoded.begin(), encoded.end(), '+', '-');
std::replace(encoded.begin(), encoded.end(), '/', '_');
std::string decoded = decodeBase64(encoded);
BOOST_CHECK_EQUAL(decoded, original);
}
BOOST_AUTO_TEST_CASE(roundtrip_stress_test)
{
using namespace osrm::engine;
std::string test_str;
for (int i = 0; i < 1000; ++i)
{
test_str += static_cast<char>(i % 256);
}
std::string encoded = encodeBase64(test_str);
std::string decoded = decodeBase64(encoded);
BOOST_CHECK_EQUAL(decoded, test_str);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
-92
View File
@@ -45,96 +45,4 @@ BOOST_AUTO_TEST_CASE(polyline6_test_case)
decodePolyline<1000000>(encodePolyline<1000000>(coords.begin(), coords.end())).begin())); decodePolyline<1000000>(encodePolyline<1000000>(coords.begin(), coords.end())).begin()));
} }
BOOST_AUTO_TEST_CASE(empty_polyline_test)
{
using namespace osrm::engine;
using namespace osrm::util;
std::vector<Coordinate> empty_coords;
BOOST_CHECK_EQUAL(encodePolyline(empty_coords.begin(), empty_coords.end()), "");
BOOST_CHECK(decodePolyline("").empty());
}
BOOST_AUTO_TEST_CASE(polyline_single_point_test)
{
using namespace osrm::engine;
using namespace osrm::util;
const std::vector<Coordinate> coords({{FixedLongitude{-122414000}, FixedLatitude{37776000}}});
const std::string encoded = encodePolyline(coords.begin(), coords.end());
BOOST_CHECK_EQUAL(encoded, "_cqeFn~cjV");
const auto decoded = decodePolyline(encoded);
BOOST_CHECK_EQUAL(decoded.size(), 1);
BOOST_CHECK_EQUAL(decoded[0].lon, FixedLongitude{-122414000});
BOOST_CHECK_EQUAL(decoded[0].lat, FixedLatitude{37776000});
}
BOOST_AUTO_TEST_CASE(polyline_multiple_points_test)
{
using namespace osrm::engine;
using namespace osrm::util;
const std::vector<Coordinate> coords({{FixedLongitude{-122414000}, FixedLatitude{37776000}},
{FixedLongitude{-122420000}, FixedLatitude{37779000}},
{FixedLongitude{-122421000}, FixedLatitude{37780000}}});
const std::string encoded = encodePolyline(coords.begin(), coords.end());
BOOST_CHECK_EQUAL(encoded, "_cqeFn~cjVwQnd@gEfE");
const auto decoded = decodePolyline(encoded);
BOOST_CHECK_EQUAL(decoded.size(), 3);
for (size_t i = 0; i < coords.size(); ++i)
{
BOOST_CHECK_EQUAL(decoded[i].lon, coords[i].lon);
BOOST_CHECK_EQUAL(decoded[i].lat, coords[i].lat);
}
}
BOOST_AUTO_TEST_CASE(polyline_large_coordinate_difference_test)
{
using namespace osrm::engine;
using namespace osrm::util;
const std::vector<Coordinate> coords({{FixedLongitude{-179000000}, FixedLatitude{-89000000}},
{FixedLongitude{179000000}, FixedLatitude{89000000}}});
const std::string encoded = encodePolyline(coords.begin(), coords.end());
BOOST_CHECK_EQUAL(encoded, "~xe~O~|oca@_sl}`@_{`hcA");
const auto decoded = decodePolyline(encoded);
BOOST_CHECK_EQUAL(decoded.size(), 2);
for (size_t i = 0; i < coords.size(); ++i)
{
BOOST_CHECK_EQUAL(decoded[i].lon, coords[i].lon);
BOOST_CHECK_EQUAL(decoded[i].lat, coords[i].lat);
}
}
BOOST_AUTO_TEST_CASE(roundtrip)
{
using namespace osrm::engine;
using namespace osrm::util;
{
const auto encoded = "_chxEn`zvN\\\\]]";
const auto decoded = decodePolyline(encoded);
const auto reencoded = encodePolyline(decoded.begin(), decoded.end());
BOOST_CHECK_EQUAL(encoded, reencoded);
}
{
const auto encoded =
"gcneIpgxzRcDnBoBlEHzKjBbHlG`@`IkDxIiKhKoMaLwTwHeIqHuAyGXeB~Ew@fFjAtIzExF";
const auto decoded = decodePolyline(encoded);
const auto reencoded = encodePolyline(decoded.begin(), decoded.end());
BOOST_CHECK_EQUAL(encoded, reencoded);
}
{
const auto encoded = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
const auto decoded = decodePolyline(encoded);
const auto reencoded = encodePolyline(decoded.begin(), decoded.end());
BOOST_CHECK_EQUAL(encoded, reencoded);
}
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()