2016-04-13 17:07:24 -04:00
|
|
|
#ifndef OSRM_UNIT_TEST_WAYPOINT_CHECK
|
|
|
|
#define OSRM_UNIT_TEST_WAYPOINT_CHECK
|
|
|
|
|
2019-08-16 04:27:49 -04:00
|
|
|
#include "engine/api/flatbuffers/fbresult_generated.h"
|
2016-04-13 17:07:24 -04:00
|
|
|
#include "osrm/coordinate.hpp"
|
|
|
|
#include "osrm/json_container.hpp"
|
|
|
|
#include "util/exception.hpp"
|
2024-05-28 12:52:49 -04:00
|
|
|
#include <variant>
|
2016-04-13 17:07:24 -04:00
|
|
|
|
2022-06-30 09:32:12 -04:00
|
|
|
inline bool waypoint_check(osrm::json::Value waypoint)
|
2016-04-13 17:07:24 -04:00
|
|
|
{
|
2022-06-30 09:32:12 -04:00
|
|
|
using namespace osrm;
|
|
|
|
|
2024-05-28 12:52:49 -04:00
|
|
|
if (!std::holds_alternative<util::json::Object>(waypoint))
|
2016-04-13 17:07:24 -04:00
|
|
|
{
|
|
|
|
throw util::exception("Must pass in a waypoint object");
|
|
|
|
}
|
2024-05-28 12:52:49 -04:00
|
|
|
const auto waypoint_object = std::get<json::Object>(waypoint);
|
|
|
|
const auto waypoint_location =
|
|
|
|
std::get<json::Array>(waypoint_object.values.at("location")).values;
|
|
|
|
util::FloatLongitude lon{std::get<json::Number>(waypoint_location[0]).value};
|
|
|
|
util::FloatLatitude lat{std::get<json::Number>(waypoint_location[1]).value};
|
2016-04-13 17:07:24 -04:00
|
|
|
util::Coordinate location_coordinate(lon, lat);
|
|
|
|
return location_coordinate.IsValid();
|
|
|
|
}
|
|
|
|
|
2019-08-16 04:27:49 -04:00
|
|
|
inline bool waypoint_check(const osrm::engine::api::fbresult::Waypoint *const waypoint)
|
|
|
|
{
|
2022-06-30 09:32:12 -04:00
|
|
|
using namespace osrm;
|
|
|
|
|
2019-08-26 07:31:51 -04:00
|
|
|
util::FloatLongitude lon{waypoint->location()->longitude()};
|
2019-08-16 04:27:49 -04:00
|
|
|
util::FloatLatitude lat{waypoint->location()->latitude()};
|
|
|
|
util::Coordinate location_coordinate(lon, lat);
|
|
|
|
return location_coordinate.IsValid();
|
|
|
|
}
|
|
|
|
|
2016-04-13 17:07:24 -04:00
|
|
|
#endif
|