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

Parse old annotations parameter true as new annotations_type all #3692

Merged
merged 2 commits into from
Feb 13, 2017

Conversation

karenzshea
Copy link
Contributor

@karenzshea karenzshea commented Feb 10, 2017

Issue

Closes #3684

Tasklist

  • add regression / cucumber cases (see docs/testing.md)
  • review
  • adjust for comments

Requirements / Relations

Sort of fixes Project-OSRM/node-osrm#297 but doesn't really matter, this pr mostly preserves backwards compatibility

{
if (parameters.annotations == true)
parameters.annotations_type = RouteParameters::AnnotationsType::All;
Copy link
Contributor

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

{
if (parameters.annotations == true)
parameters.annotations_type = RouteParameters::AnnotationsType::All;
Copy link
Contributor

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

@karenzshea karenzshea force-pushed the annotations_type_true branch from 3b02154 to 2a26a45 Compare February 13, 2017 09:25
@karenzshea karenzshea added this to the 5.6.0 milestone Feb 13, 2017
@@ -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)
Copy link
Member

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)?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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

{
auto ReqAnnotations = parameters.annotations_type;
if ((parameters.annotations == true) & (parameters.annotations_type &
RouteParameters::AnnotationsType::None))
Copy link
Member

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

Copy link
Member

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 &.

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)
Copy link
Member

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"

@chaupow
Copy link
Member

chaupow commented Feb 13, 2017

looks good overall 👍
Have some questions about the first if-conditions but otherwise good to go I think.

Also:

  • needs to be clangformatted to make travis happy.

Copy link
Member

@TheMarex TheMarex left a 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.

{
auto ReqAnnotations = parameters.annotations_type;
Copy link
Member

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;

{
auto ReqAnnotations = parameters.annotations_type;
if ((parameters.annotations == true) & (parameters.annotations_type &
RouteParameters::AnnotationsType::None))
Copy link
Member

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 &.

(parameters.annotations_type == RouteParameters::AnnotationsType::None))
{
requested_annotations = RouteParameters::AnnotationsType::All;
}
Copy link
Member

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.

@karenzshea
Copy link
Contributor Author

Also to note: this problem will go away when we remove redundant bool parameters in v6 #3644

@karenzshea karenzshea force-pushed the annotations_type_true branch 2 times, most recently from 84cb198 to 6301e34 Compare February 13, 2017 17:33
@TheMarex TheMarex merged commit e75278f into master Feb 13, 2017
@TheMarex TheMarex deleted the annotations_type_true branch February 13, 2017 18:00
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.

Refactor annotations paramater Failing annotations tests
4 participants