Skip to content
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 6 commits into from
Jul 10, 2023
Merged

Adding further engine bindings #6

merged 6 commits into from
Jul 10, 2023

Conversation

whytro
Copy link
Collaborator

@whytro whytro commented Jun 30, 2023

Added more bindings for the other engine calls. However, I did run into an issue with the MatchParameters bindings, which I suspect has something to do with the way the argument forwarding is set up.

Also added __repr__ outputs for the custom JSON types, so they print out as expected.

@whytro
Copy link
Collaborator Author

whytro commented Jun 30, 2023

I've attached the MatchParameters file as reference here, but the gist of it is that I can't find the proper parameter combination to have it link. It seems to not like that waypoints is explicitly specified in MatchParameters, while it's also handled in RouteParameters, so it expects the waypoints parameters again, which also throws off the va starting point for BaseParameters.

@nilsnolde
Copy link
Owner

Thanks for the further work! It's quite a lot to review though;) It's ok for now, and let's merge once reviewed and got your small problem out of the way. After that, we should concentrate on testing IMO, which will also allow us to see how the API currently works for a user (it's hard to understand just looking at the code).

This was referenced Jul 3, 2023
std::vector<std::string> exclude,
const BaseParameters::SnappingType snapping
) {
new (t) MatchParameters(
Copy link
Collaborator Author

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I'm not sure if it would be clearer to just fully assign all values manually

Yeah I agree here

Copy link
Collaborator Author

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you agree with manually assigning all values

exactly that:)

Copy link
Owner

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part that I didn't fully understand about the NodeJS annotations_type part there is that it seems to check what enum type was sent for annotations to assign the annotations_type value (in an array), but for the C++ side of things, it seems to base it off which RouteParameters constructor is called. If I'm understanding this part correctly, the user is able to send in an array of AnnotationsTypes, which gets calculated up? In that case, it would make sense to apply that same abstraction to the Python bindings.

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++ side std::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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The part that I didn't fully understand about the NodeJS annotations_type part there is that it seems to check what enum type was sent for annotations to assign the annotations_type value (in an array), but for the C++ side of things, it seems to base it off which RouteParameters constructor is called. If I'm understanding this part correctly, the user is able to send in an array of AnnotationsTypes, which gets calculated up? In that case, it would make sense to apply that same abstraction to the Python bindings.

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++ side std::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.

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

Copy link
Collaborator

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:

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++ side 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.

Copy link
Collaborator Author

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!

Copy link
Collaborator Author

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.

@whytro whytro marked this pull request as ready for review July 3, 2023 12:42
Copy link
Owner

@nilsnolde nilsnolde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates. Just a question for the JSON return type commit, then it LGTM. Sorry, if we were confusing on that, I'm just not sure your previous solution was actually working better for recursive types such as array/object.

@whytro
Copy link
Collaborator Author

whytro commented Jul 3, 2023

Thanks for the updates. Just a question for the JSON return type commit, then it LGTM. Sorry, if we were confusing on that, I'm just not sure your previous solution was actually working better for recursive types such as array/object.

Yes, it works both ways, and basic benchmarking seemed to show negligible difference between the two methods, so I went with the return visitor for code clarity.

On the topic of mapbox recursive types, it seems it works without an explicit .get() call, but I added it in anyways for clarity.

@nilsnolde
Copy link
Owner

LGTM, thanks!

@nilsnolde nilsnolde merged commit c3dc93b into main Jul 10, 2023
@whytro whytro deleted the parameters branch July 30, 2023 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants