This commit is contained in:
Timur A. Fatkhullin
2025-06-17 00:46:13 +03:00
parent 64a3544bd8
commit 02afd65d6f
5 changed files with 69 additions and 60 deletions

View File

@@ -39,53 +39,47 @@ public:
// check if given position (x,y) in the zone
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
bool inZone(this auto&& self,
const XT& x,
const YT& y,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
bool inZone(const XT&, const YT&, traits::mcc_systime_c auto const&)
{
return std::forward<decltype(self)>(self).inZoneImpl(x, y, utc);
return false;
}
// returns a time duration to reach the zone
// 0 - if already within
// Inf - if it never reaches the zone
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
pz_duration_t timeTo(this auto&& self,
const XT& x,
const YT& y,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
pz_duration_t timeTo(const XT&, const YT&, traits::mcc_systime_c auto const&)
{
return std::forward<decltype(self)>(self).timeToImpl(x, y, utc);
return pz_duration_t{std::numeric_limits<double>::infinity()};
}
// returns a time duration to exit from the zone
// 0 - if given position (x,y) is out of the zone
// Inf - if (x,y) is always within the zone
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
pz_duration_t timeFrom(this auto&& self,
const XT& x,
const YT& y,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
pz_duration_t timeFrom(const XT&, const YT&, traits::mcc_systime_c auto const&)
{
return std::forward<decltype(self)>(self).timeFromImpl(x, y, utc);
return pz_duration_t{0.0};
}
// all-in-one request (call three methods above)
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
pz_request_t request(const XT& x,
pz_request_t request(this auto&& self,
const XT& x,
const YT& y,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
using self_t = decltype(self);
pz_request_t res{.in_zone = false, .time_to = pz_duration_t{0.0}, .time_from{0.0}};
res.in_zone = inZone(x, y, utc);
res.in_zone = std::forward<self_t>(self).inZone(x, y, utc);
if (res.in_zone) {
res.time_from = timeFrom(x, y, utc);
res.time_from = std::forward<self_t>(self).timeFrom(x, y, utc);
} else {
res.time_to = timeFrom(x, y, utc);
res.time_to = std::forward<self_t>(self).timeTo(x, y, utc);
}
return res;
@@ -95,30 +89,10 @@ protected:
MccProhibitedZone(std::string_view name) : _name(name) {}
std::string_view _name;
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
bool inZoneImpl(const XT&, const YT&, traits::mcc_systime_c auto const&)
{
return false;
}
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
pz_duration_t timeToImpl(const XT&, const YT&, traits::mcc_systime_c auto const&)
{
return pz_duration_t{std::numeric_limits<double>::infinity()};
}
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
pz_duration_t timeFromImpl(const XT&, const YT&, traits::mcc_systime_c auto const&)
{
return pz_duration_t{0.0};
}
};
/* SOME PROHIBITED ZONE IMPLEMENTATIONS */
@@ -145,11 +119,8 @@ public:
_altLimit.normalize<MccAngle::NORM_KIND_90_90>();
}
private:
MccAngle _altLimit;
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
bool inZoneImpl(const XT& x, const YT& y, traits::mcc_systime_c auto const& utc)
bool inZone(const XT& x, const YT& y, traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
static constexpr MccCoordPairKind coord_kind = traits::mcc_type_pair_hash<XT, YT>();
@@ -160,7 +131,7 @@ private:
return y >= _altLimit;
}
} else if constexpr (coord_kind == MccCoordPairKind::COORDS_KIND_AZZD) { // trivial case
return inZoneImpl(x, MccAngleALT(std::numbers::pi / 2 - (double)y), utc);
return inZone(x, MccAngleALT(std::numbers::pi / 2 - (double)y), utc);
} else if constexpr (coord_kind == MccCoordPairKind::COORDS_KIND_HADEC_APP) {
// implementation ...
return false;
@@ -176,17 +147,25 @@ private:
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
pz_duration_t timeToImpl(const XT&, const YT&, traits::mcc_systime_c auto const&)
pz_duration_t timeTo(const XT& x,
const YT& y,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
return pz_duration_t{std::numeric_limits<double>::infinity()};
}
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
pz_duration_t timeFromImpl(const XT&, const YT&, traits::mcc_systime_c auto const&)
pz_duration_t timeFrom(const XT& x,
const YT& y,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
return pz_duration_t{0.0};
}
private:
MccAngle _altLimit;
};
} // namespace mcc