From 1a4d998141dcb59fb2f7f5863de28c6574fa7086 Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Sun, 21 Sep 2025 23:16:03 +0300 Subject: [PATCH] ... --- mcc/mcc_pcm.h | 2 +- mcc/mcc_utils.h | 42 +++++++++++++++++++++++++++++++++++++++++ mcc/tests/ccte_test.cpp | 9 +++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/mcc/mcc_pcm.h b/mcc/mcc_pcm.h index 1664ef4..23b8db1 100644 --- a/mcc/mcc_pcm.h +++ b/mcc/mcc_pcm.h @@ -300,7 +300,7 @@ public: requires(mcc_celestial_point_c || mcc_eqt_hrz_coord_c) { // for small corrections only!!! - auto ret = computePCM(std::move(app_pt), result); + auto ret = computePCM(std::move(app_pt), result, hw_pt); if (ret) { return ret; } diff --git a/mcc/mcc_utils.h b/mcc/mcc_utils.h index 532fb57..ecf9b7c 100644 --- a/mcc/mcc_utils.h +++ b/mcc/mcc_utils.h @@ -7,6 +7,7 @@ #include #include #include +#include "mcc_traits.h" namespace mcc::utils { @@ -313,4 +314,45 @@ static std::string AZZD_rad2sxg(double az, double zd, std::string_view delim = " } +// string to pair of angles +// " 12.3453467,102.4345346" +// "12:43:23.423, 102:43:12.124" +// " 12.3453467, 102:43:12.124 " +template +std::pair parseAnglePair(R&& str, bool hms1 = false, bool hms2 = false, std::string_view delim = ",") +{ + std::pair res{std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()}; + auto found1 = std::ranges::search(std::forward(str), delim); + + if (found1.empty()) { + return res; + } + + std::string s1, s2; + std::ranges::copy(str.begin(), found1.begin(), std::back_inserter(s1)); + + auto rem_len = std::distance(found1.end(), str.end()); + if (!rem_len) { + return res; + } + + auto found2 = std::ranges::search(found1.end(), str.end(), delim.begin(), delim.end()); + if (found2.empty()) { + std::ranges::copy(found1.end(), str.end(), std::back_inserter(s2)); + } else { + std::ranges::copy(found1.end(), found2.end(), std::back_inserter(s2)); + } + + auto vo1 = parsAngleString(s1, hms1); + if (vo1) { + auto vo2 = parsAngleString(s2, hms2); + if (vo2) { + res = {vo1.value(), vo2.value()}; + } + } + + return res; +} + + } // namespace mcc::utils diff --git a/mcc/tests/ccte_test.cpp b/mcc/tests/ccte_test.cpp index c7e2e5e..65e5a7d 100644 --- a/mcc/tests/ccte_test.cpp +++ b/mcc/tests/ccte_test.cpp @@ -140,5 +140,14 @@ int main() erfa.refractionCorrection(cp, &dZ); std::cout << "dZ(" << mcc::MccAngle(cp.Y).degrees() << ") = " << mcc::MccAngle(dZ).arcsecs() << "\n"; + + std::cout << "\n\n"; + + std::string sc2{" 11:34:21.21 , 104.4567892"}; + + auto p2 = mcc::utils::parseAnglePair(sc2); + + std::cout << p2.first << ", " << p2.second << "\n"; + return 0; }