7
7
#include < tuple>
8
8
#include < utility>
9
9
10
- namespace mapbox {
10
+ namespace mapbox
11
+ {
11
12
12
- namespace geometry {
13
- template < typename T>
14
- struct point
15
- {
16
- using coordinate_type = T;
13
+ namespace geometry
14
+ {
15
+ template < typename T> struct point
16
+ {
17
+ using coordinate_type = T;
17
18
18
- constexpr point ()
19
- : x(), y()
20
- {}
21
- constexpr point (T x_, T y_)
22
- : x(x_), y(y_)
23
- {}
19
+ constexpr point () : x(), y() {}
20
+ constexpr point (T x_, T y_) : x(x_), y(y_) {}
24
21
25
- T x;
26
- T y;
27
- };
28
- }
22
+ T x;
23
+ T y;
24
+ };
25
+ } // namespace geometry
29
26
30
- namespace cheap_ruler {
27
+ namespace cheap_ruler
28
+ {
31
29
32
- using point = geometry::point<double >;
30
+ using point = geometry::point<double >;
33
31
34
- class CheapRuler {
32
+ class CheapRuler
33
+ {
35
34
36
35
// Values that define WGS84 ellipsoid model of the Earth
37
- static constexpr double RE = 6378.137 ; // equatorial radius
36
+ static constexpr double RE = 6378.137 ; // equatorial radius
38
37
static constexpr double FE = 1.0 / 298.257223563 ; // flattening
39
38
40
39
static constexpr double E2 = FE * (2 - FE);
41
40
static constexpr double RAD = M_PI / 180.0 ;
42
41
43
- public:
44
- explicit CheapRuler (double latitude) {
42
+ public:
43
+ explicit CheapRuler (double latitude)
44
+ {
45
45
// Curvature formulas from https://en.wikipedia.org/wiki/Earth_radius#Meridional
46
46
double mul = RAD * RE * 1000 ;
47
47
double coslat = std::cos (latitude * RAD);
@@ -53,7 +53,8 @@ class CheapRuler {
53
53
ky = mul * w * w2 * (1 - E2 ); // based on meridonal radius of curvature
54
54
}
55
55
56
- double squareDistance (point a, point b) const {
56
+ double squareDistance (point a, point b) const
57
+ {
57
58
auto dx = longDiff (a.x , b.x ) * kx;
58
59
auto dy = (a.y - b.y ) * ky;
59
60
return dx * dx + dy * dy;
@@ -62,26 +63,23 @@ class CheapRuler {
62
63
//
63
64
// Given two points of the form [x = longitude, y = latitude], returns the distance.
64
65
//
65
- double distance (point a, point b) const {
66
- return std::sqrt (squareDistance (a, b));
67
- }
66
+ double distance (point a, point b) const { return std::sqrt (squareDistance (a, b)); }
68
67
69
68
//
70
69
// Returns the bearing between two points in angles.
71
70
//
72
- double bearing (point a, point b) const {
71
+ double bearing (point a, point b) const
72
+ {
73
73
auto dx = longDiff (b.x , a.x ) * kx;
74
74
auto dy = (b.y - a.y ) * ky;
75
75
76
76
return std::atan2 (dx, dy) / RAD;
77
77
}
78
78
79
- private:
79
+ private:
80
80
double ky;
81
81
double kx;
82
- static double longDiff (double a, double b) {
83
- return std::remainder (a - b, 360 );
84
- }
82
+ static double longDiff (double a, double b) { return std::remainder (a - b, 360 ); }
85
83
};
86
84
87
85
} // namespace cheap_ruler
0 commit comments