actually calculate distance instead of using .distance which is a timing value

This commit is contained in:
Moritz Kobitzsch 2016-10-20 12:15:36 +02:00
parent 5e167b8745
commit ecee13bffa
11 changed files with 111 additions and 6 deletions

View File

@ -19,6 +19,7 @@
- Bugfixes - Bugfixes
- fixed a bug where polyline decoding on a defective polyline could end up in out-of-bound access on a vector - fixed a bug where polyline decoding on a defective polyline could end up in out-of-bound access on a vector
- fixed compile errors in tile unit-test framework - fixed compile errors in tile unit-test framework
- fixed a bug that could result in inconsistent behaviour when collapsing instructions
- Debug Tiles - Debug Tiles
- Added support for turn penalties - Added support for turn penalties

View File

@ -3,6 +3,7 @@ Feature: Car - Street names in instructions
Background: Background:
Given the profile "car" Given the profile "car"
Given a grid size of 5 meters
Scenario: Car - A named street Scenario: Car - A named street
Given the node map Given the node map

View File

@ -34,6 +34,36 @@ Feature: Slipways and Dedicated Turn Lanes
| a,g | first,second,second | depart,turn right,arrive | | a,g | first,second,second | depart,turn right,arrive |
| a,1 | first,, | depart,turn slight right,arrive | | a,1 | first,, | depart,turn slight right,arrive |
Scenario: Turn Instead of Ramp - Max-Speed
Given the node map
"""
e
a-b-----c-d
`h |
||
1||
`|
f
|
g
"""
And the ways
| nodes | highway | name | maxspeed |
| abcd | trunk | first | 70 |
| bhf | trunk_link | | 2 |
| ecfg | primary | second | 50 |
And the relations
| type | way:from | way:to | node:via | restriction |
| restriction | abcd | ecfg | c | no_right_turn |
When I route I should get
| waypoints | route | turns |
| a,g | first,second,second | depart,turn right,arrive |
| a,1 | first,, | depart,turn slight right,arrive |
Scenario: Turn Instead of Ramp Scenario: Turn Instead of Ramp
Given the node map Given the node map
""" """

View File

@ -511,7 +511,7 @@ Feature: Turn Lane Guidance
g g
c c
a b d e a b d e
f f
""" """
@ -523,8 +523,8 @@ Feature: Turn Lane Guidance
| bc | road | left\|left | yes | primary | | bc | road | left\|left | yes | primary |
| de | road | | yes | primary | | de | road | | yes | primary |
| fd | cross | | | secondary | | fd | cross | | | secondary |
| dc | cross | | | secondary | | dc | cross | | | secondary |
| cg | cross | | | secondary | | cg | cross | | | secondary |
And the relations And the relations
| type | way:from | way:to | node:via | restriction | | type | way:from | way:to | node:via | restriction |
@ -897,6 +897,29 @@ Feature: Turn Lane Guidance
| x,d | road,road | depart,arrive | , | | x,d | road,road | depart,arrive | , |
@partition-lanes @partition-lanes
Scenario: Partitioned turn, Slight Curve - maxspeed
Given the node map
"""
f e
| |
| |
| c
a - b ' |
g d
"""
And the ways
| nodes | name | highway | oneway | turn:lanes:forward | maxspeed |
| ab | road | primary | yes | left\|right | 1 |
| bc | cross | primary | yes | | 1 |
| fbg | cross | primary | yes | | 1 |
| dce | cross | primary | yes | | 1 |
When I route I should get
| waypoints | route | turns | lanes |
| a,g | road,cross,cross | depart,turn right,arrive | ,left:false right:true, |
| a,e | road,cross,cross | depart,turn left,arrive | ,left:true right:false, |
Scenario: Partitioned turn, Slight Curve Scenario: Partitioned turn, Slight Curve
Given the node map Given the node map
""" """

View File

@ -40,6 +40,11 @@ class CoordinateExtractor
const bool traversed_in_reverse, const bool traversed_in_reverse,
const NodeID to_node) const; const NodeID to_node) const;
// wrapper in case of normal forward edges (traversed_in_reverse = false, to_node =
// node_based_graph.GetTarget(turn_edge)
std::vector<util::Coordinate> GetForwardCoordinatesAlongRoad(const NodeID from,
const EdgeID turn_edge) const;
/* When extracting the coordinates, we first extract all coordinates. We don't care about most /* When extracting the coordinates, we first extract all coordinates. We don't care about most
* of them, though. * of them, though.
* *

View File

@ -47,6 +47,9 @@ class IntersectionGenerator
NodeID *resulting_from_node, NodeID *resulting_from_node,
EdgeID *resulting_via_edge) const; EdgeID *resulting_via_edge) const;
// Allow access to the coordinate extractor for all owners
const CoordinateExtractor &GetCoordinateExtractor() const;
private: private:
const util::NodeBasedDynamicGraph &node_based_graph; const util::NodeBasedDynamicGraph &node_based_graph;
const RestrictionMap &restriction_map; const RestrictionMap &restriction_map;

View File

@ -5,7 +5,9 @@
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <algorithm>
#include <utility> #include <utility>
#include <vector>
namespace osrm namespace osrm
{ {
@ -30,6 +32,24 @@ double haversineDistance(const Coordinate first_coordinate, const Coordinate sec
double greatCircleDistance(const Coordinate first_coordinate, const Coordinate second_coordinate); double greatCircleDistance(const Coordinate first_coordinate, const Coordinate second_coordinate);
// get the length of a full coordinate vector, using one of our basic functions to compute distances
template <class BinaryOperation>
double getLength(const std::vector<Coordinate> &coordinates, BinaryOperation op)
{
if (coordinates.empty())
return 0.;
double result = 0;
const auto functor = [&result, op](const Coordinate lhs, const Coordinate rhs) {
result += op(lhs, rhs);
return false;
};
// side-effect find adding up distances
std::adjacent_find(coordinates.begin(), coordinates.end(), functor);
return result;
}
// Find the closest distance and location between coordinate and the line connecting source and // Find the closest distance and location between coordinate and the line connecting source and
// target: // target:
// coordinate // coordinate

View File

@ -298,6 +298,12 @@ CoordinateExtractor::GetCoordinateAlongRoad(const NodeID intersection_node,
return TrimCoordinatesToLength(coordinates, LOOKAHEAD_DISTANCE_WITHOUT_LANES).back(); return TrimCoordinatesToLength(coordinates, LOOKAHEAD_DISTANCE_WITHOUT_LANES).back();
} }
std::vector<util::Coordinate>
CoordinateExtractor::GetForwardCoordinatesAlongRoad(const NodeID from, const EdgeID turn_edge) const
{
return GetCoordinatesAlongRoad(from, turn_edge, false, node_based_graph.GetTarget(turn_edge));
}
std::vector<util::Coordinate> std::vector<util::Coordinate>
CoordinateExtractor::GetCoordinatesAlongRoad(const NodeID intersection_node, CoordinateExtractor::GetCoordinatesAlongRoad(const NodeID intersection_node,
const EdgeID turn_edge, const EdgeID turn_edge,

View File

@ -649,6 +649,12 @@ IntersectionGenerator::GetActualNextIntersection(const NodeID starting_node,
return result; return result;
} }
const CoordinateExtractor&
IntersectionGenerator::GetCoordinateExtractor() const
{
return coordinate_extractor;
}
} // namespace guidance } // namespace guidance
} // namespace extractor } // namespace extractor
} // namespace osrm } // namespace osrm

View File

@ -162,8 +162,12 @@ operator()(const NodeID, const EdgeID source_edge_id, Intersection intersection)
return intersection; return intersection;
// Threshold check, if the intersection is too far away, don't bother continuing // Threshold check, if the intersection is too far away, don't bother continuing
const auto &next_road_data = node_based_graph.GetEdgeData(next_road.turn.eid); const auto coordinate_extractor = intersection_generator.GetCoordinateExtractor();
if (next_road_data.distance > MAX_SLIPROAD_THRESHOLD) const auto next_road_length = util::coordinate_calculation::getLength(
coordinate_extractor.GetForwardCoordinatesAlongRoad(
node_based_graph.GetTarget(source_edge_id), next_road.turn.eid),
&util::coordinate_calculation::haversineDistance);
if (next_road_length > MAX_SLIPROAD_THRESHOLD)
{ {
return intersection; return intersection;
} }

View File

@ -1,5 +1,6 @@
#include "extractor/guidance/turn_discovery.hpp" #include "extractor/guidance/turn_discovery.hpp"
#include "extractor/guidance/constants.hpp" #include "extractor/guidance/constants.hpp"
#include "util/coordinate_calculation.hpp"
namespace osrm namespace osrm
{ {
@ -34,9 +35,14 @@ bool findPreviousIntersection(const NodeID node_v,
*/ */
const constexpr double COMBINE_DISTANCE_CUTOFF = 30; const constexpr double COMBINE_DISTANCE_CUTOFF = 30;
const auto coordinate_extractor = turn_analysis.getGenerator().GetCoordinateExtractor();
const auto via_edge_length = util::coordinate_calculation::getLength(
coordinate_extractor.GetForwardCoordinatesAlongRoad(node_v, via_edge),
&util::coordinate_calculation::haversineDistance);
// we check if via-edge is too short. In this case the previous turn cannot influence the turn // we check if via-edge is too short. In this case the previous turn cannot influence the turn
// at via_edge and the intersection at NODE_W // at via_edge and the intersection at NODE_W
if (node_based_graph.GetEdgeData(via_edge).distance > COMBINE_DISTANCE_CUTOFF) if (via_edge_length > COMBINE_DISTANCE_CUTOFF)
return false; return false;
// Node -> Via_Edge -> Intersection[0 == UTURN] -> reverse_of(via_edge) -> Intersection at node // Node -> Via_Edge -> Intersection[0 == UTURN] -> reverse_of(via_edge) -> Intersection at node