From 1417e6cf41d27c594d2bdc92f87746d2383a1b1d Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Tue, 8 Sep 2026 13:54:40 +0200 Subject: Some cleanups --- server/src/geo/utm.cppm | 140 +++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 68 deletions(-) (limited to 'server/src/geo/utm.cppm') diff --git a/server/src/geo/utm.cppm b/server/src/geo/utm.cppm index 83da222..c58ffb4 100644 --- a/server/src/geo/utm.cppm +++ b/server/src/geo/utm.cppm @@ -1,7 +1,7 @@ module; -#include #include +#include export module routemon:geo.utm; @@ -9,46 +9,32 @@ import std; import :geo; import :geo.wgs84; -namespace routemon::geo::utm -{ +namespace routemon::geo::utm { class zonable_wgs84_point { wgs84::normalized_point p_; - explicit zonable_wgs84_point(wgs84::normalized_point p) - : p_{p} - {} + explicit inline zonable_wgs84_point(wgs84::normalized_point p) : p_{p} {} public: - zonable_wgs84_point() - : p_{} - { - } + inline zonable_wgs84_point() : p_{} {} - static auto from(wgs84::normalized_point p) -> std::optional + inline static auto from(wgs84::normalized_point p) + -> std::optional { if (p.lat() < -80 || p.lat() > 84) return std::nullopt; return zonable_wgs84_point{p}; } - auto lat() const -> double - { - return p_.lat(); - } + inline auto lat() const -> double { return p_.lat(); } - auto lon() const -> double - { - return p_.lon(); - } + inline auto lon() const -> double { return p_.lon(); } - auto lon(double lon) -> void - { - p_.lon(lon); - } + inline auto lon(double lon) -> void { p_.lon(lon); } - auto lat(double lat) -> void + inline auto lat(double lat) -> void { if (lat < -80 || lat > 84) throw std::range_error{"latitude out of range for UTM"}; @@ -56,48 +42,69 @@ public: } }; -} +} // namespace routemon::geo::utm namespace boost::geometry::traits { - namespace { +namespace { - using zonable_wgs84_point = routemon::geo::utm::zonable_wgs84_point; +using zonable_wgs84_point = routemon::geo::utm::zonable_wgs84_point; - } // namespace +} // namespace - template<> struct tag { using type = point_tag; }; - template<> struct dimension : boost::mpl::int_<2> {}; - template<> struct coordinate_type { using type = double; }; - template<> struct coordinate_system { using type = routemon::geo::wgs84::cs; }; +template <> +struct tag +{ + using type = point_tag; +}; - template - struct access { - static inline auto get(zonable_wgs84_point const& p) -> double - { - if constexpr (index == 0) - return p.lon(); - else if constexpr (index == 1) - return p.lat(); - else static_assert(false, "Out of range"); - } +template <> +struct dimension : boost::mpl::int_<2> +{ +}; - static inline auto set(zonable_wgs84_point& p, double v) -> void - { - if constexpr (index == 0) - p.lon(v); - else if constexpr (index == 1) - p.lat(v); - else static_assert(false, "Out of range"); - } - }; +template <> +struct coordinate_type +{ + using type = double; +}; -} // namespace boost::geometry::traits +template <> +struct coordinate_system +{ + using type = routemon::geo::wgs84::cs; +}; -namespace routemon::geo::utm +template +struct access { + static inline auto get(zonable_wgs84_point const& p) -> double + { + if constexpr (index == 0) + return p.lon(); + else if constexpr (index == 1) + return p.lat(); + else + static_assert(false, "Out of range"); + } + + static inline auto set(zonable_wgs84_point& p, double v) -> void + { + if constexpr (index == 0) + p.lon(v); + else if constexpr (index == 1) + p.lat(v); + else + static_assert(false, "Out of range"); + } +}; + +} // namespace boost::geometry::traits -using zonable_wgs84_linestring = bgeo::model::linestring; +namespace routemon::geo::utm { + +using zonable_wgs84_linestring = + bgeo::model::linestring; // In the sense of the common WGS84 subdivisions by simple northing // and easting (so no Norway/Svalbard exceptions). @@ -130,33 +137,30 @@ class zone public: explicit constexpr zone(std::uint8_t zone_no, hemisphere h) : zone_{from(zone_no, h)} - {} + { + } - auto hemisphere() const -> enum hemisphere + constexpr auto hemisphere() const -> enum hemisphere { return static_cast(zone_ % 2); } // Return value in range [1, 60] - auto zone_no() const -> std::uint8_t - { - return 1 + zone_ / 2; - } + constexpr auto zone_no() const -> std::uint8_t { return 1 + zone_ / 2; } // Return value in range [min(), max()] - constexpr auto as_index() const -> std::uint8_t - { - return zone_; - } + constexpr auto as_index() const -> std::uint8_t { return zone_; } static auto for_wgs84_point(zonable_wgs84_point p) noexcept -> zone { auto zone_no = static_cast(1 + (p.lon() + 180.0) / 6.0); auto northern = p.lat() >= 0.0; - return zone{zone_no, northern ? hemisphere::northern : hemisphere::southern}; + return zone{ + zone_no, northern ? hemisphere::northern : hemisphere::southern + }; } - auto wgs84_proj_epsg() const -> int + constexpr auto wgs84_proj_epsg() const -> int { switch (hemisphere()) { @@ -178,7 +182,7 @@ public: return zone{60, hemisphere::southern}; } - auto next() const -> zone + constexpr auto next() const -> zone { assert(zone_ <= max().as_index()); if (zone_ == max().as_index()) @@ -188,7 +192,7 @@ public: return copy; } - auto operator==(zone rhs) const -> bool + constexpr auto operator==(zone rhs) const -> bool { return zone_ == rhs.zone_; } -- cgit v1.3