From ae652cab3cf0541173b31273bcec5746a9a81e68 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Fri, 11 Sep 2026 17:22:44 +0200 Subject: Speed improvements --- server/src/geo/utm.cppm | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'server/src/geo') diff --git a/server/src/geo/utm.cppm b/server/src/geo/utm.cppm index c58ffb4..75bba6f 100644 --- a/server/src/geo/utm.cppm +++ b/server/src/geo/utm.cppm @@ -110,6 +110,7 @@ using zonable_wgs84_linestring = // and easting (so no Norway/Svalbard exceptions). class zone { +public: // Note: calculations heavily depend on the values of the variants. enum class hemisphere : std::uint8_t { @@ -117,23 +118,6 @@ class zone southern = 1, }; - // Negative if in the southern hemisphere - // Equal to (zone_no - 1) * 2 + hemisphere - // In range [0, 119] - std::uint8_t zone_; - - static constexpr auto zone_no_valid(std::uint8_t zone_no) -> bool - { - return 0 < zone_no && zone_no <= 60; - } - - static constexpr auto from(std::uint8_t zone_no, hemisphere h) -> std::uint8_t - { - if (!zone_no_valid(zone_no)) - throw std::invalid_argument{"invalid UTM zone number"}; - return (zone_no - 1) * 2 + static_cast(h); - } - public: explicit constexpr zone(std::uint8_t zone_no, hemisphere h) : zone_{from(zone_no, h)} @@ -196,8 +180,34 @@ public: { return zone_ == rhs.zone_; } + +private: + static constexpr auto zone_no_valid(std::uint8_t zone_no) -> bool + { + return 0 < zone_no && zone_no <= 60; + } + + static constexpr auto from(std::uint8_t zone_no, enum hemisphere h) + -> std::uint8_t + { + if (!zone_no_valid(zone_no)) + throw std::invalid_argument{"invalid UTM zone number"}; + return (zone_no - 1) * 2 + static_cast(h); + } + + // Negative if in the southern hemisphere + // Equal to (zone_no - 1) * 2 + hemisphere + // In range [0, 119] + std::uint8_t zone_; }; static_assert(zone::min().as_index() == 0); static_assert(zone::max().as_index() == 119); +auto to_string(zone z) -> std::string +{ + return std::format( + "{} {}", z.zone_no(), + z.hemisphere() == zone::hemisphere::northern ? "northern" : "southern"); +} + } // namespace routemon::geo::utm -- cgit v1.3