16 #ifndef OPENKALMAN_COEFFICIENTS_INCLINATION_HPP 17 #define OPENKALMAN_COEFFICIENTS_INCLINATION_HPP 19 #include <type_traits> 24 #include "../../../basics/compatibility/language-features.hpp" 27 #include "values/functions/internal/update_real_part.hpp" 28 #include "values/math/abs.hpp" 29 #include "values/math/sin.hpp" 30 #include "values/math/cos.hpp" 31 #include "values/math/atan2.hpp" 33 #include "linear-algebra/coordinates/interfaces/coordinate_descriptor_traits.hpp" 49 template<values::fixed Down = values::fixed_minus_half_pi<
long double>, values::fixed Up = values::fixed_half_pi<
long double>>
50 requires (values::fixed_number_of_v<Up> - values::fixed_number_of_v<Down> > 0) and
53 template<
typename Down = values::fixed_minus_half_pi<
long double>,
typename Up = values::fixed_half_pi<
long double>>
57 #ifndef __cpp_concepts 58 static_assert(values::fixed<Down>);
59 static_assert(values::fixed<Up>);
60 static_assert(values::fixed_number_of_v<Up> - values::fixed_number_of_v<Down> > 0);
61 static_assert(values::fixed_number_of_v<Down> <= 0);
62 static_assert(values::fixed_number_of_v<Up> >= 0);
83 template<
typename Down,
typename Up>
95 static constexpr
bool inclination =
110 template<
typename Down,
typename Up>
116 static constexpr
auto down = values::fixed_number_of_v<Down>;
117 static constexpr
auto up = values::fixed_number_of_v<Up>;
121 static constexpr
bool is_specialized =
true;
124 static constexpr
auto 125 dimension(
const T&) {
return std::integral_constant<std::size_t, 1>{}; };
128 static constexpr
auto 129 stat_dimension(
const T&) {
return std::integral_constant<std::size_t, 2>{}; };
132 static constexpr
auto 133 is_euclidean(
const T&) {
return std::false_type{}; }
136 static constexpr
auto 139 constexpr
auto down_float =
static_cast<float>(down);
140 constexpr
auto up_float =
static_cast<float>(up);
141 constexpr
float a = (down_float * 3.f + up_float * 2.f) / (up_float - down_float);
142 constexpr
auto bits = std::numeric_limits<std::size_t>::digits;
143 if constexpr (bits < 32)
return 0x8CE6_uz +
static_cast<std::size_t
>(a * a * 0x1.p2f);
144 else if constexpr (bits < 64)
return 0x8CE6267E_uz +
static_cast<std::size_t
>(a * a * 0x1.p4f);
145 else return 0x8CE6267E341642F7_uz +
static_cast<std::size_t
>(a * a * 0x1.p8f);
156 #ifdef __cpp_concepts 158 to_euclidean_component(
const T& t,
const auto& g,
const values::index auto& euclidean_local_index)
161 template<
typename Getter,
typename L, std::enable_if_t<values::index<L> and
162 values::value<
typename std::invoke_result<const Getter&, std::
size_t>::type>,
int> = 0>
163 static constexpr
auto 167 using Scalar = std::decay_t<decltype(g(0_uz))>;
168 using R = std::decay_t<decltype(values::real(std::declval<Scalar>()))>;
169 const Scalar cf {numbers::pi_v<R> / (up - down)};
170 const Scalar horiz {R{up + down} * R{0.5}};
172 Scalar theta = cf * (g(0_uz) - horiz);
174 if (euclidean_local_index == 0)
return values::cos(theta);
183 #ifdef __cpp_concepts 185 from_euclidean_component(
const T& t,
const auto& g,
const values::index auto& local_index)
188 template<
typename Getter,
typename L, std::enable_if_t<values::index<L> and
189 values::value<
typename std::invoke_result<const Getter&, std::
size_t>::type>,
int> = 0>
190 static constexpr
auto 194 using Scalar = std::decay_t<decltype(g(0_uz))>;
195 using R = std::decay_t<decltype(values::real(std::declval<Scalar>()))>;
196 const Scalar cf {numbers::pi_v<R> / (up - down)};
197 const Scalar horiz {R{up + down} * R{0.5}};
204 if constexpr (values::complex<Scalar>)
return values::atan2(y, pos_x) / cf + horiz;
211 static constexpr std::decay_t<A> wrap_impl(
A&& a)
214 if (ap >= down and ap <= up)
216 return std::forward<decltype(a)>(a);
220 using R = std::decay_t<decltype(ap)>;
221 constexpr R range {up - down};
222 constexpr R period {range * 2};
224 auto ar = fmod(ap - R{down}, period);
226 if (ar < 0)
return values::internal::update_real_part(std::forward<decltype(a)>(a), R{down} + ar + period);
227 else if (ar > range)
return values::internal::update_real_part(std::forward<decltype(a)>(a), R{down} - ar + period);
228 else return values::internal::update_real_part(std::forward<decltype(a)>(a), R{down} + ar);
237 #ifdef __cpp_concepts 239 get_wrapped_component(
const T& t,
const auto& g,
const values::index auto& local_index)
242 template<
typename Getter,
typename L, std::enable_if_t<values::index<L> and
243 values::value<
typename std::invoke_result<const Getter&, std::
size_t>::type>,
int> = 0>
244 static constexpr
auto 248 return wrap_impl(g(0_uz));
255 #ifdef __cpp_concepts 256 static constexpr
void 257 set_wrapped_component(
const T& t,
const auto& s,
const auto& g,
const values::value auto& x,
const values::index auto& local_index)
258 requires requires(std::size_t i){ s(x, i); s(g(i), i); }
260 template<
typename Setter,
typename Getter,
typename X,
typename L, std::enable_if_t<values::value<X> and values::index<L> and
261 std::is_invocable<const Setter&, const X&, std::
size_t>::value and
262 std::is_invocable<const Setter&,
typename std::invoke_result<const Getter&, std::
size_t>::type, std::
size_t>::value,
int> = 0>
263 static constexpr
void 267 s(wrap_impl(x), 0_uz);
276 #endif //OPENKALMAN_COEFFICIENTS_INCLINATION_HPP Definition for values::floating.
static constexpr auto to_euclidean_component(const T &t, const Getter &g, const L &euclidean_local_index)
Definition: Inclination.hpp:164
Definition: basics.hpp:41
A positive or negative real number φ representing an inclination or declination from the horizon...
Definition: Inclination.hpp:55
Definition: Inclination.hpp:81
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
constexpr auto sin(const Arg &arg)
Constexpr alternative to the std::sin function.
Definition: sin.hpp:43
constexpr auto cos(const Arg &arg, std::enable_if_t< values::value< Arg >, int >=0)
Constexpr alternative to the std::cos function.
Definition: cos.hpp:43
Definition: compares_with.hpp:28
constexpr auto fixed_number_of_v
Helper template for fixed_number_of.
Definition: fixed_number_of.hpp:84
constexpr auto atan2(const Y &y_arg, const X &x_arg)
Constexpr alternative to the std::atan2 function.
Definition: atan2.hpp:46
static constexpr auto from_euclidean_component(const T &t, const Getter &g, const L &local_index)
Definition: Inclination.hpp:191
constexpr auto real(Arg arg)
A constexpr function to obtain the real part of a (complex) number.
Definition: real.hpp:40
Traits for coordinates::pattern objects.
Definition: coordinate_descriptor_traits.hpp:41
constexpr auto abs(const Arg &arg)
A constexpr alternative to std::abs.
Definition: abs.hpp:38
static constexpr void set_wrapped_component(const T &t, const Setter &s, const Getter &g, const X &x, const L &local_index)
Definition: Inclination.hpp:264
constexpr bool index
T is an index value.
Definition: index.hpp:56
static constexpr auto get_wrapped_component(const T &t, const Getter &g, const L &local_index)
Definition: Inclination.hpp:245
A matrix with typed rows and columns.
Definition: forward-class-declarations.hpp:448