Fixes issue #104. Heading and Azimuth get computed now.
This commit is contained in:
parent
c98f19c5a6
commit
5e275b3935
@ -28,12 +28,13 @@ struct SegmentInformation {
|
||||
NodeID nameID;
|
||||
unsigned length;
|
||||
unsigned duration;
|
||||
double bearing;
|
||||
short turnInstruction;
|
||||
bool necessary;
|
||||
SegmentInformation(const _Coordinate & loc, const NodeID nam, const unsigned len, const unsigned dur, const short tInstr, const bool nec) :
|
||||
location(loc), nameID(nam), length(len), duration(dur), turnInstruction(tInstr), necessary(nec) {}
|
||||
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(nec) {}
|
||||
SegmentInformation(const _Coordinate & loc, const NodeID nam, const unsigned len, const unsigned dur, const short tInstr) :
|
||||
location(loc), nameID(nam), length(len), duration(dur), turnInstruction(tInstr), necessary(tInstr != 0) {}
|
||||
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(tInstr != 0) {}
|
||||
};
|
||||
|
||||
#endif /* SEGMENTINFORMATION_H_ */
|
||||
|
@ -24,10 +24,18 @@ DescriptionFactory::DescriptionFactory() { }
|
||||
|
||||
DescriptionFactory::~DescriptionFactory() { }
|
||||
|
||||
double DescriptionFactory::GetAngleBetweenCoordinates() const {
|
||||
return 0.;//GetAngleBetweenTwoEdges(previousCoordinate, currentCoordinate, nextCoordinate);
|
||||
double DescriptionFactory::GetAzimuth(const _Coordinate& A, const _Coordinate& B) const {
|
||||
double lonDiff = (A.lon-B.lon)/100000.;
|
||||
double angle = atan2(sin(lonDiff)*cos(B.lat/100000.),
|
||||
cos(A.lat/100000.)*sin(B.lat/100000.)-sin(A.lat/100000.)*cos(B.lat/100000.)*cos(lonDiff));
|
||||
angle*=180/M_PI;
|
||||
while(angle < 0)
|
||||
angle += 360;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
|
||||
void DescriptionFactory::SetStartSegment(const PhantomNode & _startPhantom) {
|
||||
startPhantom = _startPhantom;
|
||||
AppendSegment(_startPhantom.location, _PathData(0, _startPhantom.nodeBasedEdgeNameID, 10, _startPhantom.weight1));
|
||||
@ -91,5 +99,12 @@ unsigned DescriptionFactory::Run(const unsigned zoomLevel) {
|
||||
dp.Run(pathDescription, zoomLevel);
|
||||
|
||||
//fix what needs to be fixed else
|
||||
for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){
|
||||
if(pathDescription[i].necessary) {
|
||||
int angle = 100*GetAzimuth(pathDescription[i].location, pathDescription[i+1].location);
|
||||
pathDescription[i].bearing = angle/100.;
|
||||
}
|
||||
}
|
||||
|
||||
return entireLength;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
std::vector <SegmentInformation> pathDescription;
|
||||
DescriptionFactory();
|
||||
virtual ~DescriptionFactory();
|
||||
double GetAngleBetweenCoordinates() const;
|
||||
double GetAzimuth(const _Coordinate& C, const _Coordinate& B) const;
|
||||
void AppendEncodedPolylineString(std::string &output);
|
||||
void AppendUnencodedPolylineString(std::string &output);
|
||||
void AppendSegment(const _Coordinate & coordinate, const _PathData & data);
|
||||
|
@ -27,6 +27,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "DescriptionFactory.h"
|
||||
#include "../DataStructures/SegmentInformation.h"
|
||||
#include "../DataStructures/TurnInstructions.h"
|
||||
#include "../Util/Azimuth.h"
|
||||
#include "../Util/StringUtil.h"
|
||||
|
||||
template<class SearchEngineT>
|
||||
@ -36,6 +37,7 @@ private:
|
||||
_RouteSummary summary;
|
||||
DescriptionFactory descriptionFactory;
|
||||
_Coordinate current;
|
||||
|
||||
struct {
|
||||
int startIndex;
|
||||
int nameID;
|
||||
@ -100,7 +102,7 @@ public:
|
||||
unsigned prefixSumOfNecessarySegments = 0;
|
||||
roundAbout.leaveAtExit = 0;
|
||||
roundAbout.nameID = 0;
|
||||
std::string tmpDist, tmpLength, tmpDuration;
|
||||
std::string tmpDist, tmpLength, tmpDuration, tmpBearing;
|
||||
//Fetch data from Factory and generate a string from it.
|
||||
BOOST_FOREACH(SegmentInformation & segment, descriptionFactory.pathDescription) {
|
||||
if(TurnInstructions.TurnIsNecessary( segment.turnInstruction) ) {
|
||||
@ -134,8 +136,11 @@ public:
|
||||
reply.content += tmpDuration;
|
||||
reply.content += ",\"";
|
||||
reply.content += tmpLength;
|
||||
//TODO: fix heading
|
||||
reply.content += "\",\"NE\",22.5";
|
||||
reply.content += "\",\"";
|
||||
reply.content += Azimuth::Get(segment.bearing);
|
||||
reply.content += "\",";
|
||||
doubleToStringWithTwoDigitsBehindComma(segment.bearing, tmpBearing);
|
||||
reply.content += tmpBearing;
|
||||
reply.content += "]";
|
||||
}
|
||||
} else if(TurnInstructions.StayOnRoundAbout == segment.turnInstruction) {
|
||||
|
@ -93,6 +93,14 @@ static inline void doubleToString(const double value, std::string & output){
|
||||
output = buffer ;
|
||||
}
|
||||
|
||||
static inline void doubleToStringWithTwoDigitsBehindComma(const double value, std::string & output){
|
||||
// The largest 32-bit integer is 4294967295, that is 10 chars
|
||||
// On the safe side, add 1 for sign, and 1 for trailing zero
|
||||
char buffer[12] ;
|
||||
sprintf(buffer, "%g", value) ;
|
||||
output = buffer ;
|
||||
}
|
||||
|
||||
inline std::string & replaceAll(std::string &s, const std::string &sub, const std::string &other) {
|
||||
assert(!sub.empty());
|
||||
size_t b = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user