...
This commit is contained in:
30
cxx/utils.h
30
cxx/utils.h
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <charconv>
|
||||
#include <cmath>
|
||||
#include <format>
|
||||
#include <numbers>
|
||||
#include <ranges>
|
||||
#include <regex>
|
||||
@@ -160,7 +161,7 @@ static double rad2deg(double ang)
|
||||
|
||||
|
||||
template <std::ranges::output_range<char> R, bool NORM = false>
|
||||
static R rad2deg_str(double ang, int prec = 2)
|
||||
static R rad2deg_str(double ang, int prec = 6)
|
||||
{
|
||||
R res;
|
||||
|
||||
@@ -168,31 +169,33 @@ static R rad2deg_str(double ang, int prec = 2)
|
||||
|
||||
auto degs = rad2deg<NORM>(ang);
|
||||
|
||||
std::vformat_to(std::back_inserter(res), {fmt.begin(), fmt.end()}, degs);
|
||||
std::vformat_to(std::back_inserter(res), {fmt.begin(), fmt.end()}, std::make_format_args(degs));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <bool NORM = false>
|
||||
static std::string rad2deg_str(double ang, int prec = 2)
|
||||
static std::string rad2deg_str(double ang, int prec = 6)
|
||||
{
|
||||
return rad2deg_str<std::string, NORM>(ang, prec);
|
||||
}
|
||||
|
||||
|
||||
template <std::ranges::output_range<char> R, bool NORM = false>
|
||||
static R rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 2, int prec2 = 2)
|
||||
static R rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 6, int prec2 = 6)
|
||||
{
|
||||
R res = rad2deg_str<R, NORM>(ang1, prec1);
|
||||
|
||||
R r = rad2deg_str<R, NORM>(ang2, prec2);
|
||||
|
||||
std::ranges::copy(std::back_inserter(res), delim);
|
||||
std::ranges::copy(std::back_inserter(res), r);
|
||||
std::ranges::copy(delim, std::back_inserter(res));
|
||||
std::ranges::copy(r, std::back_inserter(res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <bool NORM = false>
|
||||
static std::string rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 2, int prec2 = 2)
|
||||
static std::string rad2deg_str(double ang1, double ang2, std::string_view delim = ",", int prec1 = 6, int prec2 = 6)
|
||||
{
|
||||
return rad2deg_str<std::string, NORM>(ang1, ang2, delim, prec1, prec2);
|
||||
}
|
||||
@@ -203,7 +206,8 @@ static R rad2sxg(double ang, bool hms = false, int prec = 2)
|
||||
{
|
||||
R res;
|
||||
|
||||
std::string fmt = "{:02d}:{:02d}:{:0" + std::to_string(prec + 3) + "." + std::to_string(prec) + "f}";
|
||||
std::string fmt = "{:02.0f}:{:02.0f}:{:0" + std::to_string(prec + 3) + "." + std::to_string(prec) + "f}";
|
||||
// std::string fmt = "{:02.0f}:{:02.0f}:{:02." + std::to_string(prec) + "f}";
|
||||
|
||||
auto degs = rad2deg<NORM>(std::abs(ang));
|
||||
if (hms) {
|
||||
@@ -219,7 +223,7 @@ static R rad2sxg(double ang, bool hms = false, int prec = 2)
|
||||
std::ranges::copy(std::string_view("-"), std::back_inserter(res));
|
||||
}
|
||||
|
||||
std::vformat_to(std::back_inserter(res), {fmt.begin(), fmt.end()}, d, m, s);
|
||||
std::vformat_to(std::back_inserter(res), std::string_view{fmt.begin(), fmt.end()}, std::make_format_args(d, m, s));
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -238,8 +242,8 @@ static R RADEC_rad2sxg(double ra, double dec, std::string_view delim = ",", int
|
||||
|
||||
R r = rad2sxg(dec, false, dec_prec);
|
||||
|
||||
std::ranges::copy(std::back_inserter(res), delim);
|
||||
std::ranges::copy(std::back_inserter(res), r);
|
||||
std::ranges::copy(delim, std::back_inserter(res));
|
||||
std::ranges::copy(r, std::back_inserter(res));
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -258,8 +262,8 @@ static R AZZD_rad2sxg(double az, double zd, std::string_view delim = ",", int az
|
||||
|
||||
R r = rad2sxg(zd, false, zd_prec);
|
||||
|
||||
std::ranges::copy(std::back_inserter(res), delim);
|
||||
std::ranges::copy(std::back_inserter(res), r);
|
||||
std::ranges::copy(delim, std::back_inserter(res));
|
||||
std::ranges::copy(r, std::back_inserter(res));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user