rename MccCoordinate to MccAngle

This commit is contained in:
Timur A. Fatkhullin 2025-04-21 18:42:21 +03:00
parent 67340d1926
commit 9315018bda
5 changed files with 73 additions and 73 deletions

View File

@ -55,7 +55,7 @@ static constexpr MccHMSTag mcc_hms{};
// coordinate representation class
class MccCoordinate
class MccAngle
{
protected:
double _angleInRads{0.0};
@ -68,25 +68,25 @@ public:
NORM_KIND_90_90, // [-90,90]
};
MccCoordinate() = default;
MccAngle() = default;
// by default angle is in radians
MccCoordinate(std::convertible_to<double> auto const& val, const MccRadianTag tag = MccRadianTag{})
MccAngle(std::convertible_to<double> auto const& val, const MccRadianTag tag = MccRadianTag{})
: _angleInRads(val)
{
}
// construct angle in degrees, e.g.:
// auto ang = MccCoordinate{180.0, mcc_degrees};
MccCoordinate(std::convertible_to<double> auto const& val, const MccDegreeTag tag)
// auto ang = MccAngle{180.0, mcc_degrees};
MccAngle(std::convertible_to<double> auto const& val, const MccDegreeTag tag)
{
_angleInRads = val * utils::deg2radCoeff;
}
// constuct angle from sexagesimal representation or floating-point number of degrees, e.g.:
// auto ang = MccCoordinate{"-12:34:56.789"}; // from degrees:minutes:seconds
// auto ang = MccCoordinate{"123.574698"}; // from degrees
MccCoordinate(traits::mcc_input_char_range auto const& val)
// auto ang = MccAngle{"-12:34:56.789"}; // from degrees:minutes:seconds
// auto ang = MccAngle{"123.574698"}; // from degrees
MccAngle(traits::mcc_input_char_range auto const& val)
{
auto res = utils::parsAngleString(val);
if (res.has_value()) {
@ -97,9 +97,9 @@ public:
}
// construct angle from sexagesimal representation or floating-point number of degrees, e.g.:
// auto ang = MccCoordinate{"01:23:45.6789", mcc_hms}; // from hours:minutes:seconds
// auto ang = MccCoordinate{"123.574698"}; // from degrees
MccCoordinate(traits::mcc_input_char_range auto const& val, const MccHMSTag)
// auto ang = MccAngle{"01:23:45.6789", mcc_hms}; // from hours:minutes:seconds
// auto ang = MccAngle{"123.574698"}; // from degrees
MccAngle(traits::mcc_input_char_range auto const& val, const MccHMSTag)
{
auto res = utils::parsAngleString(val, true);
if (res.has_value()) {
@ -109,11 +109,11 @@ public:
}
}
virtual ~MccCoordinate() = default;
virtual ~MccAngle() = default;
// normalize coordinate
template <norm_kind_t KIND>
MccCoordinate& normalize()
MccAngle& normalize()
{
_angleInRads = std::fmod(_angleInRads, std::numbers::pi * 2.0);
@ -142,7 +142,7 @@ public:
return *this;
}
MccCoordinate& normalize()
MccAngle& normalize()
{
return normalize<NORM_KIND_0_360>();
}
@ -175,68 +175,68 @@ public:
return sexagesimal<std::string>(hms, prec);
}
friend MccCoordinate operator+(std::convertible_to<MccCoordinate> auto&& left,
std::convertible_to<MccCoordinate> auto&& right)
friend MccAngle operator+(std::convertible_to<MccAngle> auto&& left,
std::convertible_to<MccAngle> auto&& right)
{
// return std::forward<decltype(left)>(left)._angleInRads +
// std::forward<decltype(right)>(right)._angleInRads;
return MccCoordinate{std::forward<decltype(left)>(left)}._angleInRads +
MccCoordinate{std::forward<decltype(right)>(right)}._angleInRads;
return MccAngle{std::forward<decltype(left)>(left)}._angleInRads +
MccAngle{std::forward<decltype(right)>(right)}._angleInRads;
}
// friend MccCoordinate operator+(const MccCoordinate& left, const MccCoordinate& right)
// friend MccAngle operator+(const MccAngle& left, const MccAngle& right)
// {
// return left._angleInRads + right._angleInRads;
// }
friend MccCoordinate operator-(std::convertible_to<MccCoordinate> auto&& left,
std::convertible_to<MccCoordinate> auto&& right)
friend MccAngle operator-(std::convertible_to<MccAngle> auto&& left,
std::convertible_to<MccAngle> auto&& right)
{
// return std::forward<decltype(left)>(left)._angleInRads -
// std::forward<decltype(right)>(right)._angleInRads;
return MccCoordinate{std::forward<decltype(left)>(left)}._angleInRads -
MccCoordinate{std::forward<decltype(right)>(right)}._angleInRads;
return MccAngle{std::forward<decltype(left)>(left)}._angleInRads -
MccAngle{std::forward<decltype(right)>(right)}._angleInRads;
}
// friend MccCoordinate operator-(const MccCoordinate& left, const MccCoordinate& right)
// friend MccAngle operator-(const MccAngle& left, const MccAngle& right)
// {
// return left._angleInRads + right._angleInRads;
// }
template <typename T>
MccCoordinate operator*(T&& scalar)
MccAngle operator*(T&& scalar)
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
{
return _angleInRads * scalar;
}
template <typename T>
MccCoordinate operator/(T&& scalar)
MccAngle operator/(T&& scalar)
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
{
return _angleInRads / scalar;
}
template <typename T>
MccCoordinate operator-() // unary '-'
MccAngle operator-() // unary '-'
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
{
return -_angleInRads;
}
MccCoordinate& operator+=(const MccCoordinate& v)
MccAngle& operator+=(const MccAngle& v)
{
_angleInRads += v._angleInRads;
return *this;
}
MccCoordinate& operator-=(const MccCoordinate& v)
MccAngle& operator-=(const MccAngle& v)
{
_angleInRads += v._angleInRads;
return *this;
}
template <typename T>
MccCoordinate& operator*=(T&& scalar)
MccAngle& operator*=(T&& scalar)
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
{
_angleInRads *= scalar;
@ -244,19 +244,19 @@ public:
}
template <typename T>
MccCoordinate& operator/=(T&& scalar)
MccAngle& operator/=(T&& scalar)
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
{
_angleInRads /= scalar;
return *this;
}
auto operator<=>(const MccCoordinate& other) const
auto operator<=>(const MccAngle& other) const
{
return _angleInRads <=> other._angleInRads;
}
auto operator==(const MccCoordinate& other) const
auto operator==(const MccAngle& other) const
{
return _angleInRads == other._angleInRads;
}
@ -279,7 +279,7 @@ enum class MccNormCoordKind {
};
template <MccNormCoordKind KIND = MccNormCoordKind::NORM_KIND_0_360>
class MccNormCoordinate : public MccCoordinate
class MccNormCoordinate : public MccAngle
{
public:
static constexpr MccNormCoordKind normKind = KIND;

View File

@ -254,7 +254,7 @@ public:
_geoLocation.store(geoloc);
}
void setSiteLatitude(const MccCoordinate& lat)
void setSiteLatitude(const MccAngle& lat)
{
auto st = _geoLocation.load();
st.latitude = lat;
@ -262,7 +262,7 @@ public:
_geoLocation.store(st);
}
void setSiteLongitude(const MccCoordinate& lon)
void setSiteLongitude(const MccAngle& lon)
{
auto st = _geoLocation.load();
st.longitude = lon;
@ -330,8 +330,8 @@ public:
// 0 - already in the zone
// std::chrono::duration<>::max() - never reach the zone
// the kind of cordinates (e.g. IRCS or apparent, equatorial or horizontal) is a subject of implementation
auto pzTimeTo(const MccCoordinate& xcoord,
const MccCoordinate& ycoord,
auto pzTimeTo(const MccAngle& xcoord,
const MccAngle& ycoord,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
using d_t = std::remove_cvref_t<decltype(utc)>::duration;
@ -343,8 +343,8 @@ public:
// 0 - already out of the zone
// std::chrono::duration<>::max() - the zone itself
// the kind of cordinates (e.g. IRCS or apparent, equatorial or horizontal) is a subject of implementation
auto pzTimeFrom(const MccCoordinate& xcoord,
const MccCoordinate& ycoord,
auto pzTimeFrom(const MccAngle& xcoord,
const MccAngle& ycoord,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
using d_t = std::remove_cvref_t<decltype(utc)>::duration;
@ -360,8 +360,8 @@ public:
// never exit the zone)
auto pzCheck(this auto&& self,
const MccCoordinate& xcoord,
const MccCoordinate& ycoord,
const MccAngle& xcoord,
const MccAngle& ycoord,
std::derived_from<MccProhibitedZoneContext> auto const& context,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
@ -373,8 +373,8 @@ public:
const R2& ycoord,
std::derived_from<MccProhibitedZoneContext> auto const& context)
requires(std::ranges::output_range<OR, pzcheck_result_t<>> &&
std::derived_from<std::ranges::range_value_t<R1>, MccCoordinate> &&
std::derived_from<std::ranges::range_value_t<R2>, MccCoordinate>)
std::derived_from<std::ranges::range_value_t<R1>, MccAngle> &&
std::derived_from<std::ranges::range_value_t<R2>, MccAngle>)
{
OR res;
@ -390,8 +390,8 @@ public:
auto pzCheckRange(const R1& xcoord,
const R2& ycoord,
std::derived_from<MccProhibitedZoneContext> auto const& context)
requires(std::derived_from<std::ranges::range_value_t<R1>, MccCoordinate> &&
std::derived_from<std::ranges::range_value_t<R2>, MccCoordinate>)
requires(std::derived_from<std::ranges::range_value_t<R1>, MccAngle> &&
std::derived_from<std::ranges::range_value_t<R2>, MccAngle>)
{
return pzCheckRange<std::vector<pzcheck_result_t<>>>(xcoord, ycoord, context);
}
@ -445,8 +445,8 @@ protected:
std::atomic<MccMountMeteo> _currentMeteo;
// default implementation
auto pzCheckImpl(const MccCoordinate& xcoord,
const MccCoordinate& ycoord,
auto pzCheckImpl(const MccAngle& xcoord,
const MccAngle& ycoord,
std::derived_from<MccProhibitedZoneContext> auto const& context,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{

View File

@ -169,11 +169,11 @@ static int mcc_julday(traits::mcc_systime_c auto const& start_time,
* .second = time duration to reach given altitude AFTER object upper culmination
*/
std::pair<std::chrono::duration<double>, std::chrono::duration<double>> mcc_time_to_alt(
const MccCoordinate& alt_limit,
const MccCoordinate& ra,
const MccCoordinate& dec,
const MccCoordinate& lat,
const MccCoordinate& lon,
const MccAngle& alt,
const MccAngle& ra,
const MccAngle& dec,
const MccAngle& lat,
const MccAngle& lon,
traits::mcc_systime_c auto const& now,
traits::mcc_time_duration_c auto const& dut1, // UT1-UTC
traits::mcc_time_duration_c auto const& tt_tai, // TT-TAI
@ -183,7 +183,7 @@ std::pair<std::chrono::duration<double>, std::chrono::duration<double>> mcc_time
auto nan_dur = std::chrono::duration<double>(std::numeric_limits<double>::quiet_NaN());
auto inf_dur = std::chrono::duration<double>(std::numeric_limits<double>::infinity());
if (alt_limit < 0.0) {
if (alt < 0.0) {
return {nan_dur, nan_dur};
}
@ -197,7 +197,7 @@ std::pair<std::chrono::duration<double>, std::chrono::duration<double>> mcc_time
}
}
double cos_ha = (std::sin(alt_limit) - std::sin(dec) * std::sin(lat)) / std::cos(dec) / std::cos(lat);
double cos_ha = (std::sin(alt) - std::sin(dec) * std::sin(lat)) / std::cos(dec) / std::cos(lat);
if (std::abs(cos_ha) > 1.0) { // it never reach given altitude
return {inf_dur, inf_dur};
}

View File

@ -17,14 +17,14 @@ concept mcc_prohibited_zone_c = requires(T t, const T const_t) {
// check if given coordinates are within the zone
{
t.inZone(std::declval<const MccCoordinate&>(), std::declval<const MccCoordinate&>(),
t.inZone(std::declval<const MccAngle&>(), std::declval<const MccAngle&>(),
std::declval<typename T::pzcoords_kind_t>())
} -> std::convertible_to<bool>;
// a time duration to reach the zone (0 - if already in the zone, chrono::duration<>::max() if never
// reach the zone)
{
t.timeTo(std::declval<const MccCoordinate&>(), std::declval<const MccCoordinate&>(),
t.timeTo(std::declval<const MccAngle&>(), std::declval<const MccAngle&>(),
std::declval<typename T::pzcoords_kind_t>(),
std::declval<const std::chrono::system_clock::time_point&>())
} -> mcc_time_duration_c;
@ -32,7 +32,7 @@ concept mcc_prohibited_zone_c = requires(T t, const T const_t) {
// a time duration to exit the zone (0 - if already out of the zone, chrono::duration<>::max() if
// never exit the zone)
{
t.timeFrom(std::declval<const MccCoordinate&>(), std::declval<const MccCoordinate&>(),
t.timeFrom(std::declval<const MccAngle&>(), std::declval<const MccAngle&>(),
std::declval<typename T::pzcoords_kind_t>(),
std::declval<const std::chrono::system_clock::time_point&>())
} -> mcc_time_duration_c;
@ -46,13 +46,13 @@ class MccProhibitedZone
public:
virtual ~MccProhibitedZone() = default;
bool inZone(this auto&& self, const MccCoordinate& x, const MccCoordinate& y)
bool inZone(this auto&& self, const MccAngle& x, const MccAngle& y)
{
return std::forward<decltype(self)>(self).inZoneImpl(x, y);
}
protected:
bool inZoneImpl(const MccCoordinate&, const MccCoordinate&)
bool inZoneImpl(const MccAngle&, const MccAngle&)
{
return false;
}
@ -61,9 +61,9 @@ protected:
class MccMinAltPZ : public MccProhibitedZone
{
public:
MccMinAltPZ(const MccCoordinate& min_alt) : _minAlt(min_alt) {}
MccMinAltPZ(const MccAngle& min_alt) : _minAlt(min_alt) {}
MccCoordinate minAlt() const
MccAngle minAlt() const
{
return _minAlt;
}
@ -71,7 +71,7 @@ public:
private:
double _minAlt;
bool inZoneImpl(const MccCoordinate& alt, const MccCoordinate&)
bool inZoneImpl(const MccAngle& alt, const MccAngle&)
{
return alt <= _minAlt;
}
@ -91,7 +91,7 @@ public:
private:
double _maxAlt;
bool inZoneImpl(const MccCoordinate& alt, const MccCoordinate&)
bool inZoneImpl(const MccAngle& alt, const MccAngle&)
{
return alt >= _maxAlt;
}
@ -139,11 +139,11 @@ private:
class MccEllipsePZ
{
public:
MccEllipsePZ(const MccCoordinate& xc,
const MccCoordinate& yc,
const MccCoordinate& a,
const MccCoordinate& b,
const MccCoordinate& theta = 0.0)
MccEllipsePZ(const MccAngle& xc,
const MccAngle& yc,
const MccAngle& a,
const MccAngle& b,
const MccAngle& theta = 0.0)
: _xc(xc), _yc(yc), _a(a), _b(b), _theta(theta), _tanXc(std::tan(xc)), _tanYc(std::tan(yc))
{
_tanYc *= std::sqrt(1.0 + _tanXc * _tanXc);
@ -168,7 +168,7 @@ public:
}
// circle
MccEllipsePZ(const MccCoordinate& xc, const MccCoordinate& yc, const MccCoordinate& a)
MccEllipsePZ(const MccAngle& xc, const MccAngle& yc, const MccAngle& a)
: mcc::MccEllipsePZ(xc, yc, a, a)
{
}
@ -178,7 +178,7 @@ private:
double _xc, _yc, _a, _b, _theta;
double _tanXc, _tanYc, cxx, cxy, cyy;
bool inZoneImpl(const MccCoordinate& x, const MccCoordinate& y)
bool inZoneImpl(const MccAngle& x, const MccAngle& y)
{
auto tanX = tan(x);
auto tanY = tan(y) * sqrt(1.0 + tanX * tanX);

View File

@ -124,7 +124,7 @@ int main(int argc, char* argv[])
std::cout << "\n\n\nMccCoordinate class test:\n";
mcc::MccCoordinate ra("12:00:00", mcc::mcc_hms);
mcc::MccAngle ra("12:00:00", mcc::mcc_hms);
std::cout << "sin(12h) = " << std::sin(ra) << "\n";
std::cout << "cos(12h) = " << std::cos(ra) << "\n";
@ -133,7 +133,7 @@ int main(int argc, char* argv[])
std::cout << "sin(18h) = " << std::sin(ra) << "\n";
std::cout << "cos(18h) = " << std::cos(ra) << "\n";
ra = mcc::MccCoordinate{45.0, mcc::mcc_degrees};
ra = mcc::MccAngle{45.0, mcc::mcc_degrees};
std::cout << "sin(45) = " << std::sin(ra) << "\n";
std::cout << "cos(45) = " << std::cos(ra) << "\n";