applied requested changes to EdgeBasedNode.h
This commit is contained in:
parent
b465dabe77
commit
f923f508f5
@ -9,8 +9,6 @@
|
||||
#include "../Util/SimpleLogger.h"
|
||||
#include "../typedefs.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <osrm/Coordinate.h>
|
||||
|
||||
// An EdgeBasedNode represents a node in the edge-expanded graph.
|
||||
@ -41,7 +39,7 @@ struct EdgeBasedNode {
|
||||
) const {
|
||||
BOOST_ASSERT( query_location.isValid() );
|
||||
|
||||
double epsilon = 1.0/COORDINATE_PRECISION;
|
||||
const double epsilon = 1.0/COORDINATE_PRECISION;
|
||||
|
||||
if( ignoreInGrid ) {
|
||||
return std::numeric_limits<double>::max();
|
||||
@ -66,10 +64,9 @@ struct EdgeBasedNode {
|
||||
|
||||
// TODO: Replace with euclidean approximation when k-NN search is done
|
||||
// const double approximated_distance = FixedPointCoordinate::ApproximateEuclideanDistance(
|
||||
const double approximated_distance =
|
||||
FixedPointCoordinate::ApproximateDistance(query_location, nearest_location);
|
||||
const double approximated_distance = FixedPointCoordinate::ApproximateDistance(query_location, nearest_location);
|
||||
|
||||
BOOST_ASSERT( 0. <= approximated_distance );
|
||||
BOOST_ASSERT( 0.0 <= approximated_distance );
|
||||
return approximated_distance;
|
||||
}
|
||||
|
||||
@ -104,34 +101,27 @@ struct EdgeBasedNode {
|
||||
|
||||
private:
|
||||
|
||||
struct Point
|
||||
{
|
||||
const double x;
|
||||
const double y;
|
||||
typedef std::pair<double,double> Point;
|
||||
|
||||
Point(double x, double y)
|
||||
: x(x), y(y) {}
|
||||
};
|
||||
|
||||
// Compute the perpendicular foot of point r on the line defined by p and q.
|
||||
Point ComputePerpendicularFoot(const Point &p, const Point &q, const Point &r, double epsilon) const {
|
||||
|
||||
// the projection of r onto the line pq
|
||||
double foot_x;
|
||||
double foot_y;
|
||||
double foot_x, foot_y;
|
||||
|
||||
const bool parallel_to_y_axis = std::abs(q.x - p.x) < epsilon;
|
||||
const bool is_parallel_to_y_axis = std::abs(q.first - p.first) < epsilon;
|
||||
|
||||
if( parallel_to_y_axis ) {
|
||||
foot_x = q.x;
|
||||
foot_y = r.y;
|
||||
if( is_parallel_to_y_axis ) {
|
||||
foot_x = q.first;
|
||||
foot_y = r.second;
|
||||
} else {
|
||||
// the slope of the line through (a|b) and (c|d)
|
||||
const double m = (q.y - p.y) / (q.x - p.x);
|
||||
const double m = (q.second - p.second) / (q.first - p.first);
|
||||
|
||||
// Projection of (x|y) onto the line joining (a|b) and (c|d).
|
||||
foot_x = ((r.x + (m*r.y)) + (m*m*p.x - m*p.y))/(1.0 + m*m);
|
||||
foot_y = p.y + m*(foot_x - p.x);
|
||||
foot_x = ((r.first + (m*r.second)) + (m*m*p.first - m*p.second))/(1.0 + m*m);
|
||||
foot_y = p.second + m*(foot_x - p.first);
|
||||
}
|
||||
|
||||
return Point(foot_x, foot_y);
|
||||
@ -140,15 +130,15 @@ private:
|
||||
// Compute the ratio of the line segment pr to line segment pq.
|
||||
double ComputeRatio(const Point & p, const Point & q, const Point & r, double epsilon) const {
|
||||
|
||||
const bool parallel_to_x_axis = std::abs(q.y-p.y) < epsilon;
|
||||
const bool parallel_to_y_axis = std::abs(q.x-p.x) < epsilon;
|
||||
const bool is_parallel_to_x_axis = std::abs(q.second-p.second) < epsilon;
|
||||
const bool is_parallel_to_y_axis = std::abs(q.first-p.first) < epsilon;
|
||||
|
||||
double ratio;
|
||||
|
||||
if( !parallel_to_y_axis ) {
|
||||
ratio = (r.x - p.x)/(q.x - p.x);
|
||||
} else if( !parallel_to_x_axis ) {
|
||||
ratio = (r.y - p.y)/(q.y - p.y);
|
||||
if( !is_parallel_to_y_axis ) {
|
||||
ratio = (r.first - p.first)/(q.first - p.first);
|
||||
} else if( !is_parallel_to_x_axis ) {
|
||||
ratio = (r.second - p.second)/(q.second - p.second);
|
||||
} else {
|
||||
// (a|b) and (c|d) are essentially the same point
|
||||
// by convention, we set the ratio to 0 in this case
|
||||
@ -176,8 +166,8 @@ private:
|
||||
return FixedPointCoordinate(lat2, lon2);
|
||||
} else {
|
||||
// r lies between p and q
|
||||
return FixedPointCoordinate(y2lat(r.x)*COORDINATE_PRECISION,
|
||||
r.y*COORDINATE_PRECISION);
|
||||
return FixedPointCoordinate(y2lat(r.first)*COORDINATE_PRECISION,
|
||||
r.second*COORDINATE_PRECISION);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user