-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Parse old annotations parameter true as new annotations_type all #3692
Conversation
include/engine/api/route_api.hpp
Outdated
{ | ||
if (parameters.annotations == true) | ||
parameters.annotations_type = RouteParameters::AnnotationsType::All; |
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.
This will break new functionality with a list of values. It will always fallback to All
include/engine/api/route_api.hpp
Outdated
{ | ||
if (parameters.annotations == true) | ||
parameters.annotations_type = RouteParameters::AnnotationsType::All; |
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.
This will break new functionality with a list of values. It will always fallback to All
3b02154
to
2a26a45
Compare
include/engine/api/route_api.hpp
Outdated
@@ -228,42 +228,50 @@ class RouteAPI : public BaseAPI | |||
|
|||
std::vector<util::json::Object> annotations; | |||
|
|||
if (parameters.annotations_type != RouteParameters::AnnotationsType::None) | |||
if (parameters.annotations_type != RouteParameters::AnnotationsType::None || | |||
parameters.annotations == true) |
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.
could this also be
if (parameters.annotations == true)
?
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 think there are technically cases where only checking for parameters.annotations
could be wrong. Say with a constructor where annotations
defaults to false
and then annotations_type is manually set.
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.
Ah I get your point. Like, it should be good for how we use it now but better safe than sorry?
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.
Seems reasonable to me to keep both checks, especially since this PR is supposed to be fixing the usage case in node-osrm that I didn't think of.
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.
ok, just noticed: definitely keep this, it'll make node-osrm
prettier :D
include/engine/api/route_api.hpp
Outdated
{ | ||
auto ReqAnnotations = parameters.annotations_type; | ||
if ((parameters.annotations == true) & (parameters.annotations_type & | ||
RouteParameters::AnnotationsType::None)) |
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 think it should be &&
instead of &
in the first case because it is a boolean comparison?
if ((parameters.annotations == true) && (parameters.annotations_type &
RouteParameters::AnnotationsType::None))
Also I'm not sure what (parameters.annotations_type & RouteParameters::AnnotationsType::None)
is doing. Is
(parameters.annotations_type == RouteParameters::AnnotationsType::None)
not more intuitive and does the same? Not sure though cause I don't know much about bit-magic
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.
(parameters.annotations_type & RouteParameters::AnnotationsType::None
will always be false, needs to be ==
instead of &
.
include/engine/api/route_api.hpp
Outdated
for (const auto idx : util::irange<std::size_t>(0UL, leg_geometries.size())) | ||
{ | ||
auto &leg_geometry = leg_geometries[idx]; | ||
util::json::Object annotation; | ||
|
||
if (parameters.annotations_type & RouteParameters::AnnotationsType::Duration) | ||
if (ReqAnnotations & RouteParameters::AnnotationsType::Duration) |
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.
maybe we should add a comment explaining to the future that this basically means
"if Duration bit was set"
looks good overall 👍 Also:
|
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.
There is a logic bug and some smaller style issues.
include/engine/api/route_api.hpp
Outdated
{ | ||
auto ReqAnnotations = parameters.annotations_type; |
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.
local variables use lower_case
names. Maybe annotations_type
would be a good name here:
auto annotations_type = parameters.annotations_type;
include/engine/api/route_api.hpp
Outdated
{ | ||
auto ReqAnnotations = parameters.annotations_type; | ||
if ((parameters.annotations == true) & (parameters.annotations_type & | ||
RouteParameters::AnnotationsType::None)) |
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.
(parameters.annotations_type & RouteParameters::AnnotationsType::None
will always be false, needs to be ==
instead of &
.
include/engine/api/route_api.hpp
Outdated
(parameters.annotations_type == RouteParameters::AnnotationsType::None)) | ||
{ | ||
requested_annotations = RouteParameters::AnnotationsType::All; | ||
} |
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.
If this code block is moved before line 231 you can change the first if to also only check for the ::None
case. That reduces the points in the code that need to know about the work-a-round.
Also to note: this problem will go away when we remove redundant bool parameters in v6 #3644 |
84cb198
to
6301e34
Compare
Issue
Closes #3684
Tasklist
Requirements / Relations
Sort of fixes Project-OSRM/node-osrm#297 but doesn't really matter, this pr mostly preserves backwards compatibility