Fixes issues introduced with commit

48c6145bdf
This commit is contained in:
DennisOSRM 2012-10-29 13:24:54 +01:00
parent 4c0203c108
commit 75561b8278
2 changed files with 41 additions and 25 deletions

View File

@ -58,7 +58,7 @@ public:
//decision points have been previously marked //decision points have been previously marked
do { do {
assert(inputVector[leftBorderOfRange].necessary); assert(inputVector[leftBorderOfRange].necessary);
assert(inputVector[inputVector.back()].necessary); assert(inputVector.back().necessary);
if(inputVector[rightBorderOfRange].necessary) { if(inputVector[rightBorderOfRange].necessary) {
recursionStack.push(std::make_pair(leftBorderOfRange, rightBorderOfRange)); recursionStack.push(std::make_pair(leftBorderOfRange, rightBorderOfRange));
@ -75,7 +75,7 @@ public:
assert(inputVector[pair.second].necessary); assert(inputVector[pair.second].necessary);
assert(pair.second < sizeOfInputVector); assert(pair.second < sizeOfInputVector);
assert(pair.first < pair.second); assert(pair.first < pair.second);
int maxDistance = -INT_MIN; int maxDistance = INT_MIN;
std::size_t indexOfFarthestElement = pair.second; std::size_t indexOfFarthestElement = pair.second;
//find index idx of element with maxDistance //find index idx of element with maxDistance
for(std::size_t i = pair.first+1; i < pair.second; ++i){ for(std::size_t i = pair.first+1; i < pair.second; ++i){
@ -102,24 +102,24 @@ public:
* the other distance function. It is an approximation only, but works more or less ok. * the other distance function. It is an approximation only, but works more or less ok.
*/ */
template<class CoordT> template<class CoordT>
double fastDistance(const CoordT& point, const CoordT& segA, const CoordT& segB) { inline int fastDistance(const CoordT& point, const CoordT& segA, const CoordT& segB) const {
int p2x = (segB.lon - segA.lat); const int p2x = (segB.lon - segA.lat);
int p2y = (segB.lon - segA.lat); const int p2y = (segB.lon - segA.lat);
int something = p2x*p2x + p2y*p2y; const int something = p2x*p2x + p2y*p2y;
int u = ((point.lon - segA.lon) * p2x + (point.lat - segA.lat) * p2y) / something; int u = (something < FLT_EPSILON ? 0 : ((point.lon - segA.lon) * p2x + (point.lat - segA.lat) * p2y) / something);
if (u > 1) if (u > 1)
u = 1; u = 1;
else if (u < 0) else if (u < 0)
u = 0; u = 0;
int x = segA.lon + u * p2x; const int x = segA.lon + u * p2x;
int y = segA.lat + u * p2y; const int y = segA.lat + u * p2y;
int dx = x - point.lon; const int dx = x - point.lon;
int dy = y - point.lat; const int dy = y - point.lat;
int dist = (dx*dx + dy*dy); const int dist = (dx*dx + dy*dy);
return dist; return dist;
} }

View File

@ -74,26 +74,42 @@ Feature: Basic Routing
Scenario: 2 unconnected parallel ways Scenario: 2 unconnected parallel ways
Given the node map Given the node map
| a | b | | a | b | c |
| c | d | | d | e | f |
And the ways And the ways
| nodes | | nodes |
| ab | | abc |
| cd | | def |
When I route I should get When I route I should get
| from | to | route | | from | to | route |
| a | b | ab | | a | b | abc |
| b | a | ab | | b | a | abc |
| c | d | cd | | b | c | abc |
| d | c | cd | | c | b | abc |
| a | c | | | d | e | def |
| c | a | | | e | d | def |
| b | d | | | e | f | def |
| d | b | | | f | e | def |
| a | d | | | a | d | |
| d | a | | | d | a | |
| b | d | |
| d | b | |
| c | d | |
| d | c | |
| a | e | |
| e | a | |
| b | e | |
| e | b | |
| c | e | |
| e | c | |
| a | f | |
| f | a | |
| b | f | |
| f | b | |
| c | f | |
| f | c | |
Scenario: 3 ways connected in a triangle Scenario: 3 ways connected in a triangle
Given the node map Given the node map