-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding further engine bindings #6
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2490fcb
Add further engine support
whytro 171e825
Add __repr__ output for custom JSON types
whytro c5b00de
Add in MatchParameter support
whytro af1adc7
Add validity check for TileParameter argument
whytro 0bc51a5
Adjust visitor for JSON types to return string
whytro cc5ed2b
Adjust MatchParameter arguments and handling
whytro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "parameters/matchparameter_nb.h" | ||
|
||
#include "engine/api/match_parameters.hpp" | ||
|
||
#include <nanobind/nanobind.h> | ||
#include <nanobind/stl/string.h> | ||
#include <nanobind/stl/vector.h> | ||
|
||
namespace nb = nanobind; | ||
using namespace nb::literals; | ||
|
||
void init_MatchParameters(nb::module_& m) { | ||
using osrm::engine::api::BaseParameters; | ||
using osrm::engine::api::RouteParameters; | ||
using osrm::engine::api::MatchParameters; | ||
|
||
nb::enum_<MatchParameters::GapsType>(m, "MatchGapsType") | ||
.value("Split", MatchParameters::GapsType::Split) | ||
.value("Ignore", MatchParameters::GapsType::Ignore) | ||
.export_values(); | ||
|
||
nb::class_<MatchParameters, RouteParameters>(m, "MatchParameters") | ||
.def(nb::init<>()) | ||
.def("__init__", [](MatchParameters* t, | ||
std::vector<unsigned> timestamps, | ||
MatchParameters::GapsType gaps, | ||
bool tidy, | ||
std::vector<std::size_t> waypoints, | ||
const bool steps, | ||
const bool alternatives, | ||
const RouteParameters::AnnotationsType annotations, | ||
const RouteParameters::GeometriesType geometries, | ||
const RouteParameters::OverviewType overview, | ||
const boost::optional<bool> continue_straight, | ||
std::vector<osrm::util::Coordinate> coordinates, | ||
std::vector<boost::optional<osrm::engine::Hint>> hints, | ||
std::vector<boost::optional<double>> radiuses, | ||
std::vector<boost::optional<osrm::engine::Bearing>> bearings, | ||
std::vector<boost::optional<osrm::engine::Approach>> approaches, | ||
bool generate_hints, | ||
std::vector<std::string> exclude, | ||
const BaseParameters::SnappingType snapping | ||
) { | ||
new (t) MatchParameters( | ||
timestamps, gaps, tidy, | ||
steps, alternatives, annotations, | ||
geometries, overview, continue_straight | ||
); | ||
|
||
t->waypoints = std::move(waypoints); | ||
t->coordinates = std::move(coordinates); | ||
t->hints = std::move(hints); | ||
t->radiuses = std::move(radiuses); | ||
t->bearings = std::move(bearings); | ||
t->approaches = std::move(approaches); | ||
t->generate_hints = generate_hints; | ||
t->exclude = std::move(exclude); | ||
t->snapping = snapping; | ||
}, | ||
"timestamps"_a, | ||
"gaps"_a = MatchParameters::GapsType::Split, | ||
"tidy"_a = false, | ||
"waypoints"_a = std::vector<std::size_t>(), | ||
"steps"_a, | ||
"alternatives"_a, | ||
"annotations"_a = RouteParameters::AnnotationsType::None, | ||
"geometries"_a, | ||
"overview"_a, | ||
"continue_straight"_a, | ||
"coordinates"_a = std::vector<osrm::util::Coordinate>(), | ||
"hints"_a = std::vector<boost::optional<osrm::engine::Hint>>(), | ||
"radiuses"_a = std::vector<boost::optional<double>>(), | ||
"bearings"_a = std::vector<boost::optional<osrm::engine::Bearing>>(), | ||
"approaches"_a = std::vector<boost::optional<osrm::engine::Approach>>(), | ||
"generate_hints"_a = true, | ||
"exclude"_a = std::vector<std::string>(), | ||
"snapping"_a = BaseParameters::SnappingType::Default | ||
) | ||
.def_rw("timestamps", &MatchParameters::timestamps) | ||
.def_rw("gaps", &MatchParameters::gaps) | ||
.def_rw("tidy", &MatchParameters::tidy) | ||
.def("IsValid", &MatchParameters::IsValid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done the MatchParameters in the "assigning" way, but I'm not sure if it would be clearer to just fully assign all values manually, or use the constructor for MatchParameters and RouteParameters, and then manually assign for BaseParameters.
I believe the NodeJS bindings do it in the inverse way instead (ie. assigning BaseParameters, and then everything else is explicitly assigned), but I think that would be more complicated to replicate here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, do you mean that you agree with manually assigning all values over "hybrid" instantiation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly that:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you want to integrate that change before merging or make an issue out of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I fully understand the question... What happens in NodeJS bindings it simply converts something like this on JS side
["nodes", "distance", "speed"]
to smth like this on C++ sidestd::vector<AnnotationType>{AnnotationType::Nodes, AnnotationType::Distance, AnnotationType::Speed}
. Can we do the same on Python side? Ofc we can use https://docs.python.org/3/library/enum.html or smth like this if needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's definitely possible, but my confusion stemmed from the C++ side of things not accepting a vector of AnnotationsType - only an AnnotationsType enum. On the C++ end, is the user expected to perform that calculation prior to passing it in? Otherwise I can create an abstraction for that, like on the NodeJS bindings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh, I got it.
annotations_type
is not vector indeed, it is bitmask. Then you indeed can follow NodeJS path and just transform Python's list to this bitmask just like NodeJS bindings do.So I would rephrase what I said above:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that sounds doable, thanks for the clarifications!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made adjustments to accommodate the requested changes. In the process, I've also discovered a bug in osrm-backend's RouteParameter's AnnotationsType
|=
operator overload that renders it nonfunctional, so I've also put in a PR over there to address that.