move GetBearing(.) function into FixedPointCoordinate
This commit is contained in:
		
							parent
							
								
									a47467f29b
								
							
						
					
					
						commit
						8983c0f927
					
				| @ -330,6 +330,59 @@ void FixedPointCoordinate::Output(std::ostream &out) const | ||||
|     out << "(" << lat / COORDINATE_PRECISION << "," << lon / COORDINATE_PRECISION << ")"; | ||||
| } | ||||
| 
 | ||||
| double FixedPointCoordinate::GetBearing(const FixedPointCoordinate &A, const FixedPointCoordinate &B) | ||||
| { | ||||
|     double delta_long = DegreeToRadian(B.lon / COORDINATE_PRECISION - A.lon / COORDINATE_PRECISION); | ||||
| 
 | ||||
|     const double lat1 = DegreeToRadian(A.lat / COORDINATE_PRECISION); | ||||
|     const double lat2 = DegreeToRadian(B.lat / COORDINATE_PRECISION); | ||||
| 
 | ||||
|     const double y = sin(delta_long) * cos(lat2); | ||||
|     const double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_long); | ||||
|     double result = RadianToDegree(atan2(y, x)); | ||||
|     while (result < 0.) | ||||
|     { | ||||
|         result += 360.; | ||||
|     } | ||||
| 
 | ||||
|     while (result >= 360.) | ||||
|     { | ||||
|         result -= 360.; | ||||
|     } | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
| double FixedPointCoordinate::GetBearing(const FixedPointCoordinate &other) const | ||||
| { | ||||
|     double delta_long = DegreeToRadian(lon / COORDINATE_PRECISION - other.lon / COORDINATE_PRECISION); | ||||
| 
 | ||||
|     const double lat1 = DegreeToRadian(other.lat / COORDINATE_PRECISION); | ||||
|     const double lat2 = DegreeToRadian(lat / COORDINATE_PRECISION); | ||||
| 
 | ||||
|     const double y = sin(delta_long) * cos(lat2); | ||||
|     const double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_long); | ||||
|     double result = RadianToDegree(atan2(y, x)); | ||||
|     while (result < 0.) | ||||
|     { | ||||
|         result += 360.; | ||||
|     } | ||||
| 
 | ||||
|     while (result >= 360.) | ||||
|     { | ||||
|         result -= 360.; | ||||
|     } | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
| double FixedPointCoordinate::DegreeToRadian(const double degree) | ||||
| { | ||||
|     return degree * (M_PI / 180.); | ||||
| } | ||||
| 
 | ||||
| double FixedPointCoordinate::RadianToDegree(const double radian) | ||||
| { | ||||
|     return radian * (180. / M_PI); | ||||
| } | ||||
| 
 | ||||
| // double PointSegmentDistanceSquared( double px, double py,
 | ||||
| //                                     double p1x, double p1y,
 | ||||
|  | ||||
| @ -31,39 +31,6 @@ DescriptionFactory::DescriptionFactory() : entireLength(0) {} | ||||
| 
 | ||||
| DescriptionFactory::~DescriptionFactory() {} | ||||
| 
 | ||||
| inline double DescriptionFactory::DegreeToRadian(const double degree) const | ||||
| { | ||||
|     return degree * (M_PI / 180.); | ||||
| } | ||||
| 
 | ||||
| inline double DescriptionFactory::RadianToDegree(const double radian) const | ||||
| { | ||||
|     return radian * (180. / M_PI); | ||||
| } | ||||
| 
 | ||||
| double DescriptionFactory::GetBearing(const FixedPointCoordinate &A, const FixedPointCoordinate &B) | ||||
|     const | ||||
| { | ||||
|     double delta_long = DegreeToRadian(B.lon / COORDINATE_PRECISION - A.lon / COORDINATE_PRECISION); | ||||
| 
 | ||||
|     const double lat1 = DegreeToRadian(A.lat / COORDINATE_PRECISION); | ||||
|     const double lat2 = DegreeToRadian(B.lat / COORDINATE_PRECISION); | ||||
| 
 | ||||
|     const double y = sin(delta_long) * cos(lat2); | ||||
|     const double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_long); | ||||
|     double result = RadianToDegree(atan2(y, x)); | ||||
|     while (result < 0.) | ||||
|     { | ||||
|         result += 360.; | ||||
|     } | ||||
| 
 | ||||
|     while (result >= 360.) | ||||
|     { | ||||
|         result -= 360.; | ||||
|     } | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
| void DescriptionFactory::SetStartSegment(const PhantomNode &source) | ||||
| { | ||||
|     start_phantom = source; | ||||
|  | ||||
| @ -77,7 +77,6 @@ class DescriptionFactory | ||||
|     std::vector<SegmentInformation> path_description; | ||||
|     DescriptionFactory(); | ||||
|     virtual ~DescriptionFactory(); | ||||
|     double GetBearing(const FixedPointCoordinate &C, const FixedPointCoordinate &B) const; | ||||
|     JSON::Value AppendUnencodedPolylineString() const; | ||||
|     void AppendSegment(const FixedPointCoordinate &coordinate, const PathData &data); | ||||
|     void BuildRouteSummary(const double distance, const unsigned time); | ||||
| @ -196,8 +195,7 @@ class DescriptionFactory | ||||
|         { | ||||
|             if (path_description[i].necessary) | ||||
|             { | ||||
|                 const double angle = | ||||
|                     GetBearing(path_description[i].location, path_description[i + 1].location); | ||||
|                 const double angle = path_description[i].location.GetBearing(path_description[i + 1].location); | ||||
|                 path_description[i].bearing = angle * 10; | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -44,7 +44,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| template <class DataFacadeT> class JSONDescriptor : public BaseDescriptor<DataFacadeT> | ||||
| { | ||||
|   private: | ||||
|     // TODO: initalize in c'tor
 | ||||
|     DataFacadeT *facade; | ||||
|     DescriptorConfig config; | ||||
|     DescriptionFactory description_factory, alternate_description_factory; | ||||
|  | ||||
| @ -74,7 +74,14 @@ struct FixedPointCoordinate | ||||
|                                                FixedPointCoordinate &nearest_location, | ||||
|                                                double &r); | ||||
| 
 | ||||
|     static double GetBearing(const FixedPointCoordinate &A, const FixedPointCoordinate &B); | ||||
| 
 | ||||
|     double GetBearing(const FixedPointCoordinate &other) const; | ||||
| 
 | ||||
|     void Output(std::ostream &out) const; | ||||
| 
 | ||||
|     static double DegreeToRadian(const double degree); | ||||
|     static double RadianToDegree(const double radian); | ||||
| }; | ||||
| 
 | ||||
| inline std::ostream &operator<<(std::ostream &o, FixedPointCoordinate const &c) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user