summaryrefslogtreecommitdiffstats
path: root/server/src/geo/wgs84.cppm
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/geo/wgs84.cppm')
-rw-r--r--server/src/geo/wgs84.cppm51
1 files changed, 15 insertions, 36 deletions
diff --git a/server/src/geo/wgs84.cppm b/server/src/geo/wgs84.cppm
index d574d39..b53a963 100644
--- a/server/src/geo/wgs84.cppm
+++ b/server/src/geo/wgs84.cppm
@@ -13,25 +13,20 @@ using point = bgeo::model::point<double, 2, cs>;
13// TODO: guarantee that linestring provides non-static member 13// TODO: guarantee that linestring provides non-static member
14// auto reserve(std::size_t) -> void 14// auto reserve(std::size_t) -> void
15// Perhaps better yet: guarantee that the backing container is a std::vector. 15// Perhaps better yet: guarantee that the backing container is a std::vector.
16using linestring = bgeo::model::linestring<point, std::vector /* the default */>; 16using linestring =
17 bgeo::model::linestring<point, std::vector /* the default */>;
17using box = bgeo::model::box<point>; 18using box = bgeo::model::box<point>;
18using stype = bgeo::srs::spheroid<double>; 19using stype = bgeo::srs::spheroid<double>;
19using vincenty_strategy = bgeo::strategy::distance::vincenty<stype>; 20using vincenty_strategy = bgeo::strategy::distance::vincenty<stype>;
20 21
21auto from_lat_lon(double lat, double lon) -> point 22inline auto from_lat_lon(double lat, double lon) -> point
22{ 23{
23 return point{lon, lat}; 24 return point{lon, lat};
24} 25}
25 26
26auto lat(point p) -> double 27inline auto lat(point p) -> double { return bgeo::get<1>(p); }
27{
28 return bgeo::get<1>(p);
29}
30 28
31auto lon(point p) -> double 29inline auto lon(point p) -> double { return bgeo::get<0>(p); }
32{
33 return bgeo::get<0>(p);
34}
35 30
36// Point p with latitude in [-90, 90] and longitude in [-180, 180) 31// Point p with latitude in [-90, 90] and longitude in [-180, 180)
37auto normalize(point p) -> point 32auto normalize(point p) -> point
@@ -44,7 +39,7 @@ auto normalize(point p) -> point
44 auto p_lat = nonneg_mod360(lat(p)) - 90.0; 39 auto p_lat = nonneg_mod360(lat(p)) - 90.0;
45 if (90.0 < p_lat) 40 if (90.0 < p_lat)
46 { 41 {
47 assert(p_lat < 270.0); // by nonneg_mod360 42 assert(p_lat < 270.0); // by nonneg_mod360
48 p_lon += 180.0; 43 p_lon += 180.0;
49 p_lat -= 180.0; 44 p_lat -= 180.0;
50 } 45 }
@@ -53,7 +48,7 @@ auto normalize(point p) -> point
53 return from_lat_lon(p_lat, p_lon); 48 return from_lat_lon(p_lat, p_lon);
54} 49}
55 50
56auto is_normalized(point p) -> bool 51inline auto is_normalized(point p) -> bool
57{ 52{
58 return -90 <= lat(p) && lat(p) <= 90 && -180 <= lon(p) && lon(p) < 180; 53 return -90 <= lat(p) && lat(p) <= 90 && -180 <= lon(p) && lon(p) < 180;
59} 54}
@@ -63,32 +58,22 @@ class normalized_point
63 point p_; 58 point p_;
64 59
65public: 60public:
66 normalized_point(point p) 61 inline normalized_point(point p) : p_{is_normalized(p) ? p : normalize(p)} {}
67 : p_{is_normalized(p) ? p : normalize(p)}
68 {}
69 62
70 normalized_point() 63 inline normalized_point() : p_{} {}
71 : p_{}
72 {}
73 64
74 auto lat() const -> double 65 inline auto lat() const -> double { return bgeo::get<1>(p_); }
75 {
76 return bgeo::get<1>(p_);
77 }
78 66
79 auto lon() const -> double 67 inline auto lon() const -> double { return bgeo::get<0>(p_); }
80 {
81 return bgeo::get<0>(p_);
82 }
83 68
84 auto lat(double lat) -> void 69 inline auto lat(double lat) -> void
85 { 70 {
86 if (lat < -90 || lat > 90) 71 if (lat < -90 || lat > 90)
87 throw std::range_error{"latitude out of range"}; 72 throw std::range_error{"latitude out of range"};
88 bgeo::set<1>(p_, lat); 73 bgeo::set<1>(p_, lat);
89 } 74 }
90 75
91 auto lon(double lon) -> void 76 inline auto lon(double lon) -> void
92 { 77 {
93 if (lon < -180 || lon > 180) 78 if (lon < -180 || lon > 180)
94 throw std::range_error{"longitude out of range"}; 79 throw std::range_error{"longitude out of range"};
@@ -101,15 +86,9 @@ class normalized_linestring
101 std::vector<normalized_point> ls_; 86 std::vector<normalized_point> ls_;
102 87
103public: 88public:
104 auto empty() const -> bool 89 inline auto empty() const -> bool { return ls_.empty(); }
105 {
106 return ls_.empty();
107 }
108 90
109 auto push_back(normalized_point p) -> void 91 inline auto push_back(normalized_point p) -> void { ls_.push_back(p); }
110 {
111 ls_.push_back(p);
112 }
113}; 92};
114 93
115} // namespace routemon::geo::wgs84 94} // namespace routemon::geo::wgs84