6 constexpr std::istream &
operator>>(std::istream &is, U &vec)
8 for (
size_t i = 0; i < U::size; i++)
15 constexpr std::ostream &
operator<<(std::ostream &os, U
const &vec)
17 for (
size_t i = 0; i < U::size; i++)
26 for (
size_t i = 0; i < U::size; i++)
33 template <
size_t n, Primitive U, AnyVec Vector>
34 [[nodiscard]]
constexpr vec<n, U> as_vec(Vector
const &v)
noexcept requires(n >= 2 && n <= Vector::size)
37 for (
size_t i = 0; i < n; i++)
39 rv.
data[i] =
static_cast<U
>(v.data[i]);
34 [[nodiscard]]
constexpr vec<n, U> as_vec(Vector
const &v)
noexcept requires(n >= 2 && n <= Vector::size) {
…}
44 template <
size_t n, AnyVec Vector>
50 template <AnyVec Vector>
55 template <
size_t n, AnyVec Vector>
60 template <AnyVec Vector>
66 template <
size_t n, AnyVec Vector>
71 template <AnyVec Vector>
77 template <
size_t size, Primitive T, Primitive U>
82 template <
size_t size, Primitive T, Primitive U>
87 template <
size_t size, Primitive T, Primitive U>
92 template <
size_t size, Primitive T, Primitive U>
97 template <
size_t size, Primitive T, Primitive U>
102 template <
size_t size, Primitive T, Primitive U>
107 template <
size_t size, Primitive T, Primitive U>
112 template <
size_t size, Primitive T, Primitive U>
118 template <
size_t size, Primitive T, Primitive U>
123 template <
size_t size, Primitive T, Primitive U>
128 template <
size_t size, Primitive T, Primitive U>
133 template <
size_t size, Primitive T, Primitive U>
138 template <
size_t size, Primitive T, Primitive U>
143 template <
size_t size, Primitive T, Primitive U>
149 template <
size_t size, Primitive T, Primitive U>
154 template <
size_t size, Primitive T, Primitive U>
159 template <
size_t size, Primitive T, Primitive U>
164 template <
size_t size, Primitive T, Primitive U>
169 template <
size_t size, Primitive T, Primitive U>
174 template <
size_t size, Primitive T, Primitive U>
179 template <
size_t size, Primitive T, Primitive U>
184 template <
size_t size, Primitive T, Primitive U>
189 template <
size_t size, Primitive T, Primitive U>
194 template <
size_t size, Primitive T, Primitive U>
199 template <
size_t size, Primitive T, Primitive U>
204 template <
size_t size, Primitive T, Primitive U>
209 template <
size_t size, Primitive T, Primitive U>
215 template <
size_t size, Primitive T, Primitive U>
220 template <
size_t size, Primitive T, Primitive U>
225 template <
size_t size, Primitive T, Primitive U>
230 template <
size_t size, Primitive T, Primitive U>
235 template <
size_t size, Primitive T, Primitive U>
241 template <
size_t size, Primitive T, Primitive U>
246 template <
size_t size, Primitive T, Primitive U>
251 template <
size_t size, Primitive T, Primitive U>
256 template <
size_t size, Primitive T, Primitive U>
261 template <
size_t size, Primitive T, Primitive U>
267 template <AnyVec T, AnyVec U>
268 [[nodiscard]]
constexpr bool operator==(T
const &left, U
const &right)
noexcept requires(T::size == U::size)
271 for (
size_t i = 0; i < T::size; i++)
273 rv = rv && (left.data[i] == right.data[i]);
268 [[nodiscard]]
constexpr bool operator==(T
const &left, U
const &right)
noexcept requires(T::size == U::size) {
…}
278 template <AnyVec T, AnyVec U>
279 [[nodiscard]]
constexpr bool operator!=(T
const &left, U
const &right)
noexcept requires(T::size == U::size)
281 return !(left == right);
279 [[nodiscard]]
constexpr bool operator!=(T
const &left, U
const &right)
noexcept requires(T::size == U::size) {
…}
284 [[nodiscard]]
constexpr std::remove_const_t<typename T::type>
squared_length(T
const &vector)
noexcept
286 std::remove_const_t<typename T::type> return_value = 0;
287 for (
size_t i = 0; i < T::size; i++)
289 return_value += vector.
data[i] * vector.data[i];
284 [[nodiscard]]
constexpr std::remove_const_t<typename T::type>
squared_length(T
const &vector)
noexcept {
…}
294 [[nodiscard]]
constexpr auto length(T
const &vector)
noexcept
294 [[nodiscard]]
constexpr auto length(T
const &vector)
noexcept {
…}
302 return vector /
length(vector);
307 return vector /
length(vector);
310 template <AnyVec T, AnyVec U>
311 constexpr std::remove_const_t<typename T::type>
dot(T
const &left, U
const &right)
noexcept requires(T::size == U::size)
313 std::remove_const_t<typename T::type> return_value = 0;
314 auto const temp = left * right;
315 for (
size_t i = 0; i < T::size; i++)
317 return_value += temp[i];
311 constexpr std::remove_const_t<typename T::type>
dot(T
const &left, U
const &right)
noexcept requires(T::size == U::size) {
…}
322 template <AnyVec T, AnyVec U>
323 constexpr typename std::remove_const_t<typename T::type>
angle(T
const &left, U
const &right)
noexcept requires(T::size == U::size)
325 return acos(
clamp(
dot(left, right),
typename T::type(-1),
typename T::type(1)));
323 constexpr typename std::remove_const_t<typename T::type>
angle(T
const &left, U
const &right)
noexcept requires(T::size == U::size) {
…}
332 for (
size_t i = 0; i < T::size; i++)
334 return_value[i] =
cos(vector[i]);
343 for (
size_t i = 0; i < T::size; i++)
345 return_value[i] =
sin(vector[i]);
353 for (
size_t i = 0; i < T::size; i++)
355 return_value[i] =
tan(vector[i]);
363 for (
size_t i = 0; i < T::size; i++)
365 return_value[i] =
acos(vector[i]);
373 for (
size_t i = 0; i < T::size; i++)
375 return_value[i] =
asin(vector[i]);
383 for (
size_t i = 0; i < T::size; i++)
385 return_value[i] =
atan(vector[i]);
389 template <AnyVec T, AnyVec U>
393 for (
size_t i = 0; i < T::size; i++)
395 return_value[i] =
atan2(left[i], right[i]);
399 template <AnyVec T, AnyVec U>
402 return atan(left, right);
408 for (
size_t i = 0; i < T::size; i++)
410 return_value[i] =
sinh(vector[i]);
418 for (
size_t i = 0; i < T::size; i++)
420 return_value[i] =
cosh(vector[i]);
428 for (
size_t i = 0; i < T::size; i++)
430 return_value[i] =
tanh(vector[i]);
438 for (
size_t i = 0; i < T::size; i++)
440 return_value[i] =
asinh(vector[i]);
448 for (
size_t i = 0; i < T::size; i++)
450 return_value[i] =
acosh(vector[i]);
458 for (
size_t i = 0; i < T::size; i++)
460 return_value[i] =
atanh(vector[i]);
468 for (
size_t i = 0; i < T::size; i++)
470 return_value[i] =
exp(vector[i]);
478 for (
size_t i = 0; i < T::size; i++)
480 return_value[i] =
exp2(vector[i]);
488 for (
size_t i = 0; i < T::size; i++)
490 return_value[i] =
expm1(vector[i]);
498 for (
size_t i = 0; i < T::size; i++)
500 return_value[i] =
log(vector[i]);
508 for (
size_t i = 0; i < T::size; i++)
510 return_value[i] =
log2(vector[i]);
518 for (
size_t i = 0; i < T::size; i++)
520 return_value[i] =
log10(vector[i]);
528 for (
size_t i = 0; i < T::size; i++)
530 return_value[i] =
log1p(vector[i]);
538 for (
size_t i = 0; i < T::size; i++)
540 return_value[i] =
logb(vector[i]);
548 for (
size_t i = 0; i < T::size; i++)
550 return_value[i] =
sqrt(vector[i]);
558 for (
size_t i = 0; i < T::size; i++)
568 for (
size_t i = 0; i < T::size; i++)
570 return_value[i] =
abs(vector[i]);
578 for (
size_t i = 0; i < T::size; i++)
580 return_value[i] =
static_cast<typename T::type
>(
sign(vector[i]));
588 for (
size_t i = 0; i < T::size; i++)
590 return_value[i] =
floor(vector[i]);
598 for (
size_t i = 0; i < T::size; i++)
600 return_value[i] =
ceil(vector[i]);
608 for (
size_t i = 0; i < T::size; i++)
610 return_value[i] =
trunc(vector[i]);
618 for (
size_t i = 0; i < T::size; i++)
620 return_value[i] =
round(vector[i]);
628 for (
size_t i = 0; i < T::size; i++)
638 for (
size_t i = 0; i < T::size; i++)
640 return_value[i] =
fract(vector[i]);
648 for (
size_t i = 0; i < T::size; i++)
650 return_value[i] =
mod(vector[i], scalar);
654 template <AnyVec T, AnyVec U>
658 for (
size_t i = 0; i < T::size; i++)
660 return_value[i] =
mod(left[i], right[i]);
665 template <AnyVec T, Primitive U>
669 for (
size_t i = 0; i < T::size; i++)
671 return_value[i] =
pow(vector[i], value);
675 template <AnyVec T, AnyVec U>
679 for (
size_t i = 0; i < T::size; i++)
681 return_value[i] =
pow(vector1[i], vector2[i]);
686 template <AnyVec T, AnyVec U>
690 left.x *right.z - left.z * right.x,
691 left.x *right.y - left.y * right.x};
694 template <Primitive T, Primitive U>
698 left =
static_cast<T
>(
min);
700 left =
static_cast<T
>(
max);
703 template <AnyVec T, Primitive U>
704 constexpr void rclamp(T &left, U
const min, U
const max)
noexcept
706 for (
size_t i = 0; i < T::size; i++)
708 if (left[i] <
static_cast<typename T::type
>(
min))
712 else if (left[i] >
static_cast<typename T::type
>(
max))
718 template <AnyVec T, AnyVec U>
719 constexpr void rclamp(T &left, U
const min, U
const max)
noexcept requires(T::size == U::size)
721 for (
size_t i = 0; i < T::size; i++)
723 if (left[i] <
static_cast<typename T::type
>(
min[i]))
727 else if (left[i] >
static_cast<typename T::type
>(
max[i]))
719 constexpr void rclamp(T &left, U
const min, U
const max)
noexcept requires(T::size == U::size) {
…}
733 template <AnyVec T, Primitive U>
738 for (
size_t i = 0; i < T::size; i++)
740 if (left[i] <
static_cast<std::remove_const_t<typename T::type>
>(
min))
742 rvec[i] =
static_cast<std::remove_const_t<typename T::type>
>(
min);
744 else if (left[i] >
static_cast<std::remove_const_t<typename T::type>
>(
max))
746 rvec[i] =
static_cast<std::remove_const_t<typename T::type>
>(
max);
755 template <AnyVec T, AnyVec U>
759 for (
size_t i = 0; i < T::size; i++)
761 if (left[i] <
static_cast<std::remove_const_t<typename T::type>
>(
min[i]))
763 rvec[i] =
static_cast<std::remove_const_t<typename T::type>
>(
min[i]);
765 else if (left[i] >
static_cast<std::remove_const_t<typename T::type>
>(
max[i]))
767 rvec[i] =
static_cast<std::remove_const_t<typename T::type>
>(
max[i]);
776 template <Primitive T, Primitive U>
777 [[nodiscard]]
constexpr T
clamp(T left, U
const min, U
const max)
noexcept
777 [[nodiscard]]
constexpr T
clamp(T left, U
const min, U
const max)
noexcept {
…}
786 template <AnyVec T, Primitive U>
790 for (
size_t i = 0; i < T::size; i++)
792 rv[i] = std::min(left[i],
static_cast<typename T::type
>(
max));
797 template <AnyVec T, Primitive U>
801 for (
size_t i = 0; i < T::size; i++)
803 rv[i] = std::max(left[i],
static_cast<typename T::type
>(
min));
808 template <AnyVec T, AnyVec U>
812 for (
size_t i = 0; i < T::size; i++)
814 rv[i] = std::min(left[i],
static_cast<typename T::type
>(right[i]));
819 template <AnyVec T, AnyVec U>
823 for (
size_t i = 0; i < T::size; i++)
825 rv[i] = std::max(left[i],
static_cast<typename T::type
>(right[i]));
829 template <AnyVec T, AnyVec U>
830 constexpr void rmin(T &left, U
const &
max)
noexcept requires(T::size == U::size)
832 for (
size_t i = 0; i < T::size; i++)
834 left[i] = std::min(left[i],
static_cast<typename T::type
>(
max[i]));
830 constexpr void rmin(T &left, U
const &
max)
noexcept requires(T::size == U::size) {
…}
838 template <AnyVec T, AnyVec U>
839 constexpr void rmax(T &left, U
const &
min)
noexcept requires(T::size == U::size)
841 for (
size_t i = 0; i < T::size; i++)
843 left[i] = std::max(left[i],
static_cast<typename T::type
>(
min[i]));
839 constexpr void rmax(T &left, U
const &
min)
noexcept requires(T::size == U::size) {
…}
847 template <AnyVec T, Primitive U>
848 constexpr void rmin(T &left, U
const max)
noexcept
850 for (
size_t i = 0; i < T::size; i++)
852 left[i] = std::min(left[i],
static_cast<typename T::type
>(
max));
848 constexpr void rmin(T &left, U
const max)
noexcept {
…}
856 template <AnyVec T, Primitive U>
857 constexpr void rmax(T &left, U
const min)
noexcept
859 for (
size_t i = 0; i < T::size; i++)
861 left[i] = std::max(left[i],
static_cast<typename T::type
>(
min));
857 constexpr void rmax(T &left, U
const min)
noexcept {
…}
865 template <Primitive T, Primitive U>
866 constexpr void rmin(T &left, U
const max)
noexcept
868 left = left <
max ? left :
max;
871 template <Primitive T, Primitive U>
872 constexpr void rmax(T &left, U
const min)
noexcept
874 left = left >
min ? left :
min;
877 [[nodiscard]]
constexpr std::remove_const_t<typename T::type>
distance(T
const &left, T
const &right)
noexcept
879 return length(left - right);
877 [[nodiscard]]
constexpr std::remove_const_t<typename T::type>
distance(T
const &left, T
const &right)
noexcept {
…}
881 template <
typename T, Primitive U>
882 [[nodiscard]]
constexpr auto lerp(T
const &from, T
const &to, U
const param)
noexcept
884 return from * (1 - param) + to * param;
882 [[nodiscard]]
constexpr auto lerp(T
const &from, T
const &to, U
const param)
noexcept {
…}
886 template <
typename T, Primitive U>
887 [[nodiscard]]
constexpr auto mix(T
const &from, T
const &to, U
const param)
noexcept
889 return lerp(from, to, param);
887 [[nodiscard]]
constexpr auto mix(T
const &from, T
const &to, U
const param)
noexcept {
…}
Contains mathematical utility functions and classes.
constexpr auto lerp(T const &from, T const &to, U const param) noexcept
Linearly interpolate between two values.
float atanh(T x) noexcept
constexpr vec< T::size, std::remove_const_t< typename T::type > > max(T const &left, U const max) noexcept
Returns a new vector with each element being the maximum of the corresponding element in left and min...
float atan2(T x, T y) noexcept
float log1p(T x) noexcept
float acosh(T x) noexcept
constexpr T length(qua< T > const &q) noexcept
Computes the length (or magnitude) of a quaternion.
float expm1(T x) noexcept
float log10(T x) noexcept
constexpr void rmin(T &left, U const &max) noexcept
Modifies left in-place, setting each element to the minimum of itself and the corresponding element i...
constexpr vec< n, typename Vector::type > const & as_crvec(Vector const &v) noexcept
Convert a given const vector to a const reference of vec with specified size and type.
float mod(T x, U y) noexcept
constexpr T clamp(T x, T min, T max) noexcept
Function to clamp a value between a minimum and maximum.
constexpr mat< T::size.x, T::size.y, std::remove_const_t< typename T::type > > operator-(T const &left, U const right)
Subtracts a matrix from a primitive.
constexpr T angle(qua< T > const &quaternion) noexcept
Computes the angle (or magnitude) of a quaternion.
T roundEven(T x) noexcept
float inversesqrt(T x) noexcept
constexpr auto operator*(U const &lhs, V const &rhs)
Multiplies two matrices.
constexpr std::remove_const_t< typename T::type > distance(T const &left, T const &right) noexcept
Compute the distance between two vectors.
constexpr bool operator==(T const &left, U const &right) noexcept
constexpr vec< n, U > as_vec(Vector const &v) noexcept
Create a new vector of a specified size and type from the given vector.
constexpr std::remove_const_t< typename T::type > squared_length(T const &vector) noexcept
Compute the squared length of the given vector.
constexpr std::istream & operator>>(std::istream &is, U &matrix)
Reads a matrix from an input stream.
constexpr std::ostream & operator<<(std::ostream &os, U const &matrix)
Writes a matrix to an output stream.
constexpr void rclamp(T &left, U const min, U const max) noexcept
Clamp the value of left between min and max in-place.
float asinh(T x) noexcept
constexpr T dot(qua< T > const &left, qua< U > const &right) noexcept
Computes the dot product of two quaternions.
constexpr void rmax(T &left, U const &min) noexcept
Modifies left in-place, setting each element to the maximum of itself and the corresponding element i...
float pow(T x, U y) noexcept
constexpr bool operator!=(T const &left, U const &right) noexcept
constexpr qua< T > normalize(qua< T > const &q) noexcept
Normalizes a quaternion.
constexpr vec< T::size, std::remove_const_t< typename T::type > > unit_vector(T const &vector) noexcept
Compute the unit vector (normalized vector) of the given vector.
constexpr mat< T::size.x, T::size.y, std::remove_const_t< typename T::type > > operator+(U const left, T const &right)
Adds a matrix to a primitive.
constexpr vec< n, typename Vector::type > & as_rvec(Vector &v) noexcept
Convert a given vector to a reference of vec with specified size and type.
constexpr auto mix(T const &from, T const &to, U const param) noexcept
Mix between two values (same as lerp).
constexpr vec< size, std::remove_const_t< T > > operator%(_detail::rvec< size, T > const &left, U const value) noexcept
constexpr vec< T::size, std::remove_const_t< typename T::type > > min(T const &left, U const min) noexcept
Returns a new vector with each element being the minimum of the corresponding element in left and max...
constexpr qua< T > operator/(U const value, qua< T > const &vector) noexcept
Scalar-quaternion division.
constexpr vec< 3, T > cross(qua< T > const &left, vec< 3, U > const &right) noexcept
Cross product between quaternion and vector.
Internal detail definition of a reference vector with fixed size L and type T
Definition of the mathematical vector with fixed size L and type T
std::array< T, size > data
The underlying data of the vector.
Contains a collection of mathematical operations and utility functions for vector objects.