This commit is contained in:
Timur A. Fatkhullin
2026-02-02 02:36:23 +03:00
parent a4d6f17114
commit ae91e7320c
11 changed files with 1311 additions and 103 deletions

View File

@@ -69,6 +69,7 @@ public:
template <mcc_coord_epoch_c EpT = MccCelestialCoordEpoch>
MccCoordPair(CO_LON_T const& x, CO_LAT_T const& y, EpT const& epoch = EpT::now()) : _x(x), _y(y), _epoch(epoch)
{
normalize();
}
MccCoordPair(const MccCoordPair&) = default;
@@ -85,6 +86,8 @@ public:
setX((double)other.x());
setY((double)other.y());
setEpoch(other.epoch());
normalize();
}
@@ -96,6 +99,8 @@ public:
setX((double)other.x());
setY((double)other.y());
setEpoch(other.epoch());
normalize();
}
@@ -107,6 +112,8 @@ public:
setX((double)other.x());
setY((double)other.y());
setEpoch(other.epoch());
normalize();
}
@@ -118,6 +125,8 @@ public:
setX((double)other.x());
setY((double)other.y());
setEpoch(other.epoch());
normalize();
}
@@ -161,11 +170,15 @@ public:
void setX(const CO_LON_T& x)
{
_x = x;
normalize();
}
void setY(const CO_LAT_T& y)
{
_y = y;
normalize();
}
void setEpoch(mcc_coord_epoch_c auto const& ep)
@@ -178,6 +191,26 @@ protected:
CO_LAT_T _y;
MccCelestialCoordEpoch _epoch;
void normalize()
{
if constexpr (pairKind != MccCoordPairKind::COORDS_KIND_GENERIC &&
pairKind != MccCoordPairKind::COORDS_KIND_XY) {
if constexpr (pairKind == MccCoordPairKind::COORDS_KIND_HADEC_APP ||
pairKind == MccCoordPairKind::COORDS_KIND_HADEC_OBS) {
_x = (double)MccAngle(_x).normalize<MccAngle::NORM_KIND_180_180>();
} else { // RA, AZ
_x = (double)MccAngle(_x).normalize<MccAngle::NORM_KIND_0_360>();
}
// DEC and ALT is [-90,90] degrees
if constexpr (pairKind != MccCoordPairKind::COORDS_KIND_AZZD) {
_y = (double)MccAngle(_y).normalize<MccAngle::NORM_KIND_90_90>();
} else { // ZD id [0, 180] degrees
_y = (double)MccAngle(_y).normalize<MccAngle::NORM_KIND_0_180>();
}
}
}
};
@@ -436,7 +469,7 @@ public:
template <mcc_coord_pair_c PT>
operator PT()
operator PT() const
{
if constexpr (PT::pairKind == MccCoordPairKind::COORDS_KIND_LONLAT) { // returns geographic site coordinates
std::pair<double, double> pos;
@@ -447,7 +480,7 @@ public:
PT res;
to(res);
toAtSameEpoch(res);
return res;
}
@@ -457,8 +490,14 @@ public:
error_t toAtSameEpoch(PT& cpair, PTs&... cpairs) const
{
if constexpr (PT::pairKind != MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
cpair.setEpoch(_epoch);
if (_pairKind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) { // from ICRS: set current epoch for result
cpair.setEpoch(MccCelestialCoordEpoch::now());
} else {
cpair.setEpoch(_epoch);
}
}
auto err = toHelper(cpair);
if (err) {
return err;
@@ -620,6 +659,16 @@ protected:
// HA, DEC to AZ, ALT (AZ from the South through the West)
void hadec2azalt(double ha, double dec, double phi, double& az, double& alt) const
{
eraHd2ae(ha, dec, phi, &az, &alt);
// from ERFA "from N" to "from S"
if (az > std::numbers::pi) {
az -= std::numbers::pi;
} else {
az += std::numbers::pi;
}
return;
const auto cos_phi = std::cos(phi), sin_phi = std::sin(phi);
const auto cos_dec = std::cos(dec), sin_dec = std::sin(dec);
const auto cos_ha = std::cos(ha), sin_ha = std::sin(ha);
@@ -638,7 +687,6 @@ protected:
az = utils::isEqual(r, 0.0) ? 0.0 : std::atan2(y, x);
if (az < 0.0) {
// az += std::numbers::pi * 2.0; // to range of [0, 2*PI]
az += MCC_TWO_PI; // to range of [0, 2*PI]
}
@@ -649,6 +697,11 @@ protected:
// AZ, ALT to HA, DEC (AZ from the South through the West)
void azalt2hadec(double az, double alt, double phi, double& ha, double& dec) const
{
az += std::numbers::pi;
eraAe2hd(az, alt, phi, &ha, &dec);
return;
const auto cos_phi = std::cos(phi), sin_phi = std::sin(phi);
const auto cos_az = std::cos(az), sin_az = std::sin(az);
const auto cos_alt = std::cos(alt), sin_alt = std::sin(alt);
@@ -724,6 +777,11 @@ protected:
}
}
if (utils::isEqual(ra_icrs, MCC_TWO_PI)) {
ra_icrs = 0.0;
}
// here, from APP or OBS to ICRS and exit
if (pkind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS &&
PT::pairKind == MccCoordPairKind::COORDS_KIND_RADEC_ICRS) {
@@ -896,7 +954,26 @@ protected:
return error_t{};
};
return comp_func(pkind); // ran transformation
auto err = comp_func(pkind); // ran transformation
if (ra < 0.0) {
ra += MCC_TWO_PI;
cpair.setX(ra);
}
if (az < 0.0) {
az += MCC_TWO_PI;
cpair.setX(az);
}
// if (utils::isEqual(ra, MCC_TWO_PI)) {
// cpair.setX(0.0);
// }
// if (utils::isEqual(az, MCC_TWO_PI)) {
// cpair.setX(0.0);
// }
return err;
}
};