20 #ifndef ANTKEEPER_MATH_VECTOR_HPP
21 #define ANTKEEPER_MATH_VECTOR_HPP
31 #include <type_traits>
42 template <
class T, std::
size_t N>
58 template <
class U, std::size_t... I>
59 [[nodiscard]]
inline constexpr
vector<U, N> type_cast(std::index_sequence<I...>)
const noexcept
61 return {
static_cast<U
>(
elements[I])...};
72 [[nodiscard]]
inline constexpr
explicit operator vector<U, N>() const noexcept
74 return type_cast<U>(std::make_index_sequence<N>{});
78 template <std::size_t M, std::size_t... I>
79 [[nodiscard]]
inline constexpr
vector<T, M> size_cast(std::index_sequence<I...>)
const noexcept
81 return {(I < N) ?
elements[I] : T{0} ...};
91 template <std::
size_t M>
92 [[nodiscard]]
inline constexpr
explicit operator vector<T, M>() const noexcept
94 return size_cast<M>(std::make_index_sequence<M>{});
166 static_assert(N > 0,
"Vector does not contain an x element.");
171 static_assert(N > 0,
"Vector does not contain an x element.");
182 static_assert(N > 1,
"Vector does not contain a y element.");
187 static_assert(N > 1,
"Vector does not contain a y element.");
198 static_assert(N > 2,
"Vector does not contain a z element.");
203 static_assert(N > 2,
"Vector does not contain a z element.");
253 [[nodiscard]]
inline constexpr std::reverse_iterator<element_type*>
rbegin() noexcept
255 return std::reverse_iterator<element_type*>(
elements + N);
257 [[nodiscard]]
inline constexpr std::reverse_iterator<const element_type*>
rbegin() const noexcept
259 return std::reverse_iterator<const element_type*>(
elements + N);
261 [[nodiscard]]
inline constexpr std::reverse_iterator<const element_type*>
crbegin() const noexcept
263 return std::reverse_iterator<const element_type*>(
elements + N);
271 [[nodiscard]]
inline constexpr std::reverse_iterator<element_type*>
rend() noexcept
273 return std::reverse_iterator<element_type*>(
elements);
275 [[nodiscard]]
inline constexpr std::reverse_iterator<const element_type*>
rend() const noexcept
277 return std::reverse_iterator<const element_type*>(
elements);
279 [[nodiscard]]
inline constexpr std::reverse_iterator<const element_type*>
crend() const noexcept
281 return std::reverse_iterator<const element_type*>(
elements);
293 [[nodiscard]]
inline constexpr std::size_t
size() const noexcept
312 template <std::size_t... I>
313 [[nodiscard]]
inline static constexpr
vector one(std::index_sequence<I...>) noexcept
324 [[nodiscard]]
inline static constexpr
vector one() noexcept
326 return one(std::make_index_sequence<N>{});
330 template <std::size_t... I>
331 [[nodiscard]]
inline static constexpr
vector infinity(std::index_sequence<I...>) noexcept
336 return {(I ? std::numeric_limits<element_type>::infinity() : std::numeric_limits<
element_type>::
infinity())...};
344 return infinity(std::make_index_sequence<N>{});
351 namespace vector_types {
383 template <std::
size_t N>
396 template <std::
size_t N>
409 template <std::
size_t N>
422 template <std::
size_t N>
435 template <std::
size_t N>
445 using namespace vector_types;
457 template <
class T, std::
size_t N>
458 [[nodiscard]] constexpr vector<T, N>
abs(
const vector<T, N>&
x);
469 template <
class T, std::
size_t N>
470 [[nodiscard]] constexpr vector<T, N>
add(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
471 template <
class T, std::
size_t N>
472 [[nodiscard]] constexpr vector<T, N>
add(
const vector<T, N>&
x, T
y) noexcept;
482 template <std::
size_t N>
483 [[nodiscard]] constexpr
bool all(
const vector<bool, N>&
x) noexcept;
493 template <std::
floating_po
int T, std::
size_t N>
494 [[nodiscard]] T
angle(
const vector<T, N>& from,
const vector<T, N>& to);
503 template <std::
size_t N>
504 [[nodiscard]] constexpr
bool any(
const vector<bool, N>&
x) noexcept;
513 template <std::
floating_po
int T, std::
size_t N>
514 [[nodiscard]] constexpr vector<T, N>
ceil(
const vector<T, N>&
x);
526 template <
class T, std::
size_t N>
527 [[nodiscard]] constexpr vector<T, N>
clamp(
const vector<T, N>&
x,
const vector<T, N>&
min,
const vector<T, N>&
max);
528 template <
class T, std::
size_t N>
529 [[nodiscard]] constexpr vector<T, N>
clamp(
const vector<T, N>&
x, T
min, T
max);
540 template <std::
floating_po
int T, std::
size_t N>
541 [[nodiscard]] vector<T, N>
clamp_length(
const vector<T, N>&
x, T max_length);
552 [[nodiscard]] constexpr vector<T, 3>
cross(
const vector<T, 3>&
x,
const vector<T, 3>&
y) noexcept;
562 template <std::
floating_po
int T, std::
size_t N>
563 [[nodiscard]] T
distance(
const vector<T, N>& p0,
const vector<T, N>& p1);
574 template <
class T, std::
size_t N>
575 [[nodiscard]] constexpr vector<T, N>
div(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
576 template <
class T, std::
size_t N>
577 [[nodiscard]] constexpr vector<T, N>
div(
const vector<T, N>&
x, T
y) noexcept;
578 template <
class T, std::
size_t N>
579 [[nodiscard]] constexpr vector<T, N>
div(T
x,
const vector<T, N>&
y) noexcept;
590 template <
class T, std::
size_t N>
591 [[nodiscard]] constexpr T
dot(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
601 template <
class T, std::
size_t N>
602 [[nodiscard]] constexpr vector<bool, N>
equal(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
611 template <std::
floating_po
int T, std::
size_t N>
612 [[nodiscard]] constexpr vector<T, N>
floor(
const vector<T, N>&
x);
624 template <
class T, std::
size_t N>
625 [[nodiscard]] constexpr vector<T, N>
fma(
const vector<T, N>&
x,
const vector<T, N>&
y,
const vector<T, N>&
z);
626 template <
class T, std::
size_t N>
627 [[nodiscard]] constexpr vector<T, N>
fma(
const vector<T, N>&
x, T
y, T
z);
637 template <std::
floating_po
int T, std::
size_t N>
638 [[nodiscard]] constexpr vector<T, N>
fract(
const vector<T, N>&
x);
652 template<std::
size_t I,
class T, std::
size_t N>
654 template<std::
size_t I,
class T, std::
size_t N>
656 template<std::
size_t I,
class T, std::
size_t N>
658 template<std::
size_t I,
class T, std::
size_t N>
670 template <
class T, std::
size_t N>
671 [[nodiscard]] constexpr vector<bool, N>
greater_than(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
681 template <
class T, std::
size_t N>
682 [[nodiscard]] constexpr vector<bool, N>
greater_than_equal(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
691 template <std::
floating_po
int T, std::
size_t N>
701 template <std::
floating_po
int T, std::
size_t N>
702 [[nodiscard]] T
length(
const vector<T, N>&
x);
712 template <
class T, std::
size_t N>
713 [[nodiscard]] constexpr vector<bool, N>
less_than(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
723 template <
class T, std::
size_t N>
724 [[nodiscard]] constexpr vector<bool, N>
less_than_equal(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
734 template <
class T, std::
size_t N>
735 [[nodiscard]] constexpr vector<T, N>
max(
const vector<T, N>&
x,
const vector<T, N>&
y);
744 template <
class T, std::
size_t N>
745 [[nodiscard]] constexpr T
max(
const vector<T, N>&
x);
755 template <
class T, std::
size_t N>
756 [[nodiscard]] constexpr vector<T, N>
min(
const vector<T, N>&
x,
const vector<T, N>&
y);
765 template <
class T, std::
size_t N>
766 [[nodiscard]] constexpr T
min(
const vector<T, N>&
x);
777 template <std::
floating_po
int T, std::
size_t N>
778 [[nodiscard]] constexpr vector<T, N>
mod(
const vector<T, N>&
x,
const vector<T, N>&
y);
779 template <std::
floating_po
int T, std::
size_t N>
780 [[nodiscard]] constexpr vector<T, N>
mod(
const vector<T, N>&
x, T
y);
792 template <
class T, std::
size_t N>
793 [[nodiscard]] constexpr vector<T, N>
mul(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
794 template <
class T, std::
size_t N>
795 [[nodiscard]] constexpr vector<T, N>
mul(
const vector<T, N>&
x, T
y) noexcept;
805 template <
class T, std::
size_t N>
806 [[nodiscard]] constexpr vector<T, N>
negate(
const vector<T, N>&
x) noexcept;
815 template <std::
floating_po
int T, std::
size_t N>
816 [[nodiscard]] vector<T, N>
normalize(
const vector<T, N>&
x);
825 template <
class T, std::
size_t N>
826 [[nodiscard]] constexpr vector<bool, N>
logical_not(
const vector<T, N>&
x) noexcept;
836 template <
class T, std::
size_t N>
837 [[nodiscard]] constexpr vector<bool, N>
not_equal(
const vector<T, N>&
x,
const vector<T, N>&
y) noexcept;
848 template <std::
floating_po
int T, std::
size_t N>
849 [[nodiscard]] vector<T, N>
pow(
const vector<T, N>&
x,
const vector<T, N>&
y);
850 template <std::
floating_po
int T, std::
size_t N>
851 [[nodiscard]] vector<T, N>
pow(
const vector<T, N>&
x, T
y);
861 template <std::
floating_po
int T, std::
size_t N>
862 [[nodiscard]] constexpr vector<T, N>
round(
const vector<T, N>&
x);
870 template <std::
floating_po
int T, std::
size_t N>
871 [[nodiscard]] constexpr vector<T, N>
sign(
const vector<T, N>&
x);
882 template <std::
floating_po
int T>
883 [[nodiscard]] T
signed_angle(
const vector<T, 3>&
x,
const vector<T, 3>&
y,
const vector<T, 3>& n);
893 template <
class T, std::
size_t N>
894 [[nodiscard]] constexpr T
sqr_distance(
const vector<T, N>& p0,
const vector<T, N>& p1) noexcept;
903 template <
class T, std::
size_t N>
904 [[nodiscard]] constexpr T
sqr_length(
const vector<T, N>&
x) noexcept;
913 template <std::
floating_po
int T, std::
size_t N>
925 template <
class T, std::
size_t N>
927 template <
class T, std::
size_t N>
929 template <
class T, std::
size_t N>
939 template <
class T, std::
size_t N>
953 template <std::size_t... Indices,
class T, std::size_t N>
974 template <std::
floating_po
int T, std::
size_t N>
978 template <
class T, std::size_t N, std::size_t... I>
981 return {std::abs(
x[I])...};
984 template <
class T, std::
size_t N>
987 return abs(
x, std::make_index_sequence<N>{});
991 template <
class T, std::size_t N, std::size_t... I>
992 inline constexpr vector<T, N>
add(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
994 return {(
x[I] +
y[I])...};
997 template <
class T, std::
size_t N>
1000 return add(
x,
y, std::make_index_sequence<N>{});
1004 template <
class T, std::size_t N, std::size_t... I>
1005 inline constexpr vector<T, N>
add(
const vector<T, N>&
x, T
y, std::index_sequence<I...>) noexcept
1007 return {(
x[I] +
y)...};
1010 template <
class T, std::
size_t N>
1013 return add(
x,
y, std::make_index_sequence<N>{});
1017 template <std::size_t N, std::size_t... I>
1018 inline constexpr
bool all(
const vector<bool, N>&
x, std::index_sequence<I...>) noexcept
1020 return (
x[I] && ...);
1023 template <std::
size_t N>
1026 return all(
x, std::make_index_sequence<N>{});
1029 template <std::
floating_po
int T, std::
size_t N>
1032 return std::acos(std::min<T>(std::max<T>(
dot(from, to), T{-1}), T{1}));
1036 template <std::size_t N, std::size_t... I>
1037 inline constexpr
bool any(
const vector<bool, N>&
x, std::index_sequence<I...>) noexcept
1039 return (
x[I] || ...);
1042 template <std::
size_t N>
1045 return any(
x, std::make_index_sequence<N>{});
1049 template <std::floating_point T, std::size_t N, std::size_t... I>
1050 inline constexpr vector<T, N>
ceil(
const vector<T, N>&
x, std::index_sequence<I...>)
1052 return {std::ceil(
x[I])...};
1055 template <std::
floating_po
int T, std::
size_t N>
1058 return ceil(
x, std::make_index_sequence<N>{});
1062 template <
class T, std::size_t N, std::size_t... I>
1063 inline constexpr vector<T, N>
clamp(
const vector<T, N>&
x,
const vector<T, N>& min_val,
const vector<T, N>& max_val, std::index_sequence<I...>)
1065 return {std::min<T>(max_val[I], std::max<T>(min_val[I],
x[I]))...};
1068 template <
class T, std::
size_t N>
1071 return clamp(
x,
min,
max, std::make_index_sequence<N>{});
1075 template <
class T, std::size_t N, std::size_t... I>
1076 inline constexpr vector<T, N>
clamp(
const vector<T, N>&
x, T
min, T
max, std::index_sequence<I...>)
1078 return {std::min<T>(
max, std::max<T>(
min,
x[I]))...};
1081 template <
class T, std::
size_t N>
1084 return clamp(
x,
min,
max, std::make_index_sequence<N>{});
1087 template <std::
floating_po
int T, std::
size_t N>
1091 return (length2 > max_length * max_length) ? (
x * (max_length /
std::sqrt(length2))) :
x;
1099 x[1] *
y[2] -
x[2] *
y[1],
1100 x[2] *
y[0] -
x[0] *
y[2],
1101 x[0] *
y[1] -
x[1] *
y[0]
1105 template <std::
floating_po
int T, std::
size_t N>
1112 template <
class T, std::size_t N, std::size_t... I>
1113 inline constexpr vector<T, N>
div(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1115 return {(
x[I] /
y[I])...};
1118 template <
class T, std::
size_t N>
1121 return div(
x,
y, std::make_index_sequence<N>{});
1125 template <
class T, std::size_t N, std::size_t... I>
1126 inline constexpr vector<T, N>
div(
const vector<T, N>&
x, T
y, std::index_sequence<I...>) noexcept
1128 return {(
x[I] /
y)...};
1131 template <
class T, std::
size_t N>
1134 return div(
x,
y, std::make_index_sequence<N>{});
1138 template <
class T, std::size_t N, std::size_t... I>
1139 inline constexpr vector<T, N>
div(T
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1141 return {(
x /
y[I])...};
1144 template <
class T, std::
size_t N>
1147 return div(
x,
y, std::make_index_sequence<N>{});
1151 template <
class T, std::size_t N, std::size_t... I>
1152 inline constexpr T
dot(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1154 return ((
x[I] *
y[I]) + ...);
1157 template <
class T, std::
size_t N>
1160 return dot(
x,
y, std::make_index_sequence<N>{});
1164 template <
class T, std::size_t N, std::size_t... I>
1165 inline constexpr vector<bool, N>
equal(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1167 return {(
x[I] ==
y[I])...};
1170 template <
class T, std::
size_t N>
1173 return equal(
x,
y, std::make_index_sequence<N>{});
1177 template <std::floating_point T, std::size_t N, std::size_t... I>
1178 inline constexpr vector<T, N>
floor(
const vector<T, N>&
x, std::index_sequence<I...>)
1180 return {std::floor(
x[I])...};
1183 template <std::
floating_po
int T, std::
size_t N>
1186 return floor(
x, std::make_index_sequence<N>{});
1190 template <std::floating_point T, std::size_t N, std::size_t... I>
1191 inline constexpr vector<T, N>
fma(
const vector<T, N>&
x,
const vector<T, N>&
y,
const vector<T, N>&
z, std::index_sequence<I...>)
1193 return {std::fma(
x[I],
y[I],
z[I])...};
1196 template <std::
floating_po
int T, std::
size_t N>
1199 return fma(
x,
y,
z, std::make_index_sequence<N>{});
1203 template <std::floating_point T, std::size_t N, std::size_t... I>
1204 inline constexpr vector<T, N>
fma(
const vector<T, N>&
x, T
y, T
z, std::index_sequence<I...>)
1206 return {std::fma(
x[I],
y,
z)...};
1209 template <std::
floating_po
int T, std::
size_t N>
1212 return fma(
x,
y,
z, std::make_index_sequence<N>{});
1216 template <std::floating_point T, std::size_t N, std::size_t... I>
1217 inline constexpr vector<T, N>
fract(
const vector<T, N>&
x, std::index_sequence<I...>)
1219 return {
x[I] - std::floor(
x[I])...};
1222 template <std::
floating_po
int T, std::
size_t N>
1225 return fract(
x, std::make_index_sequence<N>{});
1228 template<std::
size_t I,
class T, std::
size_t N>
1231 static_assert(I < N);
1232 return v.elements[I];
1235 template<std::
size_t I,
class T, std::
size_t N>
1238 static_assert(I < N);
1239 return std::move(v.elements[I]);
1242 template<std::
size_t I,
class T, std::
size_t N>
1245 static_assert(I < N);
1246 return v.elements[I];
1249 template<std::
size_t I,
class T, std::
size_t N>
1252 static_assert(I < N);
1253 return std::move(v.elements[I]);
1257 template <
class T, std::size_t N, std::size_t... I>
1258 inline constexpr vector<bool, N>
greater_than(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1260 return {(
x[I] >
y[I])...};
1263 template <
class T, std::
size_t N>
1270 template <
class T, std::size_t N, std::size_t... I>
1271 inline constexpr vector<bool, N>
greater_than_equal(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1273 return {(
x[I] >=
y[I])...};
1276 template <
class T, std::
size_t N>
1282 template <std::
floating_po
int T, std::
size_t N>
1288 template <std::
floating_po
int T, std::
size_t N>
1295 template <
class T, std::size_t N, std::size_t... I>
1296 inline constexpr vector<bool, N>
less_than(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1298 return {(
x[I] <
y[I])...};
1301 template <
class T, std::
size_t N>
1304 return less_than(
x,
y, std::make_index_sequence<N>{});
1308 template <
class T, std::size_t N, std::size_t... I>
1309 inline constexpr vector<bool, N>
less_than_equal(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1311 return {(
x[I] <=
y[I])...};
1314 template <
class T, std::
size_t N>
1321 template <
class T, std::size_t N, std::size_t... I>
1322 inline constexpr vector<T, N>
max(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>)
1324 return {std::max<T>(
x[I],
y[I])...};
1327 template <
class T, std::
size_t N>
1330 return max(
x,
y, std::make_index_sequence<N>{});
1333 template <
class T, std::
size_t N>
1336 return *std::max_element(
x.elements,
x.elements + N);
1340 template <
class T, std::size_t N, std::size_t... I>
1341 inline constexpr vector<T, N>
min(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>)
1343 return {std::min<T>(
x[I],
y[I])...};
1346 template <
class T, std::
size_t N>
1349 return min(
x,
y, std::make_index_sequence<N>{});
1352 template <
class T, std::
size_t N>
1355 return *std::min_element(
x.elements,
x.elements + N);
1359 template <std::floating_point T, std::size_t N, std::size_t... I>
1360 inline constexpr vector<T, N>
mod(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>)
1362 return {std::fmod(
x[I],
y[I])...};
1365 template <std::
floating_po
int T, std::
size_t N>
1368 return mod(
x,
y, std::make_index_sequence<N>{});
1372 template <std::floating_point T, std::size_t N, std::size_t... I>
1373 inline constexpr vector<T, N>
mod(
const vector<T, N>&
x, T
y, std::index_sequence<I...>)
1375 return {std::fmod(
x[I],
y)...};
1378 template <std::
floating_po
int T, std::
size_t N>
1381 return mod(
x,
y, std::make_index_sequence<N>{});
1385 template <
class T, std::size_t N, std::size_t... I>
1386 inline constexpr vector<T, N>
mul(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1388 return {(
x[I] *
y[I])...};
1391 template <
class T, std::
size_t N>
1394 return mul(
x,
y, std::make_index_sequence<N>{});
1398 template <
class T, std::size_t N, std::size_t... I>
1399 inline constexpr vector<T, N>
mul(
const vector<T, N>&
x, T
y, std::index_sequence<I...>) noexcept
1401 return {(
x[I] *
y)...};
1404 template <
class T, std::
size_t N>
1407 return mul(
x,
y, std::make_index_sequence<N>{});
1411 template <
class T, std::size_t N, std::size_t... I>
1412 inline constexpr vector<T, N>
negate(
const vector<T, N>&
x, std::index_sequence<I...>) noexcept
1414 return {(-
x[I])...};
1417 template <
class T, std::
size_t N>
1420 return negate(
x, std::make_index_sequence<N>{});
1423 template <std::
floating_po
int T, std::
size_t N>
1430 template <
class T, std::size_t N, std::size_t... I>
1431 inline constexpr vector<bool, N>
logical_not(
const vector<T, N>&
x, std::index_sequence<I...>) noexcept
1436 template <
class T, std::
size_t N>
1443 template <
class T, std::size_t N, std::size_t... I>
1444 inline constexpr vector<bool, N>
not_equal(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1446 return {(
x[I] !=
y[I])...};
1449 template <
class T, std::
size_t N>
1452 return not_equal(
x,
y, std::make_index_sequence<N>{});
1456 template <std::floating_point T, std::size_t N, std::size_t... I>
1457 inline vector<T, N>
pow(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>)
1459 return {std::pow(
x[I],
y[I])...};
1462 template <std::
floating_po
int T, std::
size_t N>
1465 return pow(
x,
y, std::make_index_sequence<N>{});
1469 template <std::floating_point T, std::size_t N, std::size_t... I>
1470 inline vector<T, N>
pow(
const vector<T, N>&
x, T
y, std::index_sequence<I...>)
1472 return {std::pow(
x[I],
y)...};
1475 template <std::
floating_po
int T, std::
size_t N>
1478 return pow(
x,
y, std::make_index_sequence<N>{});
1482 template <std::floating_point T, std::size_t N, std::size_t... I>
1483 inline constexpr vector<T, N>
round(
const vector<T, N>&
x, std::index_sequence<I...>)
1485 return {std::round(
x[I])...};
1488 template <std::
floating_po
int T, std::
size_t N>
1491 return round(
x, std::make_index_sequence<N>{});
1495 template <std::floating_point T, std::size_t N, std::size_t... I>
1496 inline constexpr vector<T, N>
sign(
const vector<T, N>&
x, std::index_sequence<I...>)
1498 return {std::copysign(T{1},
x[I])...};
1501 template <std::
floating_po
int T, std::
size_t N>
1504 return sign(
x, std::make_index_sequence<N>{});
1507 template <std::
floating_po
int T>
1510 return std::atan2(
triple(axis, from, to),
dot(from, to));
1513 template <
class T, std::
size_t N>
1519 template <
class T, std::
size_t N>
1526 template <std::floating_point T, std::size_t N, std::size_t... I>
1527 inline vector<T, N>
sqrt(
const vector<T, N>&
x, std::index_sequence<I...>)
1532 template <std::
floating_po
int T, std::
size_t N>
1535 return sqrt(
x, std::make_index_sequence<N>{});
1539 template <
class T, std::size_t N, std::size_t... I>
1540 inline constexpr vector<T, N>
sub(
const vector<T, N>&
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1542 return {(
x[I] -
y[I])...};
1545 template <
class T, std::
size_t N>
1548 return sub(
x,
y, std::make_index_sequence<N>{});
1552 template <
class T, std::size_t N, std::size_t... I>
1553 inline constexpr vector<T, N>
sub(
const vector<T, N>&
x, T
y, std::index_sequence<I...>) noexcept
1555 return {(
x[I] -
y)...};
1558 template <
class T, std::
size_t N>
1561 return sub(
x,
y, std::make_index_sequence<N>{});
1565 template <
class T, std::size_t N, std::size_t... I>
1566 inline constexpr vector<T, N>
sub(T
x,
const vector<T, N>&
y, std::index_sequence<I...>) noexcept
1568 return {(
x -
y[I])...};
1571 template <
class T, std::
size_t N>
1574 return sub(
x,
y, std::make_index_sequence<N>{});
1578 template <
class T, std::size_t N, std::size_t... I>
1579 inline constexpr T
sum(
const vector<T, N>&
x, std::index_sequence<I...>) noexcept
1581 return (
x[I] + ...);
1584 template <
class T, std::
size_t N>
1587 return sum(
x, std::make_index_sequence<N>{});
1590 template <std::size_t... Indices,
class T, std::size_t N>
1593 return {
x[Indices]...};
1603 template <std::floating_point T, std::size_t N, std::size_t... I>
1604 inline constexpr vector<T, N>
trunc(
const vector<T, N>&
x, std::index_sequence<I...>)
1606 return {std::trunc(
x[I])...};
1609 template <std::
floating_po
int T, std::
size_t N>
1612 return trunc(
x, std::make_index_sequence<N>{});
1615 namespace operators {
1618 template <
class T, std::
size_t N>
1626 template <
class T, std::
size_t N>
1631 template <
class T, std::
size_t N>
1639 template <
class T, std::
size_t N>
1646 template <
class T, std::
size_t N>
1653 template <
class T, std::
size_t N>
1660 template <
class T, std::
size_t N>
1668 template <
class T, std::
size_t N>
1673 template <
class T, std::
size_t N>
1681 template <
class T, std::
size_t N>
1688 template <
class T, std::
size_t N>
1695 template <
class T, std::
size_t N>
1702 template <
class T, std::
size_t N>
1717 template <
class T, std::
size_t N>
1722 template <
class T, std::
size_t N>
1738 template <
class T, std::
size_t N>
1743 template <
class T, std::
size_t N>
1759 template <
class T, std::
size_t N>
1764 template <
class T, std::
size_t N>
1780 template <
class T, std::
size_t N>
1785 template <
class T, std::
size_t N>
1800 template <
class T, std::
size_t N>
1805 for (std::size_t i = 0; i < N; ++i)
1829 template <
class T, std::
size_t N>
1850 template<
class T, std::
size_t N>
1851 struct tuple_size<
math::vector<T, N>>
1864 template<std::
size_t I,
class T, std::
size_t N>
1865 struct tuple_element<I,
math::vector<T, N>>
1877 template <
class T, std::
size_t N>
1878 struct formatter<
math::vector<T, N>>: formatter<T>
1882 auto&& out = fc.out();
1883 format_to(out,
"{{");
1885 for (std::size_t i = 0; i < N; ++i)
1890 format_to(out,
", ");
1894 return format_to(out,
"}}");
1900 static_assert(std::is_standard_layout_v<math::fvec3>);
1901 static_assert(std::is_trivial_v<math::fvec3>);
format
Image and vertex formats.
constexpr vector< T, N > operator+(T x, const vector< T, N > &y) noexcept
constexpr vector< T, N > operator/(T x, const vector< T, N > &y) noexcept
Divides a vector by a value.
constexpr vector< T, N > & operator*=(vector< T, N > &x, T y) noexcept
Multiplies two values and stores the result in the first value.
constexpr vector< T, N > & operator-=(vector< T, N > &x, T y) noexcept
Subtracts the first value by the second value and stores the result in the first value.
constexpr vector< T, N > & operator/=(vector< T, N > &x, T y) noexcept
Divides the first value by the second value and stores the result in the first value.
constexpr vector< T, N > operator-(T x, const vector< T, N > &y) noexcept
Subtracts a value by another value.
constexpr vector< T, N > & operator+=(vector< T, N > &x, T y) noexcept
Adds two values and stores the result in the first value.
constexpr vector< T, N > operator*(T x, const vector< T, N > &y) noexcept
Multiplies two values.
constexpr bool operator==(const vector< T, N > &x, const vector< T, N > &y) noexcept
Tests two vector for equality.
constexpr bool operator!=(const vector< T, N > &x, const vector< T, N > &y) noexcept
Tests two vector for inequality.
Mathematical functions and data types.
T fract(T x)
Returns the fractional part of a floating-point number.
constexpr vector< T, N > sign(const vector< T, N > &x)
Returns a vector containing the signs of each element.
constexpr T sqr_distance(const vector< T, N > &p0, const vector< T, N > &p1) noexcept
Calculates the square distance between two points.
constexpr vector< bool, N > not_equal(const vector< T, N > &x, const vector< T, N > &y) noexcept
Compares two vectors for inequality.
constexpr vector< T, N > round(const vector< T, N > &x)
Performs a element-wise round operation.
constexpr vector< T, N > floor(const vector< T, N > &x)
Performs a element-wise floor operation.
T signed_angle(const vector< T, 3 > &x, const vector< T, 3 > &y, const vector< T, 3 > &n)
Calculates the signed angle between two direction vectors about axis.
constexpr matrix< T, P, M > mul(const matrix< T, N, M > &a, const matrix< T, P, N > &b) noexcept
Multiplies two matrices.
constexpr vector< T, N > trunc(const vector< T, N > &x)
Performs a element-wise trunc operation.
T angle(const vector< T, N > &from, const vector< T, N > &to)
Calculates the angle between two direction vectors.
constexpr vector< T, N > fma(const vector< T, N > &x, const vector< T, N > &y, const vector< T, N > &z)
Performs a multiply-add operation.
constexpr vector< T, sizeof...(Indices)> swizzle(const vector< T, N > &x) noexcept
Makes an m-dimensional vector by rearranging and/or duplicating elements of an n-dimensional vector.
vector< T, N > clamp_length(const vector< T, N > &x, T max_length)
Clamps the length of a vector.
constexpr vector< T, N > max(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the maximum elements of two vectors.
quaternion< T > normalize(const quaternion< T > &q)
Normalizes a quaternion.
constexpr matrix< T, N, M > div(const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
Divides a matrix by a matrix.
constexpr vector< T, N > mod(const vector< T, N > &x, const vector< T, N > &y)
Calculates the element-wise remainder of the division operation x / y.
T length(const quaternion< T > &q)
Calculates the length of a quaternion.
constexpr vector< T, N > ceil(const vector< T, N > &x)
Performs an element-wise ceil operation.
vector< T, N > pow(const vector< T, N > &x, const vector< T, N > &y)
Raises each element to a power.
constexpr matrix< T, N, M > add(const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
Adds two matrices.
constexpr vector< T, N > abs(const vector< T, N > &x)
Returns the absolute values of each element.
constexpr vector< bool, N > less_than_equal(const vector< T, N > &x, const vector< T, N > &y) noexcept
Performs a element-wise less-than or equal-to comparison of two vectors.
constexpr bool all(const vector< bool, N > &x) noexcept
Checks if all elements of a boolean vector are true.
constexpr T sqr_length(const quaternion< T > &q) noexcept
Calculates the square length of a quaternion.
constexpr vector< bool, N > logical_not(const vector< T, N > &x) noexcept
Logically inverts a boolean vector.
constexpr T triple(const vector< T, 3 > &x, const vector< T, 3 > &y, const vector< T, 3 > &z) noexcept
Calculates the triple product of three vectors.
constexpr vector< bool, N > less_than(const vector< T, N > &x, const vector< T, N > &y) noexcept
Performs a element-wise less-than comparison of two vectors.
constexpr vector< bool, N > equal(const vector< T, N > &x, const vector< T, N > &y) noexcept
Compares two vectors for equality.
T distance(const vector< T, N > &p0, const vector< T, N > &p1)
Calculates the distance between two points.
constexpr matrix< T, N, M > sub(const matrix< T, N, M > &a, const matrix< T, N, M > &b) noexcept
Subtracts a matrix from another matrix.
constexpr vector< T, N > clamp(const vector< T, N > &x, const vector< T, N > &min, const vector< T, N > &max)
Clamps the values of a vector's elements.
constexpr matrix< T, N, M >::column_vector_type & get(matrix< T, N, M > &m) noexcept
Extracts the Ith column from a matrix.
constexpr vector< bool, N > greater_than_equal(const vector< T, N > &x, const vector< T, N > &y) noexcept
Performs a element-wise greater-than or equal-to comparison of two vectors.
constexpr vector< T, 3 > cross(const vector< T, 3 > &x, const vector< T, 3 > &y) noexcept
Calculates the cross product of two vectors.
constexpr bool any(const vector< bool, N > &x) noexcept
Checks if any elements of a boolean vector are true.
constexpr vector< bool, N > greater_than(const vector< T, N > &x, const vector< T, N > &y) noexcept
Performs a element-wise greater-than comparison of two vectors.
vector< T, N > sqrt(const vector< T, N > &x)
Takes the square root of each element.
constexpr T dot(const quaternion< T > &a, const quaternion< T > &b) noexcept
Calculates the dot product of two quaternions.
vector< T, N > sqrt(const vector< T, N > &x, const vector< T, N > &y)
T inv_length(const quaternion< T > &q)
Calculates the inverse length of a quaternion.
constexpr T sum(const vector< T, N > &x) noexcept
Calculates the sum of all elements in a vector.
constexpr vector< T, N > min(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the minimum elements of two vectors.
constexpr quaternion< T > negate(const quaternion< T > &q) noexcept
Negates a quaternion.
constexpr const element_type & operator[](std::size_t i) const noexcept
Returns a reference to the element at a given index.
constexpr const element_type & front() const noexcept
Returns a reference to the first element.
constexpr element_type & x() noexcept
Returns a reference to the first element.
constexpr element_type & back() noexcept
Returns a reference to the last element.
constexpr std::reverse_iterator< const element_type * > rend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed vector.
constexpr element_type & y() noexcept
Returns a reference to the second element.
constexpr element_type * data() noexcept
Returns a pointer to the element array.
constexpr std::reverse_iterator< const element_type * > crbegin() const noexcept
Returns a reverse iterator to the first element of the reversed vector.
constexpr std::reverse_iterator< const element_type * > crend() const noexcept
Returns a reverse iterator to the element following the last element of the reversed vector.
constexpr const element_type * cbegin() const noexcept
Returns an iterator to the first element.
constexpr std::reverse_iterator< element_type * > rbegin() noexcept
Returns a reverse iterator to the first element of the reversed vector.
constexpr const element_type * data() const noexcept
Returns a pointer to the element array.
static constexpr vector zero() noexcept
Returns a zero vector, where every element is equal to zero.
static constexpr vector one() noexcept
Returns a vector of ones, where every element is equal to one.
static constexpr vector infinity() noexcept
Returns a vector of infinities, where every element is equal to infinity.
constexpr element_type * begin() noexcept
Returns an iterator to the first element.
constexpr element_type & operator[](std::size_t i) noexcept
Returns a reference to the element at a given index.
constexpr const element_type & z() const noexcept
Returns a reference to the third element.
constexpr element_type & front() noexcept
Returns a reference to the first element.
T element_type
Element type.
constexpr const element_type & x() const noexcept
Returns a reference to the first element.
constexpr const element_type & y() const noexcept
Returns a reference to the second element.
constexpr element_type & z() noexcept
Returns a reference to the third element.
static constexpr std::size_t element_count
Number of elements.
constexpr const element_type * cend() const noexcept
Returns an iterator to the element following the last element.
constexpr const element_type * end() const noexcept
Returns an iterator to the element following the last element.
constexpr const element_type & back() const noexcept
Returns a reference to the last element.
constexpr std::reverse_iterator< element_type * > rend() noexcept
Returns a reverse iterator to the element following the last element of the reversed vector.
constexpr std::size_t size() const noexcept
Returns the number of elements in the vector.
constexpr std::reverse_iterator< const element_type * > rbegin() const noexcept
Returns a reverse iterator to the first element of the reversed vector.
constexpr const element_type * begin() const noexcept
Returns an iterator to the first element.
element_type elements[N]
Array of elements.
constexpr element_type * end() noexcept
Returns an iterator to the element following the last element.