Refactoring _Coordinate class
This commit is contained in:
+12
-12
@@ -18,8 +18,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
#ifndef COORDINATE_H_
|
||||
#define COORDINATE_H_
|
||||
#ifndef FIXED_POINT_COORDINATE_H_
|
||||
#define FIXED_POINT_COORDINATE_H_
|
||||
|
||||
#include "../Util/StringUtil.h"
|
||||
|
||||
@@ -31,11 +31,11 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
static const double COORDINATE_PRECISION = 1000000.;
|
||||
|
||||
struct _Coordinate {
|
||||
struct FixedPointCoordinate {
|
||||
int lat;
|
||||
int lon;
|
||||
_Coordinate () : lat(INT_MIN), lon(INT_MIN) {}
|
||||
explicit _Coordinate (int t, int n) : lat(t) , lon(n) {}
|
||||
FixedPointCoordinate () : lat(INT_MIN), lon(INT_MIN) {}
|
||||
explicit FixedPointCoordinate (int t, int n) : lat(t) , lon(n) {}
|
||||
|
||||
void Reset() {
|
||||
lat = INT_MIN;
|
||||
@@ -55,12 +55,12 @@ struct _Coordinate {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool operator==(const _Coordinate & other) const {
|
||||
bool operator==(const FixedPointCoordinate & other) const {
|
||||
return lat == other.lat && lon == other.lon;
|
||||
}
|
||||
};
|
||||
|
||||
inline std::ostream & operator<<(std::ostream & out, const _Coordinate & c){
|
||||
inline std::ostream & operator<<(std::ostream & out, const FixedPointCoordinate & c){
|
||||
out << "(" << c.lat << "," << c.lon << ")";
|
||||
return out;
|
||||
}
|
||||
@@ -93,11 +93,11 @@ inline double ApproximateDistance( const int lat1, const int lon1, const int lat
|
||||
return distance;
|
||||
}
|
||||
|
||||
inline double ApproximateDistance(const _Coordinate &c1, const _Coordinate &c2) {
|
||||
inline double ApproximateDistance(const FixedPointCoordinate &c1, const FixedPointCoordinate &c2) {
|
||||
return ApproximateDistance( c1.lat, c1.lon, c2.lat, c2.lon );
|
||||
}
|
||||
|
||||
inline double ApproximateEuclideanDistance(const _Coordinate &c1, const _Coordinate &c2) {
|
||||
inline double ApproximateEuclideanDistance(const FixedPointCoordinate &c1, const FixedPointCoordinate &c2) {
|
||||
assert(c1.lat != INT_MIN);
|
||||
assert(c1.lon != INT_MIN);
|
||||
assert(c2.lat != INT_MIN);
|
||||
@@ -122,7 +122,7 @@ static inline void convertInternalLatLonToString(const int value, std::string &
|
||||
output = string;
|
||||
}
|
||||
|
||||
static inline void convertInternalCoordinateToString(const _Coordinate & coord, std::string & output) {
|
||||
static inline void convertInternalCoordinateToString(const FixedPointCoordinate & coord, std::string & output) {
|
||||
std::string tmp;
|
||||
convertInternalLatLonToString(coord.lon, tmp);
|
||||
output = tmp;
|
||||
@@ -131,7 +131,7 @@ static inline void convertInternalCoordinateToString(const _Coordinate & coord,
|
||||
output += tmp;
|
||||
output += " ";
|
||||
}
|
||||
static inline void convertInternalReversedCoordinateToString(const _Coordinate & coord, std::string & output) {
|
||||
static inline void convertInternalReversedCoordinateToString(const FixedPointCoordinate & coord, std::string & output) {
|
||||
std::string tmp;
|
||||
convertInternalLatLonToString(coord.lat, tmp);
|
||||
output = tmp;
|
||||
@@ -141,4 +141,4 @@ static inline void convertInternalReversedCoordinateToString(const _Coordinate &
|
||||
output += " ";
|
||||
}
|
||||
|
||||
#endif /* COORDINATE_H_ */
|
||||
#endif /* FIXED_POINT_COORDINATE_H_ */
|
||||
|
||||
@@ -31,7 +31,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
class HilbertCode : boost::noncopyable {
|
||||
public:
|
||||
static uint64_t GetHilbertNumberForCoordinate(
|
||||
const _Coordinate & current_coordinate) {
|
||||
const FixedPointCoordinate & current_coordinate
|
||||
) {
|
||||
unsigned location[2];
|
||||
location[0] = current_coordinate.lat+( 90*COORDINATE_PRECISION);
|
||||
location[1] = current_coordinate.lon+(180*COORDINATE_PRECISION);
|
||||
|
||||
@@ -107,8 +107,8 @@ public:
|
||||
}
|
||||
|
||||
inline bool FindNearestNodeCoordForLatLon(
|
||||
const _Coordinate& input_coordinate,
|
||||
_Coordinate& result,
|
||||
const FixedPointCoordinate& input_coordinate,
|
||||
FixedPointCoordinate& result,
|
||||
const unsigned zoom_level = 18
|
||||
) const {
|
||||
PhantomNode resulting_phantom_node;
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
}
|
||||
|
||||
inline bool FindPhantomNodeForCoordinate(
|
||||
const _Coordinate & input_coordinate,
|
||||
const FixedPointCoordinate & input_coordinate,
|
||||
PhantomNode & resulting_phantom_node,
|
||||
const unsigned zoom_level
|
||||
) const {
|
||||
@@ -164,9 +164,9 @@ private:
|
||||
NodeInfo b;
|
||||
while(!nodes_input_stream.eof()) {
|
||||
nodes_input_stream.read((char *)&b, sizeof(NodeInfo));
|
||||
coordinateVector.push_back(_Coordinate(b.lat, b.lon));
|
||||
coordinateVector.push_back(FixedPointCoordinate(b.lat, b.lon));
|
||||
}
|
||||
std::vector<_Coordinate>(coordinateVector).swap(coordinateVector);
|
||||
std::vector<FixedPointCoordinate>(coordinateVector).swap(coordinateVector);
|
||||
nodes_input_stream.close();
|
||||
|
||||
SimpleLogger().Write(logDEBUG) << "Loading edge data";
|
||||
@@ -191,7 +191,7 @@ private:
|
||||
SimpleLogger().Write(logDEBUG) << "Opening NN indices";
|
||||
}
|
||||
|
||||
std::vector<_Coordinate> coordinateVector;
|
||||
std::vector<FixedPointCoordinate> coordinateVector;
|
||||
std::vector<NodeID> origEdgeData_viaNode;
|
||||
std::vector<unsigned> origEdgeData_nameID;
|
||||
std::vector<TurnInstruction> origEdgeData_turnInstruction;
|
||||
|
||||
@@ -24,13 +24,20 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "Coordinate.h"
|
||||
|
||||
struct PhantomNode {
|
||||
PhantomNode() : edgeBasedNode(UINT_MAX), nodeBasedEdgeNameID(UINT_MAX), weight1(INT_MAX), weight2(INT_MAX), ratio(0.) {}
|
||||
PhantomNode() :
|
||||
edgeBasedNode(UINT_MAX),
|
||||
nodeBasedEdgeNameID(UINT_MAX),
|
||||
weight1(INT_MAX),
|
||||
weight2(INT_MAX),
|
||||
ratio(0.)
|
||||
{ }
|
||||
|
||||
NodeID edgeBasedNode;
|
||||
unsigned nodeBasedEdgeNameID;
|
||||
int weight1;
|
||||
int weight2;
|
||||
double ratio;
|
||||
_Coordinate location;
|
||||
FixedPointCoordinate location;
|
||||
void Reset() {
|
||||
edgeBasedNode = UINT_MAX;
|
||||
nodeBasedEdgeNameID = UINT_MAX;
|
||||
@@ -88,7 +95,7 @@ inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn){
|
||||
struct NodesOfEdge {
|
||||
NodeID edgeBasedNode;
|
||||
double ratio;
|
||||
_Coordinate projectedPoint;
|
||||
FixedPointCoordinate projectedPoint;
|
||||
};
|
||||
|
||||
#endif /* PHANTOMNODES_H_ */
|
||||
|
||||
@@ -33,14 +33,14 @@ SearchEngine::SearchEngine(
|
||||
|
||||
void SearchEngine::GetCoordinatesForNodeID(
|
||||
NodeID id,
|
||||
_Coordinate& result
|
||||
FixedPointCoordinate& result
|
||||
) const {
|
||||
result.lat = _queryData.nodeHelpDesk->getLatitudeOfNode(id);
|
||||
result.lon = _queryData.nodeHelpDesk->getLongitudeOfNode(id);
|
||||
}
|
||||
|
||||
void SearchEngine::FindPhantomNodeForCoordinate(
|
||||
const _Coordinate & location,
|
||||
const FixedPointCoordinate & location,
|
||||
PhantomNode & result,
|
||||
const unsigned zoomLevel
|
||||
) const {
|
||||
|
||||
@@ -45,17 +45,17 @@ public:
|
||||
AlternativeRouting<SearchEngineData> alternativePaths;
|
||||
|
||||
SearchEngine(
|
||||
QueryGraph * g,
|
||||
NodeInformationHelpDesk * nh,
|
||||
QueryGraph * g,
|
||||
NodeInformationHelpDesk * nh,
|
||||
std::vector<std::string> & n
|
||||
);
|
||||
~SearchEngine();
|
||||
|
||||
void GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const;
|
||||
void GetCoordinatesForNodeID(NodeID id, FixedPointCoordinate& result) const;
|
||||
|
||||
void FindPhantomNodeForCoordinate(
|
||||
const _Coordinate & location,
|
||||
PhantomNode & result,
|
||||
const FixedPointCoordinate & location,
|
||||
PhantomNode & result,
|
||||
unsigned zoomLevel
|
||||
) const;
|
||||
|
||||
|
||||
@@ -27,16 +27,16 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include <climits>
|
||||
|
||||
struct SegmentInformation {
|
||||
_Coordinate location;
|
||||
FixedPointCoordinate location;
|
||||
NodeID nameID;
|
||||
double length;
|
||||
unsigned duration;
|
||||
double bearing;
|
||||
TurnInstruction turnInstruction;
|
||||
bool necessary;
|
||||
SegmentInformation(const _Coordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr, const bool nec) :
|
||||
SegmentInformation(const FixedPointCoordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr, const bool nec) :
|
||||
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(nec) {}
|
||||
SegmentInformation(const _Coordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr) :
|
||||
SegmentInformation(const FixedPointCoordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr) :
|
||||
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(tInstr != 0) {}
|
||||
};
|
||||
|
||||
|
||||
@@ -100,8 +100,8 @@ private:
|
||||
max_lat = std::max(max_lat, other.max_lat);
|
||||
}
|
||||
|
||||
inline _Coordinate Centroid() const {
|
||||
_Coordinate centroid;
|
||||
inline FixedPointCoordinate Centroid() const {
|
||||
FixedPointCoordinate centroid;
|
||||
//The coordinates of the midpoints are given by:
|
||||
//x = (x1 + x2) /2 and y = (y1 + y2) /2.
|
||||
centroid.lon = (min_lon + max_lon)/2;
|
||||
@@ -110,10 +110,10 @@ private:
|
||||
}
|
||||
|
||||
inline bool Intersects(const RectangleInt2D & other) const {
|
||||
_Coordinate upper_left (other.max_lat, other.min_lon);
|
||||
_Coordinate upper_right(other.max_lat, other.max_lon);
|
||||
_Coordinate lower_right(other.min_lat, other.max_lon);
|
||||
_Coordinate lower_left (other.min_lat, other.min_lon);
|
||||
FixedPointCoordinate upper_left (other.max_lat, other.min_lon);
|
||||
FixedPointCoordinate upper_right(other.max_lat, other.max_lon);
|
||||
FixedPointCoordinate lower_right(other.min_lat, other.max_lon);
|
||||
FixedPointCoordinate lower_left (other.min_lat, other.min_lon);
|
||||
|
||||
return (
|
||||
Contains(upper_left)
|
||||
@@ -123,7 +123,7 @@ private:
|
||||
);
|
||||
}
|
||||
|
||||
inline double GetMinDist(const _Coordinate & location) const {
|
||||
inline double GetMinDist(const FixedPointCoordinate & location) const {
|
||||
bool is_contained = Contains(location);
|
||||
if (is_contained) {
|
||||
return 0.0;
|
||||
@@ -169,13 +169,13 @@ private:
|
||||
return min_dist;
|
||||
}
|
||||
|
||||
inline double GetMinMaxDist(const _Coordinate & location) const {
|
||||
inline double GetMinMaxDist(const FixedPointCoordinate & location) const {
|
||||
double min_max_dist = DBL_MAX;
|
||||
//Get minmax distance to each of the four sides
|
||||
_Coordinate upper_left (max_lat, min_lon);
|
||||
_Coordinate upper_right(max_lat, max_lon);
|
||||
_Coordinate lower_right(min_lat, max_lon);
|
||||
_Coordinate lower_left (min_lat, min_lon);
|
||||
FixedPointCoordinate upper_left (max_lat, min_lon);
|
||||
FixedPointCoordinate upper_right(max_lat, max_lon);
|
||||
FixedPointCoordinate lower_right(min_lat, max_lon);
|
||||
FixedPointCoordinate lower_left (min_lat, min_lon);
|
||||
|
||||
min_max_dist = std::min(
|
||||
min_max_dist,
|
||||
@@ -211,7 +211,7 @@ private:
|
||||
return min_max_dist;
|
||||
}
|
||||
|
||||
inline bool Contains(const _Coordinate & location) const {
|
||||
inline bool Contains(const FixedPointCoordinate & location) const {
|
||||
bool lats_contained =
|
||||
(location.lat > min_lat) && (location.lat < max_lat);
|
||||
bool lons_contained =
|
||||
@@ -303,7 +303,7 @@ public:
|
||||
input_wrapper_vector[element_counter].m_array_index = element_counter;
|
||||
//Get Hilbert-Value for centroid in mercartor projection
|
||||
DataT & current_element = input_data_vector[element_counter];
|
||||
_Coordinate current_centroid = current_element.Centroid();
|
||||
FixedPointCoordinate current_centroid = current_element.Centroid();
|
||||
current_centroid.lat = COORDINATE_PRECISION*lat2y(current_centroid.lat/COORDINATE_PRECISION);
|
||||
|
||||
uint64_t current_hilbert_value = HilbertCode::GetHilbertNumberForCoordinate(current_centroid);
|
||||
@@ -449,7 +449,7 @@ public:
|
||||
}
|
||||
/*
|
||||
inline void FindKNearestPhantomNodesForCoordinate(
|
||||
const _Coordinate & location,
|
||||
const FixedPointCoordinate & location,
|
||||
const unsigned zoom_level,
|
||||
const unsigned candidate_count,
|
||||
std::vector<std::pair<PhantomNode, double> > & result_vector
|
||||
@@ -465,7 +465,7 @@ public:
|
||||
double min_max_dist = DBL_MAX;
|
||||
bool found_a_nearest_edge = false;
|
||||
|
||||
_Coordinate nearest, current_start_coordinate, current_end_coordinate;
|
||||
FixedPointCoordinate nearest, current_start_coordinate, current_end_coordinate;
|
||||
|
||||
//initialize queue with root element
|
||||
std::priority_queue<QueryCandidate> traversal_queue;
|
||||
@@ -493,8 +493,8 @@ public:
|
||||
double current_ratio = 0.;
|
||||
double current_perpendicular_distance = ComputePerpendicularDistance(
|
||||
input_coordinate,
|
||||
_Coordinate(current_edge.lat1, current_edge.lon1),
|
||||
_Coordinate(current_edge.lat2, current_edge.lon2),
|
||||
FixedPointCoordinate(current_edge.lat1, current_edge.lon1),
|
||||
FixedPointCoordinate(current_edge.lat2, current_edge.lon2),
|
||||
nearest,
|
||||
¤t_ratio
|
||||
);
|
||||
@@ -523,11 +523,11 @@ public:
|
||||
1 == abs(current_edge.id - result_phantom_node.edgeBasedNode )
|
||||
&& CoordinatesAreEquivalent(
|
||||
current_start_coordinate,
|
||||
_Coordinate(
|
||||
FixedPointCoordinate(
|
||||
current_edge.lat1,
|
||||
current_edge.lon1
|
||||
),
|
||||
_Coordinate(
|
||||
FixedPointCoordinate(
|
||||
current_edge.lat2,
|
||||
current_edge.lon2
|
||||
),
|
||||
@@ -563,14 +563,14 @@ public:
|
||||
|
||||
const double distance_to_edge =
|
||||
ApproximateDistance (
|
||||
_Coordinate(nearest_edge.lat1, nearest_edge.lon1),
|
||||
FixedPointCoordinate(nearest_edge.lat1, nearest_edge.lon1),
|
||||
result_phantom_node.location
|
||||
);
|
||||
|
||||
const double length_of_edge =
|
||||
ApproximateDistance(
|
||||
_Coordinate(nearest_edge.lat1, nearest_edge.lon1),
|
||||
_Coordinate(nearest_edge.lat2, nearest_edge.lon2)
|
||||
FixedPointCoordinate(nearest_edge.lat1, nearest_edge.lon1),
|
||||
FixedPointCoordinate(nearest_edge.lat2, nearest_edge.lon2)
|
||||
);
|
||||
|
||||
const double ratio = (found_a_nearest_edge ?
|
||||
@@ -596,7 +596,7 @@ public:
|
||||
|
||||
*/
|
||||
bool FindPhantomNodeForCoordinate(
|
||||
const _Coordinate & input_coordinate,
|
||||
const FixedPointCoordinate & input_coordinate,
|
||||
PhantomNode & result_phantom_node,
|
||||
const unsigned zoom_level
|
||||
) {
|
||||
@@ -611,7 +611,7 @@ public:
|
||||
double min_max_dist = DBL_MAX;
|
||||
bool found_a_nearest_edge = false;
|
||||
|
||||
_Coordinate nearest, current_start_coordinate, current_end_coordinate;
|
||||
FixedPointCoordinate nearest, current_start_coordinate, current_end_coordinate;
|
||||
|
||||
//initialize queue with root element
|
||||
std::priority_queue<QueryCandidate> traversal_queue;
|
||||
@@ -650,8 +650,8 @@ public:
|
||||
double current_ratio = 0.;
|
||||
double current_perpendicular_distance = ComputePerpendicularDistance(
|
||||
input_coordinate,
|
||||
_Coordinate(current_edge.lat1, current_edge.lon1),
|
||||
_Coordinate(current_edge.lat2, current_edge.lon2),
|
||||
FixedPointCoordinate(current_edge.lat1, current_edge.lon1),
|
||||
FixedPointCoordinate(current_edge.lat2, current_edge.lon2),
|
||||
nearest,
|
||||
¤t_ratio
|
||||
);
|
||||
@@ -680,11 +680,11 @@ public:
|
||||
1 == abs(current_edge.id - result_phantom_node.edgeBasedNode )
|
||||
&& CoordinatesAreEquivalent(
|
||||
current_start_coordinate,
|
||||
_Coordinate(
|
||||
FixedPointCoordinate(
|
||||
current_edge.lat1,
|
||||
current_edge.lon1
|
||||
),
|
||||
_Coordinate(
|
||||
FixedPointCoordinate(
|
||||
current_edge.lat2,
|
||||
current_edge.lon2
|
||||
),
|
||||
@@ -768,10 +768,10 @@ private:
|
||||
}
|
||||
|
||||
inline double ComputePerpendicularDistance(
|
||||
const _Coordinate& inputPoint,
|
||||
const _Coordinate& source,
|
||||
const _Coordinate& target,
|
||||
_Coordinate& nearest, double *r) const {
|
||||
const FixedPointCoordinate& inputPoint,
|
||||
const FixedPointCoordinate& source,
|
||||
const FixedPointCoordinate& target,
|
||||
FixedPointCoordinate& nearest, double *r) const {
|
||||
const double x = static_cast<double>(inputPoint.lat);
|
||||
const double y = static_cast<double>(inputPoint.lon);
|
||||
const double a = static_cast<double>(source.lat);
|
||||
@@ -815,7 +815,7 @@ private:
|
||||
return (p-x)*(p-x) + (q-y)*(q-y);
|
||||
}
|
||||
|
||||
inline bool CoordinatesAreEquivalent(const _Coordinate & a, const _Coordinate & b, const _Coordinate & c, const _Coordinate & d) const {
|
||||
inline bool CoordinatesAreEquivalent(const FixedPointCoordinate & a, const FixedPointCoordinate & b, const FixedPointCoordinate & c, const FixedPointCoordinate & d) const {
|
||||
return (a == b && c == d) || (a == c && b == d) || (a == d && b == c);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user