3 #include "core/az_el.h" 16 static constexpr
const auto& clamp(
const U& x,
const U& mini,
const U& maxi) {
19 return max(mini, min(maxi, x));
22 constexpr
float degrees(
float radians) {
return radians * 180 / M_PI; }
23 constexpr
float radians(
float degrees) {
return degrees * M_PI / 180; }
25 template <
typename T,
size_t azimuth_divisions,
size_t elevation_divisions>
27 static_assert(elevation_divisions % 2,
"elevation_divisions must be odd");
36 constexpr
auto& at(
index_pair i) {
return table[i.azimuth][i.elevation]; }
38 return table[i.azimuth][i.elevation];
43 static constexpr
auto get_azimuth_angle() {
44 return 360.0 / azimuth_divisions;
47 static constexpr
auto get_elevation_angle() {
48 return 180.0 / (elevation_divisions + 1);
53 static constexpr
size_t azimuth_to_index(
double azimuth) {
54 azimuth += get_azimuth_angle() / 2;
58 return static_cast<size_t>(azimuth / get_azimuth_angle()) %
62 static constexpr
size_t elevation_to_index(
double elevation) {
63 elevation += 90 + (get_elevation_angle() / 2);
64 while (elevation < 0) {
69 static_cast<size_t>(elevation / get_elevation_angle()) %
70 (2 * (elevation_divisions + 1));
72 if (elevation_divisions + 1 < adjusted) {
73 throw std::runtime_error{
"Elevation out of range."};
76 return clamp(adjusted, 1ul, elevation_divisions) - 1;
80 return {azimuth_to_index(azel.azimuth),
81 elevation_to_index(azel.elevation)};
86 static constexpr
auto index_to_azimuth(
size_t index) {
87 if (azimuth_divisions <= index) {
88 throw std::runtime_error{
"Index out of range."};
90 return (index * get_azimuth_angle());
93 static constexpr
auto index_to_elevation(
size_t index) {
94 if (elevation_divisions <= index) {
95 throw std::runtime_error{
"Index out of range."};
97 return ((index + 1) * get_elevation_angle()) - 90;
101 return {index_to_azimuth(i.azimuth), index_to_elevation(i.elevation)};
107 return compute_pointing(
108 az_el{-radians(index_to_azimuth(i.azimuth)),
109 radians(index_to_elevation(i.elevation))});
112 static auto index(
const glm::vec3& i) {
113 const auto radians = compute_azimuth_elevation(i);
114 return index_pair{azimuth_to_index(degrees(-radians.azimuth)),
115 elevation_to_index(degrees(radians.elevation))};
119 T
table[azimuth_divisions][elevation_divisions]{};
122 template <
typename T,
typename Alloc,
size_t Az,
size_t El>
123 void resize_if_necessary(
126 for (
auto& azimuth : t.table) {
127 for (
auto& elevation : azimuth) {
128 if (elevation.size() < new_size) {
129 elevation.resize(new_size);
Definition: vector_look_up_table.h:29
Definition: capsule_base.h:9
Definition: vector_look_up_table.h:26
T table[azimuth_divisions][elevation_divisions]
Using a C array because it's more constexpr-ready than std::array.
Definition: vector_look_up_table.h:119