 |
LeviLamina
|
Loading...
Searching...
No Matches
5#include "ll/api/base/Macro.h"
7#define LL_VEC_X_MEMBER(T) \
11#define LL_VEC_Y_MEMBER(T) \
15#define LL_VEC_Z_MEMBER(T) \
19#define LL_VEC_W_MEMBER(T) \
26#define LL_VEC2_IMPL(NAME, BNAME, TYPE, BASE) \
27 class LL_EBO NAME : public BASE<BNAME, TYPE, TYPE> { \
29 LL_VEC_X_MEMBER(TYPE); \
31 TYPE y, g, t, z, b, p; \
34 [[nodiscard]] constexpr NAME(NAME&&) noexcept = default; \
35 LL_MAY_CONSTEXPR NAME& operator=(NAME&&) noexcept = default; \
36 [[nodiscard]] constexpr NAME(NAME const&) noexcept = default; \
37 LL_MAY_CONSTEXPR NAME& operator=(NAME const&) noexcept = default; \
39 [[nodiscard]] constexpr NAME(TYPE all = 0) noexcept : x(all), z(all) {} \
41 template <std::convertible_to<TYPE> T0, std::convertible_to<TYPE> T1> \
42 [[nodiscard]] constexpr NAME(T0 x, T1 z) noexcept \
43 : x(static_cast<TYPE>((std::is_floating_point_v<T0> && !std::is_floating_point_v<TYPE>) ? std::floor(x) : x)), \
45 static_cast<TYPE>((std::is_floating_point_v<T1> && !std::is_floating_point_v<TYPE>) ? std::floor(z) : z) \
47 template <IsField T> \
48 [[nodiscard]] constexpr NAME(T const& vec) \
49 requires((IsIntN<T> || IsFloatN<T> || IsBoolN<T>) && T::size() == 2) \
51 T::forEachComponent([&]<typename axis_type, size_t iter> { \
52 if constexpr (std::is_floating_point_v<axis_type> && !std::is_floating_point_v<TYPE>) { \
53 this->get<TYPE, iter>() = static_cast<TYPE>(std::floor(vec.template get<axis_type, iter>())); \
55 this->get<TYPE, iter>() = static_cast<TYPE>((vec.template get<axis_type, iter>())); \
59 template <typename T, size_t N> \
60 [[nodiscard]] constexpr T& get() noexcept { \
61 if constexpr (N == 0) { \
63 } else if constexpr (N == 1) { \
66 static_assert(ll::traits::always_false<T>); \
69 template <typename T, size_t N> \
70 [[nodiscard]] constexpr T const& get() const noexcept { \
71 if constexpr (N == 0) { \
73 } else if constexpr (N == 1) { \
76 static_assert(ll::traits::always_false<T>); \
81#define LL_VEC3_IMPL(NAME, BNAME, TYPE, BASE) \
82 class LL_EBO NAME : public BASE<BNAME, TYPE, TYPE, TYPE> { \
84 LL_VEC_X_MEMBER(TYPE); \
85 LL_VEC_Y_MEMBER(TYPE); \
86 LL_VEC_Z_MEMBER(TYPE); \
88 [[nodiscard]] constexpr NAME(NAME&&) = default; \
89 LL_MAY_CONSTEXPR NAME& operator=(NAME&&) = default; \
90 [[nodiscard]] constexpr NAME(NAME const&) = default; \
91 LL_MAY_CONSTEXPR NAME& operator=(NAME const&) = default; \
93 [[nodiscard]] constexpr NAME(TYPE all = 0) noexcept : x(all), y(all), z(all) {} \
95 template <std::convertible_to<TYPE> T0, std::convertible_to<TYPE> T1, std::convertible_to<TYPE> T2> \
96 [[nodiscard]] constexpr NAME(T0 x, T1 y, T2 z) noexcept \
97 : x(static_cast<TYPE>((std::is_floating_point_v<T0> && !std::is_floating_point_v<TYPE>) ? std::floor(x) : x)), \
98 y(static_cast<TYPE>((std::is_floating_point_v<T1> && !std::is_floating_point_v<TYPE>) ? std::floor(y) : y)), \
100 static_cast<TYPE>((std::is_floating_point_v<T2> && !std::is_floating_point_v<TYPE>) ? std::floor(z) : z) \
102 template <IsField T> \
103 [[nodiscard]] constexpr NAME(T const& vec) \
104 requires((IsIntN<T> || IsFloatN<T> || IsBoolN<T>) && T::size() == 3) \
106 T::forEachComponent([&]<typename axis_type, size_t iter> { \
107 if constexpr (std::is_floating_point_v<axis_type> && !std::is_floating_point_v<TYPE>) { \
108 this->get<TYPE, iter>() = static_cast<TYPE>(std::floor(vec.template get<axis_type, iter>())); \
110 this->get<TYPE, iter>() = static_cast<TYPE>((vec.template get<axis_type, iter>())); \
114 template <typename T, size_t N> \
115 [[nodiscard]] constexpr T& get() noexcept { \
116 if constexpr (N == 0) { \
118 } else if constexpr (N == 1) { \
120 } else if constexpr (N == 2) { \
123 static_assert(ll::traits::always_false<T>); \
126 template <typename T, size_t N> \
127 [[nodiscard]] constexpr T const& get() const noexcept { \
128 if constexpr (N == 0) { \
130 } else if constexpr (N == 1) { \
132 } else if constexpr (N == 2) { \
135 static_assert(ll::traits::always_false<T>); \
140#define LL_VEC4_IMPL(NAME, BNAME, TYPE, BASE) \
141 class LL_EBO NAME : public BASE<BNAME, TYPE, TYPE, TYPE, TYPE> { \
143 LL_VEC_X_MEMBER(TYPE); \
144 LL_VEC_Y_MEMBER(TYPE); \
145 LL_VEC_Z_MEMBER(TYPE); \
146 LL_VEC_W_MEMBER(TYPE); \
148 [[nodiscard]] constexpr NAME(NAME&&) = default; \
149 LL_MAY_CONSTEXPR NAME& operator=(NAME&&) = default; \
150 [[nodiscard]] constexpr NAME(NAME const&) = default; \
151 LL_MAY_CONSTEXPR NAME& operator=(NAME const&) = default; \
153 [[nodiscard]] constexpr NAME(TYPE all = 0) noexcept : x(all), y(all), z(all), w(all) {} \
156 std::convertible_to<TYPE> T0, \
157 std::convertible_to<TYPE> T1, \
158 std::convertible_to<TYPE> T2, \
159 std::convertible_to<TYPE> T3> \
160 [[nodiscard]] constexpr NAME(T0 x, T1 y, T2 z, T3 w) noexcept \
161 : x(static_cast<TYPE>((std::is_floating_point_v<T0> && !std::is_floating_point_v<TYPE>) ? std::floor(x) : x)), \
162 y(static_cast<TYPE>((std::is_floating_point_v<T1> && !std::is_floating_point_v<TYPE>) ? std::floor(y) : y)), \
163 z(static_cast<TYPE>((std::is_floating_point_v<T2> && !std::is_floating_point_v<TYPE>) ? std::floor(z) : z)), \
165 static_cast<TYPE>((std::is_floating_point_v<T3> && !std::is_floating_point_v<TYPE>) ? std::floor(w) : w) \
167 template <IsField T> \
168 [[nodiscard]] constexpr NAME(T const& vec) \
169 requires((IsIntN<T> || IsFloatN<T> || IsBoolN<T>) && T::size() == 4) \
171 T::forEachComponent([&]<typename axis_type, size_t iter> { \
172 if constexpr (std::is_floating_point_v<axis_type> && !std::is_floating_point_v<TYPE>) { \
173 this->get<TYPE, iter>() = static_cast<TYPE>(std::floor(vec.template get<axis_type, iter>())); \
175 this->get<TYPE, iter>() = static_cast<TYPE>((vec.template get<axis_type, iter>())); \
179 template <typename T, size_t N> \
180 [[nodiscard]] constexpr T& get() noexcept { \
181 if constexpr (N == 0) { \
183 } else if constexpr (N == 1) { \
185 } else if constexpr (N == 2) { \
187 } else if constexpr (N == 3) { \
190 static_assert(ll::traits::always_false<T>); \
193 template <typename T, size_t N> \
194 [[nodiscard]] constexpr T const& get() const noexcept { \
195 if constexpr (N == 0) { \
197 } else if constexpr (N == 1) { \
199 } else if constexpr (N == 2) { \
201 } else if constexpr (N == 3) { \
204 static_assert(ll::traits::always_false<T>); \