mountcontrol/cxx/mcc_mount_pz.h
2025-06-14 15:29:01 +03:00

99 lines
3.0 KiB
C++

#pragma once
/* MOUNT CONTROL COMPONENTS LIBRARY */
/* PROHIBITED ZONE IMPLEMENTATION */
#include <chrono>
#include <string_view>
#include "mcc_mount_coord.h"
#include "mcc_traits.h"
namespace mcc
{
class MccProhibitedZone
{
public:
// floating-point time duration (seconds)
typedef std::chrono::duration<double> pz_duration_t;
struct pz_request_t {
bool in_zone{false}; // true if given coordinates are within the zone
pz_duration_t time_to{0.0}; // a time duration to reach the zone
pz_duration_t time_from{0.0}; // a time duration to exit the zone
};
struct pz_context_t {
};
MccProhibitedZone(std::string_view name) : _name(name) {}
std::string_view name() const
{
return _name;
}
// check if given position (x,y) in the zone
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
bool inZone(const XT& x,
const YT& y,
const pz_context_t& context,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
static constexpr size_t coord_kind = traits::mcc_type_pair_hash<XT, YT>();
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(const XT& x,
const YT& y,
const pz_context_t& context,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
static constexpr size_t coord_kind = traits::mcc_type_pair_hash<XT, YT>();
}
// 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(const XT& x,
const YT& y,
const pz_context_t& context,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
static constexpr size_t coord_kind = traits::mcc_type_pair_hash<XT, YT>();
}
template <std::derived_from<MccAngle> XT, std::derived_from<MccAngle> YT>
pz_request_t request(const XT& x,
const YT& y,
const pz_context_t& context,
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
{
pz_request_t res{.in_zone = false, .time_to = pz_duration_t{0.0}, .time_from{0.0}};
res.in_zone = inZone(x, y, context, utc);
if (res.in_zone) {
res.time_from = timeFrom(x, y, context, utc);
} else {
res.time_to = timeFrom(x, y, context, utc);
}
return res;
}
protected:
std::string_view _name;
};
} // namespace mcc