Bearing is reported as integer only, fixes cucumber tests for issue #292
This commit is contained in:
parent
b7bcc401e7
commit
df68c3ad48
@ -24,15 +24,29 @@ DescriptionFactory::DescriptionFactory() : entireLength(0) { }
|
|||||||
|
|
||||||
DescriptionFactory::~DescriptionFactory() { }
|
DescriptionFactory::~DescriptionFactory() { }
|
||||||
|
|
||||||
double DescriptionFactory::GetAzimuth(const _Coordinate& A, const _Coordinate& B) const {
|
inline double DescriptionFactory::DegreeToRadian(const double degree) const {
|
||||||
double lonDiff = (A.lon-B.lon)/100000.;
|
return degree * (M_PI/180);
|
||||||
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;
|
inline double DescriptionFactory::RadianToDegree(const double radian) const {
|
||||||
|
return radian * (180/M_PI);
|
||||||
|
}
|
||||||
|
|
||||||
|
double DescriptionFactory::GetBearing(const _Coordinate& A, const _Coordinate& B) const {
|
||||||
|
double deltaLong = DegreeToRadian(B.lon/100000. - A.lon/100000.);
|
||||||
|
|
||||||
|
double lat1 = DegreeToRadian(A.lat/100000.);
|
||||||
|
double lat2 = DegreeToRadian(B.lat/100000.);
|
||||||
|
|
||||||
|
double y = sin(deltaLong) * cos(lat2);
|
||||||
|
double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(deltaLong);
|
||||||
|
double result = RadianToDegree(atan2(y, x));
|
||||||
|
while(result <= 0.)
|
||||||
|
result += 360.;
|
||||||
|
while(result >= 360.)
|
||||||
|
result -= 360.;
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionFactory::SetStartSegment(const PhantomNode & _startPhantom) {
|
void DescriptionFactory::SetStartSegment(const PhantomNode & _startPhantom) {
|
||||||
@ -170,8 +184,8 @@ void DescriptionFactory::Run(const SearchEngineT &sEngine, const unsigned zoomLe
|
|||||||
//fix what needs to be fixed else
|
//fix what needs to be fixed else
|
||||||
for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){
|
for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){
|
||||||
if(pathDescription[i].necessary) {
|
if(pathDescription[i].necessary) {
|
||||||
int angle = 100*GetAzimuth(pathDescription[i].location, pathDescription[i+1].location);
|
double angle = GetBearing(pathDescription[i].location, pathDescription[i+1].location);
|
||||||
pathDescription[i].bearing = angle/100.;
|
pathDescription[i].bearing = angle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,9 @@ class DescriptionFactory {
|
|||||||
PhantomNode startPhantom, targetPhantom;
|
PhantomNode startPhantom, targetPhantom;
|
||||||
|
|
||||||
typedef SearchEngine<QueryEdge::EdgeData, StaticGraph<QueryEdge::EdgeData> > SearchEngineT;
|
typedef SearchEngine<QueryEdge::EdgeData, StaticGraph<QueryEdge::EdgeData> > SearchEngineT;
|
||||||
|
|
||||||
|
double DegreeToRadian(const double degree) const;
|
||||||
|
double RadianToDegree(const double degree) const;
|
||||||
public:
|
public:
|
||||||
struct _RouteSummary {
|
struct _RouteSummary {
|
||||||
std::string lengthString;
|
std::string lengthString;
|
||||||
@ -66,7 +69,7 @@ public:
|
|||||||
std::vector <SegmentInformation> pathDescription;
|
std::vector <SegmentInformation> pathDescription;
|
||||||
DescriptionFactory();
|
DescriptionFactory();
|
||||||
virtual ~DescriptionFactory();
|
virtual ~DescriptionFactory();
|
||||||
double GetAzimuth(const _Coordinate& C, const _Coordinate& B) const;
|
double GetBearing(const _Coordinate& C, const _Coordinate& B) const;
|
||||||
void AppendEncodedPolylineString(std::string &output);
|
void AppendEncodedPolylineString(std::string &output);
|
||||||
void AppendUnencodedPolylineString(std::string &output);
|
void AppendUnencodedPolylineString(std::string &output);
|
||||||
void AppendSegment(const _Coordinate & coordinate, const _PathData & data);
|
void AppendSegment(const _Coordinate & coordinate, const _PathData & data);
|
||||||
|
@ -127,7 +127,7 @@ public:
|
|||||||
reply.content += "m\",\"";
|
reply.content += "m\",\"";
|
||||||
reply.content += Azimuth::Get(segment.bearing);
|
reply.content += Azimuth::Get(segment.bearing);
|
||||||
reply.content += "\",";
|
reply.content += "\",";
|
||||||
doubleToStringWithTwoDigitsBehindComma(segment.bearing, tmpBearing);
|
intToString(round(segment.bearing), tmpBearing);
|
||||||
reply.content += tmpBearing;
|
reply.content += tmpBearing;
|
||||||
reply.content += "]";
|
reply.content += "]";
|
||||||
}
|
}
|
||||||
|
@ -31,19 +31,19 @@ struct Azimuth {
|
|||||||
if(heading >= 0 && heading <= 22.5)
|
if(heading >= 0 && heading <= 22.5)
|
||||||
return "N";
|
return "N";
|
||||||
if(heading > 22.5 && heading <= 67.5)
|
if(heading > 22.5 && heading <= 67.5)
|
||||||
return "NW";
|
return "NE";
|
||||||
if(heading > 67.5 && heading <= 112.5)
|
if(heading > 67.5 && heading <= 112.5)
|
||||||
return "W";
|
return "E";
|
||||||
if(heading > 112.5 && heading <= 157.5)
|
if(heading > 112.5 && heading <= 157.5)
|
||||||
return "SW";
|
return "SE";
|
||||||
return "S";
|
return "S";
|
||||||
}
|
}
|
||||||
if(heading > 202.5 && heading <= 247.5)
|
if(heading > 202.5 && heading <= 247.5)
|
||||||
return "SE";
|
return "SW";
|
||||||
if(heading > 247.5 && heading <= 292.5)
|
if(heading > 247.5 && heading <= 292.5)
|
||||||
return "E";
|
return "W";
|
||||||
if(heading > 292.5 && heading <= 337.5)
|
if(heading > 292.5 && heading <= 337.5)
|
||||||
return "NE";
|
return "NW";
|
||||||
return "N";
|
return "N";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,7 @@ Feature: Compass bearing
|
|||||||
|
|
||||||
When I route I should get
|
When I route I should get
|
||||||
| from | to | route | compass | bearing |
|
| from | to | route | compass | bearing |
|
||||||
| a | b | ab | NW | 45 |
|
| a | b | ab | NW | 315 |
|
||||||
|
|
||||||
@west
|
@west
|
||||||
Scenario: Bearing when going west
|
Scenario: Bearing when going west
|
||||||
@ -26,7 +26,7 @@ Feature: Compass bearing
|
|||||||
|
|
||||||
When I route I should get
|
When I route I should get
|
||||||
| from | to | route | compass | bearing |
|
| from | to | route | compass | bearing |
|
||||||
| a | b | ab | W | 90 |
|
| a | b | ab | W | 270 |
|
||||||
|
|
||||||
Scenario: Bearing af 45 degree intervals
|
Scenario: Bearing af 45 degree intervals
|
||||||
Given the node map
|
Given the node map
|
||||||
@ -48,13 +48,13 @@ Feature: Compass bearing
|
|||||||
When I route I should get
|
When I route I should get
|
||||||
| from | to | route | compass | bearing |
|
| from | to | route | compass | bearing |
|
||||||
| x | a | xa | N | 0 |
|
| x | a | xa | N | 0 |
|
||||||
| x | b | xb | NW | 45 |
|
| x | b | xb | NW | 315 |
|
||||||
| x | c | xc | W | 90 |
|
| x | c | xc | W | 270 |
|
||||||
| x | d | xd | SW | 135 |
|
| x | d | xd | SW | 225 |
|
||||||
| x | e | xe | S | 180 |
|
| x | e | xe | S | 180 |
|
||||||
| x | f | xf | SE | 225 |
|
| x | f | xf | SE | 135 |
|
||||||
| x | g | xg | E | 270 |
|
| x | g | xg | E | 90 |
|
||||||
| x | h | xh | NE | 315 |
|
| x | h | xh | NE | 45 |
|
||||||
|
|
||||||
Scenario: Bearing in a roundabout
|
Scenario: Bearing in a roundabout
|
||||||
Given the node map
|
Given the node map
|
||||||
@ -76,8 +76,8 @@ Feature: Compass bearing
|
|||||||
|
|
||||||
When I route I should get
|
When I route I should get
|
||||||
| from | to | route | compass | bearing |
|
| from | to | route | compass | bearing |
|
||||||
| c | b | cd,de,ef,fg,gh,ha,ab | W,SW,S,SE,E,NE,N | 90,135,180,225,270,0,45 |
|
| c | b | cd,de,ef,fg,gh,ha,ab | W,SW,S,SE,E,NE,N | 270,225,180,135,90,45,0 |
|
||||||
| g | f | gh,ha,ab,bc,cd,de,ef | E,NE,N,NW,W,SW,S | 270,315,0,45,90,180,225 |
|
| g | f | gh,ha,ab,bc,cd,de,ef | E,NE,N,NW,W,SW,S | 90,45,0,315,270,225,180 |
|
||||||
|
|
||||||
Scenario: Bearing should stay constant when zig-zagging
|
Scenario: Bearing should stay constant when zig-zagging
|
||||||
Given the node map
|
Given the node map
|
||||||
@ -96,4 +96,4 @@ Feature: Compass bearing
|
|||||||
|
|
||||||
When I route I should get
|
When I route I should get
|
||||||
| from | to | route | compass | bearing |
|
| from | to | route | compass | bearing |
|
||||||
| a | h | ab,bc,cd,de,ef,fg,gh | N,SE,N,SE,N,SE,N | 0,225,0,225,0,225,0 |
|
| a | h | ab,bc,cd,de,ef,fg,gh | N,SE,N,SE,N,SE,N | 0,135,0,135,0,135,0 |
|
||||||
|
Loading…
Reference in New Issue
Block a user