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

add display lat lon to locations and use for side of street if provided #1769

Merged
merged 26 commits into from
Jun 18, 2020

Conversation

kevinkreiser
Copy link
Member

this adds display ll to the input location so that in the case that you have both a routing coordinate and a display coordinate you can use the former to control how the route is generated and the latter to control the side of street output (narrative). in the event that a display ll is not provided, the required ll will be used, as it already was, as both the routing and display ll.

throw std::runtime_error{"lon is missing"};
};
Copy link
Member Author

Choose a reason for hiding this comment

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

this was just a simplification of the formatting. was driving me nuts

candidate.get_side(location.display_latlng_ ? *location.display_latlng_ : location.latlng_,
location.display_latlng_
? location.display_latlng_->DistanceSquared(candidate.point)
: candidate.sq_distance);
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the meat of the change. if we provided a display ll we use that in conjunction with its distance from the candidate/snapped location to determine side of street, otherwise we fall back to the previous logic which was to use the input location ll as the display ll as well as the routing ll and its distance from the candidate/snapped location

Copy link
Member Author

Choose a reason for hiding this comment

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

we really should handle that TODO before we ship this need to worry about the case where the display ll isnt really near the route ll

Copy link
Collaborator

Choose a reason for hiding this comment

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

Resolved that TODO in 599ba26. Let me know if that's along the lines of what you were thinking as well.

lon = midgard::circular_range_clamp<float>(*lon, -180, 180);
location->mutable_display_ll()->set_lat(*lat);
location->mutable_display_ll()->set_lng(*lon);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

this is where we parse the request from json into our internal pbf request object

x.display_latlng_ = {answer.first - ortho.x(), answer.second - ortho.y()};
search(x, false, answer,
{PE{{t, l, 3}, ratio, answer, 0, S::LEFT}, PE{{t, l, 8}, 1.f - ratio, answer, 0, S::RIGHT}});

Copy link
Member Author

Choose a reason for hiding this comment

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

what we do here is we take a test for side of street that was relying on the routing ll to determine side of street and we put the routing ll on the road and then set the display ll to what was the routing ll. in this case the display ll is offset perpendicular to the road. we test a display ll on both sides of the road.

dgearhart
dgearhart previously approved these changes Apr 19, 2019
Copy link
Member

@dgearhart dgearhart left a comment

Choose a reason for hiding this comment

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

LGTM - when CI is happy :shipit:

test/search.cc Outdated
search(x, false, answer,
{PE{{t, l, 3}, ratio, answer, 0, S::RIGHT}, PE{{t, l, 8}, 1.f - ratio, answer, 0, S::LEFT}});

// try nuking display ll by setting street_side_max_distance less than display ll distance
Copy link
Collaborator

Choose a reason for hiding this comment

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

Added a test here for street_side_max_distance

@kevinkreiser
Copy link
Member Author

@danpaz im going to answer your question to the outdated comment here so it doesnt get burried.

the default distance seems a bit excessive imho. 5km is a very far distance, maybe something more like 1km? at any rate it does solve part of the problem i was alluding to with that TODO but i should have explained a bit further. let me take a stab at that.

the unexpanded upon part of my worry in that TODO was an angular one. specifically what does "to the right" or "to the left" really mean? geometrically speaking you can say does a point lie on either side of this line (geodesic in our case) by looking at the sign of the area of the triangle formed by the point and 2 points along the line (we have functions for this already). however my intuition tells me that a human will not see it so simply. rather i suspect a human expects a cone to the left or to the right of their position within which they would consider something to the left or to the right of them.

image

so there you can see the tangent at the snap point is red and the cones are blue. geometrically a point inbetween the red and blue would still have a side of street but might be pretty confusing to a person. now you might say, a ha but the snap point is always perpendicular to the display ll so the angle from the snap to the display ll (green dot). that isnt the case sadly. the display ll can be in any orientation to the snap point. the snap point is usually (but also not always) perpendicular to the input ll but the display ll is any random ll that is provided.

so anyway i think we need to do one more thing:

  1. measure the aboslute angle of the tangent at the snap point (in the example image above its about 45)
  2. measure the absolute angle between the snap point and the display ll (in the example image its 135)
  3. put a cone (some slack) around right_center = tangent_angle + 90 and around left_center = tangent_angle - 90`
  4. and check that the angle mesasured in #2 is in either the right or left cone

Comment on lines 142 to 144
// add 360 degrees if angle becomes negative
auto angle_diff = (angle_to_point - tang_angle) >= 0.0f ? (angle_to_point - tang_angle)
: (angle_to_point - tang_angle + 360.0f);
Copy link
Member Author

@kevinkreiser kevinkreiser Jun 15, 2020

Choose a reason for hiding this comment

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

i think this can be:

auto angle_diff = angle_to_point - tang_angle;
if(angle_diff < 0.f) {
  angle_diff += 360.f;
}

…5000m as some tests use points > 1000m away from the road
src/loki/search.cc Outdated Show resolved Hide resolved
src/loki/search.cc Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
size_t index = edge->forward() ? 0 : info.shape().size() - 2;
float angle =
tangent_angle(index, candidate.point, info.shape(),
GetOffsetForHeading(edge->classification(), edge->use()), edge->forward());
Copy link
Member Author

Choose a reason for hiding this comment

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

well this is unfortunate, but correct. we need to measure the tangent at the node for every edge. this means a bunch of tangent checks. if performance doesnt check out we shoudl think about putting the distance check first before the tangent... but then we have the fact that heading might need it... gah, lets see what performance numbers say before we complicate our lives..

@kevinkreiser
Copy link
Member Author

@danpaz well i went to leave a reivew on this and then remember i made this PR originally....

anyway my review is: Approved pending performance regression testing

@danpaz
Copy link
Collaborator

danpaz commented Jun 18, 2020

master

$ ./valhalla_benchmark_loki --config ../local/valhalla-utrecht.json -t 4 -i 100 -b 1 -r 0 ../local/scripts/benchmark_loki/coords.txt
2020/06/18 14:34:47.612565 [ERROR] (stat): /Users/danielpaz-soldan/code/valhalla/local/regions/norcal.tard No such file or directory
2020/06/18 14:34:47.612778 [WARN] Tile extract could not be loaded
2020/06/18 14:35:03.354841 [INFO] Succeeded Searches on Uncached Tiles
2020/06/18 14:35:03.354866 [INFO] --------------------------------
2020/06/18 14:35:03.354876 [INFO] Total: 2993
2020/06/18 14:35:03.354884 [INFO] Fastest: 5ms (5.000000ms per)
2020/06/18 14:35:03.354888 [INFO] Slowest: 137ms (137.000000ms per)
2020/06/18 14:35:03.354891 [INFO] Median: 9.985633ms
2020/06/18 14:35:03.354894 [INFO] Standard Deviation: 4.267468ms
2020/06/18 14:35:03.354897 [INFO] Faster Than 1 Standard Deviation: 8
2020/06/18 14:35:03.354900 [INFO] Slower Than 1 Standard Deviation: 296
2020/06/18 14:35:03.354902 [INFO] --------------------------------


2020/06/18 14:35:03.355127 [INFO] Failed Searches on Uncached Tiles
2020/06/18 14:35:03.355131 [INFO] --------------------------------
2020/06/18 14:35:03.355134 [INFO] No results
2020/06/18 14:35:03.355136 [INFO] --------------------------------


2020/06/18 14:35:03.355371 [INFO] Succeeded Searches on Cached Tiles
2020/06/18 14:35:03.355375 [INFO] --------------------------------
2020/06/18 14:35:03.355378 [INFO] Total: 2993
2020/06/18 14:35:03.355381 [INFO] Fastest: 5ms (5.000000ms per)
2020/06/18 14:35:03.355385 [INFO] Slowest: 178ms (178.000000ms per)
2020/06/18 14:35:03.355388 [INFO] Median: 10.050117ms
2020/06/18 14:35:03.355391 [INFO] Standard Deviation: 5.983229ms
2020/06/18 14:35:03.355393 [INFO] Faster Than 1 Standard Deviation: 0
2020/06/18 14:35:03.355396 [INFO] Slower Than 1 Standard Deviation: 143
2020/06/18 14:35:03.355398 [INFO] --------------------------------


2020/06/18 14:35:03.355710 [INFO] Failed Searches on Cached Tiles
2020/06/18 14:35:03.355719 [INFO] --------------------------------
2020/06/18 14:35:03.355723 [INFO] No results
2020/06/18 14:35:03.355727 [INFO] --------------------------------
$ ./valhalla_benchmark_loki --config ../local/valhalla-utrecht.json -t 4 -i 100 -b 1 -r 0 ../local/scripts/benchmark_loki/coords.txt
2020/06/18 14:35:35.138412 [ERROR] (stat): /Users/danielpaz-soldan/code/valhalla/local/regions/norcal.tard No such file or directory
2020/06/18 14:35:35.138621 [WARN] Tile extract could not be loaded
2020/06/18 14:35:51.255341 [INFO] Succeeded Searches on Uncached Tiles
2020/06/18 14:35:51.255363 [INFO] --------------------------------
2020/06/18 14:35:51.255373 [INFO] Total: 2993
2020/06/18 14:35:51.255382 [INFO] Fastest: 5ms (5.000000ms per)
2020/06/18 14:35:51.255386 [INFO] Slowest: 169ms (169.000000ms per)
2020/06/18 14:35:51.255389 [INFO] Median: 10.137989ms
2020/06/18 14:35:51.255392 [INFO] Standard Deviation: 5.734580ms
2020/06/18 14:35:51.255395 [INFO] Faster Than 1 Standard Deviation: 0
2020/06/18 14:35:51.255398 [INFO] Slower Than 1 Standard Deviation: 197
2020/06/18 14:35:51.255400 [INFO] --------------------------------


2020/06/18 14:35:51.255628 [INFO] Failed Searches on Uncached Tiles
2020/06/18 14:35:51.255632 [INFO] --------------------------------
2020/06/18 14:35:51.255635 [INFO] No results
2020/06/18 14:35:51.255638 [INFO] --------------------------------


2020/06/18 14:35:51.255879 [INFO] Succeeded Searches on Cached Tiles
2020/06/18 14:35:51.255884 [INFO] --------------------------------
2020/06/18 14:35:51.255887 [INFO] Total: 2993
2020/06/18 14:35:51.255890 [INFO] Fastest: 5ms (5.000000ms per)
2020/06/18 14:35:51.255893 [INFO] Slowest: 174ms (174.000000ms per)
2020/06/18 14:35:51.255896 [INFO] Median: 10.392249ms
2020/06/18 14:35:51.255899 [INFO] Standard Deviation: 7.000728ms
2020/06/18 14:35:51.255902 [INFO] Faster Than 1 Standard Deviation: 0
2020/06/18 14:35:51.255904 [INFO] Slower Than 1 Standard Deviation: 109
2020/06/18 14:35:51.255907 [INFO] --------------------------------


2020/06/18 14:35:51.256164 [INFO] Failed Searches on Cached Tiles
2020/06/18 14:35:51.256175 [INFO] --------------------------------
2020/06/18 14:35:51.256179 [INFO] No results
2020/06/18 14:35:51.256182 [INFO] --------------------------------

kk_display

$ ./valhalla_benchmark_loki --config ../local/valhalla-utrecht.json -t 4 -i 100 -b 1 -r 0 ../local/scripts/benchmark_loki/coords.txt
2020/06/18 14:44:21.600947 [ERROR] (stat): /Users/danielpaz-soldan/code/valhalla/local/regions/norcal.tard No such file or directory
2020/06/18 14:44:21.601181 [WARN] Tile extract could not be loaded
2020/06/18 14:44:37.515735 [INFO] Succeeded Searches on Uncached Tiles
2020/06/18 14:44:37.515760 [INFO] --------------------------------
2020/06/18 14:44:37.515773 [INFO] Total: 2993
2020/06/18 14:44:37.515781 [INFO] Fastest: 5ms (5.000000ms per)
2020/06/18 14:44:37.515788 [INFO] Slowest: 169ms (169.000000ms per)
2020/06/18 14:44:37.515792 [INFO] Median: 10.126629ms
2020/06/18 14:44:37.515796 [INFO] Standard Deviation: 6.622033ms
2020/06/18 14:44:37.515800 [INFO] Faster Than 1 Standard Deviation: 0
2020/06/18 14:44:37.515803 [INFO] Slower Than 1 Standard Deviation: 138
2020/06/18 14:44:37.515807 [INFO] --------------------------------


2020/06/18 14:44:37.516060 [INFO] Failed Searches on Uncached Tiles
2020/06/18 14:44:37.516068 [INFO] --------------------------------
2020/06/18 14:44:37.516073 [INFO] No results
2020/06/18 14:44:37.516076 [INFO] --------------------------------


2020/06/18 14:44:37.516360 [INFO] Succeeded Searches on Cached Tiles
2020/06/18 14:44:37.516368 [INFO] --------------------------------
2020/06/18 14:44:37.516669 [INFO] Total: 2993
2020/06/18 14:44:37.516676 [INFO] Fastest: 5ms (5.000000ms per)
2020/06/18 14:44:37.516682 [INFO] Slowest: 150ms (150.000000ms per)
2020/06/18 14:44:37.516687 [INFO] Median: 10.127965ms
2020/06/18 14:44:37.516692 [INFO] Standard Deviation: 5.768099ms
2020/06/18 14:44:37.516697 [INFO] Faster Than 1 Standard Deviation: 0
2020/06/18 14:44:37.516701 [INFO] Slower Than 1 Standard Deviation: 211
2020/06/18 14:44:37.516705 [INFO] --------------------------------


2020/06/18 14:44:37.517047 [INFO] Failed Searches on Cached Tiles
2020/06/18 14:44:37.517058 [INFO] --------------------------------
2020/06/18 14:44:37.517063 [INFO] No results
2020/06/18 14:44:37.517067 [INFO] --------------------------------
$ ./valhalla_benchmark_loki --config ../local/valhalla-utrecht.json -t 4 -i 100 -b 1 -r 0 ../local/scripts/benchmark_loki/coords.txt
2020/06/18 14:44:53.135111 [ERROR] (stat): /Users/danielpaz-soldan/code/valhalla/local/regions/norcal.tard No such file or directory
2020/06/18 14:44:53.135335 [WARN] Tile extract could not be loaded
2020/06/18 14:45:08.984496 [INFO] Succeeded Searches on Uncached Tiles
2020/06/18 14:45:08.984522 [INFO] --------------------------------
2020/06/18 14:45:08.984532 [INFO] Total: 2993
2020/06/18 14:45:08.984538 [INFO] Fastest: 5ms (5.000000ms per)
2020/06/18 14:45:08.984544 [INFO] Slowest: 177ms (177.000000ms per)
2020/06/18 14:45:08.984547 [INFO] Median: 10.121617ms
2020/06/18 14:45:08.984550 [INFO] Standard Deviation: 6.694312ms
2020/06/18 14:45:08.984553 [INFO] Faster Than 1 Standard Deviation: 0
2020/06/18 14:45:08.984556 [INFO] Slower Than 1 Standard Deviation: 142
2020/06/18 14:45:08.984559 [INFO] --------------------------------


2020/06/18 14:45:08.984777 [INFO] Failed Searches on Uncached Tiles
2020/06/18 14:45:08.984781 [INFO] --------------------------------
2020/06/18 14:45:08.984783 [INFO] No results
2020/06/18 14:45:08.984786 [INFO] --------------------------------


2020/06/18 14:45:08.985017 [INFO] Succeeded Searches on Cached Tiles
2020/06/18 14:45:08.985020 [INFO] --------------------------------
2020/06/18 14:45:08.985023 [INFO] Total: 2993
2020/06/18 14:45:08.985027 [INFO] Fastest: 5ms (5.000000ms per)
2020/06/18 14:45:08.985030 [INFO] Slowest: 145ms (145.000000ms per)
2020/06/18 14:45:08.985033 [INFO] Median: 10.052790ms
2020/06/18 14:45:08.985036 [INFO] Standard Deviation: 5.889892ms
2020/06/18 14:45:08.985039 [INFO] Faster Than 1 Standard Deviation: 0
2020/06/18 14:45:08.985042 [INFO] Slower Than 1 Standard Deviation: 199
2020/06/18 14:45:08.985044 [INFO] --------------------------------


2020/06/18 14:45:08.985254 [INFO] Failed Searches on Cached Tiles
2020/06/18 14:45:08.985257 [INFO] --------------------------------
2020/06/18 14:45:08.985259 [INFO] No results
2020/06/18 14:45:08.985262 [INFO] --------------------------------

Copy link
Collaborator

@danpaz danpaz left a comment

Choose a reason for hiding this comment

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

Approving on @kevinkreiser 's behalf

@danpaz danpaz merged commit d51152a into master Jun 18, 2020
@danpaz danpaz deleted the kk_display branch June 18, 2020 15:47
yuzheyan added a commit that referenced this pull request Jun 23, 2020
* master:
  Protect against nan in uniform_resample_spherical_polyline (#2431)
  Update config.h.cmake
  nit: Adds missing cmake dependency for benchmarks (#2430)
  add display lat lon to locations and use for side of street if provided (#1769)
  Fixes includes for projects using Valhalla as a library (#2423)
  Add additional exit phrases (#2421)
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.

None yet

4 participants