1
0
Fork 0
forked from suyu/suyu

vector_math: Make functions constexpr where applicable

This commit is contained in:
Lioncash 2018-08-07 21:32:05 -04:00
parent 4e3bc37791
commit 5c323d96e0

View file

@ -42,71 +42,72 @@ class Vec3;
template <typename T> template <typename T>
class Vec4; class Vec4;
template <typename T>
static inline Vec2<T> MakeVec(const T& x, const T& y);
template <typename T>
static inline Vec3<T> MakeVec(const T& x, const T& y, const T& z);
template <typename T>
static inline Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w);
template <typename T> template <typename T>
class Vec2 { class Vec2 {
public: public:
T x{}; T x{};
T y{}; T y{};
Vec2() = default; constexpr Vec2() = default;
Vec2(const T& _x, const T& _y) : x(_x), y(_y) {} constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {}
template <typename T2> template <typename T2>
Vec2<T2> Cast() const { constexpr Vec2<T2> Cast() const {
return Vec2<T2>((T2)x, (T2)y); return Vec2<T2>(static_cast<T2>(x), static_cast<T2>(y));
} }
static Vec2 AssignToAll(const T& f) { static constexpr Vec2 AssignToAll(const T& f) {
return Vec2<T>(f, f); return Vec2{f, f};
} }
Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const { constexpr Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const {
return MakeVec(x + other.x, y + other.y); return {x + other.x, y + other.y};
} }
void operator+=(const Vec2& other) { constexpr Vec2& operator+=(const Vec2& other) {
x += other.x; x += other.x;
y += other.y; y += other.y;
return *this;
} }
Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const { constexpr Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const {
return MakeVec(x - other.x, y - other.y); return {x - other.x, y - other.y};
} }
void operator-=(const Vec2& other) { constexpr Vec2& operator-=(const Vec2& other) {
x -= other.x; x -= other.x;
y -= other.y; y -= other.y;
return *this;
} }
template <typename U = T> template <typename U = T>
Vec2<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { constexpr Vec2<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const {
return MakeVec(-x, -y); return {-x, -y};
} }
Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const { constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const {
return MakeVec(x * other.x, y * other.y); return {x * other.x, y * other.y};
}
template <typename V>
Vec2<decltype(T{} * V{})> operator*(const V& f) const {
return MakeVec(x * f, y * f);
}
template <typename V>
void operator*=(const V& f) {
*this = *this * f;
}
template <typename V>
Vec2<decltype(T{} / V{})> operator/(const V& f) const {
return MakeVec(x / f, y / f);
}
template <typename V>
void operator/=(const V& f) {
*this = *this / f;
} }
T Length2() const { template <typename V>
constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const {
return {x * f, y * f};
}
template <typename V>
constexpr Vec2& operator*=(const V& f) {
*this = *this * f;
return *this;
}
template <typename V>
constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const {
return {x / f, y / f};
}
template <typename V>
constexpr Vec2& operator/=(const V& f) {
*this = *this / f;
return *this;
}
constexpr T Length2() const {
return x * x + y * y; return x * x + y * y;
} }
@ -118,60 +119,59 @@ public:
Vec2 Normalized() const; Vec2 Normalized() const;
float Normalize(); // returns the previous length, which is often useful float Normalize(); // returns the previous length, which is often useful
T& operator[](int i) // allow vector[1] = 3 (vector.y=3) constexpr T& operator[](std::size_t i) {
{
return *((&x) + i); return *((&x) + i);
} }
T operator[](const int i) const { constexpr const T& operator[](std::size_t i) const {
return *((&x) + i); return *((&x) + i);
} }
void SetZero() { constexpr void SetZero() {
x = 0; x = 0;
y = 0; y = 0;
} }
// Common aliases: UV (texel coordinates), ST (texture coordinates) // Common aliases: UV (texel coordinates), ST (texture coordinates)
T& u() { constexpr T& u() {
return x; return x;
} }
T& v() { constexpr T& v() {
return y; return y;
} }
T& s() { constexpr T& s() {
return x; return x;
} }
T& t() { constexpr T& t() {
return y; return y;
} }
const T& u() const { constexpr const T& u() const {
return x; return x;
} }
const T& v() const { constexpr const T& v() const {
return y; return y;
} }
const T& s() const { constexpr const T& s() const {
return x; return x;
} }
const T& t() const { constexpr const T& t() const {
return y; return y;
} }
// swizzlers - create a subvector of specific components // swizzlers - create a subvector of specific components
const Vec2 yx() const { constexpr Vec2 yx() const {
return Vec2(y, x); return Vec2(y, x);
} }
const Vec2 vu() const { constexpr Vec2 vu() const {
return Vec2(y, x); return Vec2(y, x);
} }
const Vec2 ts() const { constexpr Vec2 ts() const {
return Vec2(y, x); return Vec2(y, x);
} }
}; };
template <typename T, typename V> template <typename T, typename V>
Vec2<T> operator*(const V& f, const Vec2<T>& vec) { constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) {
return Vec2<T>(f * vec.x, f * vec.y); return Vec2<T>(f * vec.x, f * vec.y);
} }
@ -196,64 +196,75 @@ public:
T y{}; T y{};
T z{}; T z{};
Vec3() = default; constexpr Vec3() = default;
Vec3(const T& _x, const T& _y, const T& _z) : x(_x), y(_y), z(_z) {} constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {}
template <typename T2> template <typename T2>
Vec3<T2> Cast() const { constexpr Vec3<T2> Cast() const {
return MakeVec<T2>((T2)x, (T2)y, (T2)z); return Vec3<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z));
} }
// Only implemented for T=int and T=float // Only implemented for T=int and T=float
static Vec3 FromRGB(unsigned int rgb); static Vec3 FromRGB(unsigned int rgb);
unsigned int ToRGB() const; // alpha bits set to zero unsigned int ToRGB() const; // alpha bits set to zero
static Vec3 AssignToAll(const T& f) { static constexpr Vec3 AssignToAll(const T& f) {
return MakeVec(f, f, f); return Vec3(f, f, f);
} }
Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const { constexpr Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const {
return MakeVec(x + other.x, y + other.y, z + other.z); return {x + other.x, y + other.y, z + other.z};
} }
void operator+=(const Vec3& other) {
constexpr Vec3& operator+=(const Vec3& other) {
x += other.x; x += other.x;
y += other.y; y += other.y;
z += other.z; z += other.z;
return *this;
} }
Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const {
return MakeVec(x - other.x, y - other.y, z - other.z); constexpr Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const {
return {x - other.x, y - other.y, z - other.z};
} }
void operator-=(const Vec3& other) {
constexpr Vec3& operator-=(const Vec3& other) {
x -= other.x; x -= other.x;
y -= other.y; y -= other.y;
z -= other.z; z -= other.z;
return *this;
} }
template <typename U = T> template <typename U = T>
Vec3<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { constexpr Vec3<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const {
return MakeVec(-x, -y, -z); return {-x, -y, -z};
}
Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const {
return MakeVec(x * other.x, y * other.y, z * other.z);
}
template <typename V>
Vec3<decltype(T{} * V{})> operator*(const V& f) const {
return MakeVec(x * f, y * f, z * f);
}
template <typename V>
void operator*=(const V& f) {
*this = *this * f;
}
template <typename V>
Vec3<decltype(T{} / V{})> operator/(const V& f) const {
return MakeVec(x / f, y / f, z / f);
}
template <typename V>
void operator/=(const V& f) {
*this = *this / f;
} }
T Length2() const { constexpr Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const {
return {x * other.x, y * other.y, z * other.z};
}
template <typename V>
constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const {
return {x * f, y * f, z * f};
}
template <typename V>
constexpr Vec3& operator*=(const V& f) {
*this = *this * f;
return *this;
}
template <typename V>
constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const {
return {x / f, y / f, z / f};
}
template <typename V>
constexpr Vec3& operator/=(const V& f) {
*this = *this / f;
return *this;
}
constexpr T Length2() const {
return x * x + y * y + z * z; return x * x + y * y + z * z;
} }
@ -265,78 +276,78 @@ public:
Vec3 Normalized() const; Vec3 Normalized() const;
float Normalize(); // returns the previous length, which is often useful float Normalize(); // returns the previous length, which is often useful
T& operator[](int i) // allow vector[2] = 3 (vector.z=3) constexpr T& operator[](std::size_t i) {
{
return *((&x) + i);
}
T operator[](const int i) const {
return *((&x) + i); return *((&x) + i);
} }
void SetZero() { constexpr const T& operator[](std::size_t i) const {
return *((&x) + i);
}
constexpr void SetZero() {
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
} }
// Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates) // Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates)
T& u() { constexpr T& u() {
return x; return x;
} }
T& v() { constexpr T& v() {
return y; return y;
} }
T& w() { constexpr T& w() {
return z; return z;
} }
T& r() { constexpr T& r() {
return x; return x;
} }
T& g() { constexpr T& g() {
return y; return y;
} }
T& b() { constexpr T& b() {
return z; return z;
} }
T& s() { constexpr T& s() {
return x; return x;
} }
T& t() { constexpr T& t() {
return y; return y;
} }
T& q() { constexpr T& q() {
return z; return z;
} }
const T& u() const { constexpr const T& u() const {
return x; return x;
} }
const T& v() const { constexpr const T& v() const {
return y; return y;
} }
const T& w() const { constexpr const T& w() const {
return z; return z;
} }
const T& r() const { constexpr const T& r() const {
return x; return x;
} }
const T& g() const { constexpr const T& g() const {
return y; return y;
} }
const T& b() const { constexpr const T& b() const {
return z; return z;
} }
const T& s() const { constexpr const T& s() const {
return x; return x;
} }
const T& t() const { constexpr const T& t() const {
return y; return y;
} }
const T& q() const { constexpr const T& q() const {
return z; return z;
} }
@ -345,7 +356,7 @@ public:
// _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all // _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all
// component names (x<->r) and permutations (xy<->yx) // component names (x<->r) and permutations (xy<->yx)
#define _DEFINE_SWIZZLER2(a, b, name) \ #define _DEFINE_SWIZZLER2(a, b, name) \
const Vec2<T> name() const { \ constexpr Vec2<T> name() const { \
return Vec2<T>(a, b); \ return Vec2<T>(a, b); \
} }
#define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \ #define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \
@ -366,7 +377,7 @@ public:
}; };
template <typename T, typename V> template <typename T, typename V>
Vec3<T> operator*(const V& f, const Vec3<T>& vec) { constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) {
return Vec3<T>(f * vec.x, f * vec.y, f * vec.z); return Vec3<T>(f * vec.x, f * vec.y, f * vec.z);
} }
@ -397,66 +408,80 @@ public:
T z{}; T z{};
T w{}; T w{};
Vec4() = default; constexpr Vec4() = default;
Vec4(const T& _x, const T& _y, const T& _z, const T& _w) : x(_x), y(_y), z(_z), w(_w) {} constexpr Vec4(const T& x_, const T& y_, const T& z_, const T& w_)
: x(x_), y(y_), z(z_), w(w_) {}
template <typename T2> template <typename T2>
Vec4<T2> Cast() const { constexpr Vec4<T2> Cast() const {
return Vec4<T2>((T2)x, (T2)y, (T2)z, (T2)w); return Vec4<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z),
static_cast<T2>(w));
} }
// Only implemented for T=int and T=float // Only implemented for T=int and T=float
static Vec4 FromRGBA(unsigned int rgba); static Vec4 FromRGBA(unsigned int rgba);
unsigned int ToRGBA() const; unsigned int ToRGBA() const;
static Vec4 AssignToAll(const T& f) { static constexpr Vec4 AssignToAll(const T& f) {
return Vec4<T>(f, f, f, f); return Vec4(f, f, f, f);
} }
Vec4<decltype(T{} + T{})> operator+(const Vec4& other) const { constexpr Vec4<decltype(T{} + T{})> operator+(const Vec4& other) const {
return MakeVec(x + other.x, y + other.y, z + other.z, w + other.w); return {x + other.x, y + other.y, z + other.z, w + other.w};
} }
void operator+=(const Vec4& other) {
constexpr Vec4& operator+=(const Vec4& other) {
x += other.x; x += other.x;
y += other.y; y += other.y;
z += other.z; z += other.z;
w += other.w; w += other.w;
return *this;
} }
Vec4<decltype(T{} - T{})> operator-(const Vec4& other) const {
return MakeVec(x - other.x, y - other.y, z - other.z, w - other.w); constexpr Vec4<decltype(T{} - T{})> operator-(const Vec4& other) const {
return {x - other.x, y - other.y, z - other.z, w - other.w};
} }
void operator-=(const Vec4& other) {
constexpr Vec4& operator-=(const Vec4& other) {
x -= other.x; x -= other.x;
y -= other.y; y -= other.y;
z -= other.z; z -= other.z;
w -= other.w; w -= other.w;
return *this;
} }
template <typename U = T> template <typename U = T>
Vec4<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { constexpr Vec4<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const {
return MakeVec(-x, -y, -z, -w); return {-x, -y, -z, -w};
}
Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const {
return MakeVec(x * other.x, y * other.y, z * other.z, w * other.w);
}
template <typename V>
Vec4<decltype(T{} * V{})> operator*(const V& f) const {
return MakeVec(x * f, y * f, z * f, w * f);
}
template <typename V>
void operator*=(const V& f) {
*this = *this * f;
}
template <typename V>
Vec4<decltype(T{} / V{})> operator/(const V& f) const {
return MakeVec(x / f, y / f, z / f, w / f);
}
template <typename V>
void operator/=(const V& f) {
*this = *this / f;
} }
T Length2() const { constexpr Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const {
return {x * other.x, y * other.y, z * other.z, w * other.w};
}
template <typename V>
constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const {
return {x * f, y * f, z * f, w * f};
}
template <typename V>
constexpr Vec4& operator*=(const V& f) {
*this = *this * f;
return *this;
}
template <typename V>
constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const {
return {x / f, y / f, z / f, w / f};
}
template <typename V>
constexpr Vec4& operator/=(const V& f) {
*this = *this / f;
return *this;
}
constexpr T Length2() const {
return x * x + y * y + z * z + w * w; return x * x + y * y + z * z + w * w;
} }
@ -468,15 +493,15 @@ public:
Vec4 Normalized() const; Vec4 Normalized() const;
float Normalize(); // returns the previous length, which is often useful float Normalize(); // returns the previous length, which is often useful
T& operator[](int i) // allow vector[2] = 3 (vector.z=3) constexpr T& operator[](std::size_t i) {
{
return *((&x) + i);
}
T operator[](const int i) const {
return *((&x) + i); return *((&x) + i);
} }
void SetZero() { constexpr const T& operator[](std::size_t i) const {
return *((&x) + i);
}
constexpr void SetZero() {
x = 0; x = 0;
y = 0; y = 0;
z = 0; z = 0;
@ -484,29 +509,29 @@ public:
} }
// Common alias: RGBA (colors) // Common alias: RGBA (colors)
T& r() { constexpr T& r() {
return x; return x;
} }
T& g() { constexpr T& g() {
return y; return y;
} }
T& b() { constexpr T& b() {
return z; return z;
} }
T& a() { constexpr T& a() {
return w; return w;
} }
const T& r() const { constexpr const T& r() const {
return x; return x;
} }
const T& g() const { constexpr const T& g() const {
return y; return y;
} }
const T& b() const { constexpr const T& b() const {
return z; return z;
} }
const T& a() const { constexpr const T& a() const {
return w; return w;
} }
@ -518,7 +543,7 @@ public:
// DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and // DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and
// permutations (xy<->yx) // permutations (xy<->yx)
#define _DEFINE_SWIZZLER2(a, b, name) \ #define _DEFINE_SWIZZLER2(a, b, name) \
const Vec2<T> name() const { \ constexpr Vec2<T> name() const { \
return Vec2<T>(a, b); \ return Vec2<T>(a, b); \
} }
#define DEFINE_SWIZZLER2_COMP1(a, a2) \ #define DEFINE_SWIZZLER2_COMP1(a, a2) \
@ -545,7 +570,7 @@ public:
#undef _DEFINE_SWIZZLER2 #undef _DEFINE_SWIZZLER2
#define _DEFINE_SWIZZLER3(a, b, c, name) \ #define _DEFINE_SWIZZLER3(a, b, c, name) \
const Vec3<T> name() const { \ constexpr Vec3<T> name() const { \
return Vec3<T>(a, b, c); \ return Vec3<T>(a, b, c); \
} }
#define DEFINE_SWIZZLER3_COMP1(a, a2) \ #define DEFINE_SWIZZLER3_COMP1(a, a2) \
@ -579,42 +604,42 @@ public:
}; };
template <typename T, typename V> template <typename T, typename V>
Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) { constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) {
return MakeVec(f * vec.x, f * vec.y, f * vec.z, f * vec.w); return {f * vec.x, f * vec.y, f * vec.z, f * vec.w};
} }
using Vec4f = Vec4<float>; using Vec4f = Vec4<float>;
template <typename T> template <typename T>
static inline decltype(T{} * T{} + T{} * T{}) Dot(const Vec2<T>& a, const Vec2<T>& b) { constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec2<T>& a, const Vec2<T>& b) {
return a.x * b.x + a.y * b.y; return a.x * b.x + a.y * b.y;
} }
template <typename T> template <typename T>
static inline decltype(T{} * T{} + T{} * T{}) Dot(const Vec3<T>& a, const Vec3<T>& b) { constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3<T>& a, const Vec3<T>& b) {
return a.x * b.x + a.y * b.y + a.z * b.z; return a.x * b.x + a.y * b.y + a.z * b.z;
} }
template <typename T> template <typename T>
static inline decltype(T{} * T{} + T{} * T{}) Dot(const Vec4<T>& a, const Vec4<T>& b) { constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4<T>& a, const Vec4<T>& b) {
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
} }
template <typename T> template <typename T>
static inline Vec3<decltype(T{} * T{} - T{} * T{})> Cross(const Vec3<T>& a, const Vec3<T>& b) { constexpr Vec3<decltype(T{} * T{} - T{} * T{})> Cross(const Vec3<T>& a, const Vec3<T>& b) {
return MakeVec(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x};
} }
// linear interpolation via float: 0.0=begin, 1.0=end // linear interpolation via float: 0.0=begin, 1.0=end
template <typename X> template <typename X>
static inline decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end,
const float t) { const float t) {
return begin * (1.f - t) + end * t; return begin * (1.f - t) + end * t;
} }
// linear interpolation via int: 0=begin, base=end // linear interpolation via int: 0=begin, base=end
template <typename X, int base> template <typename X, int base>
static inline decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, const X& end, constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin, const X& end,
const int t) { const int t) {
return (begin * (base - t) + end * t) / base; return (begin * (base - t) + end * t) / base;
} }
@ -622,7 +647,7 @@ static inline decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begi
// bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second // bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second
// interpolation. // interpolation.
template <typename X> template <typename X>
inline auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11, const float s, constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11, const float s,
const float t) { const float t) {
auto y0 = Lerp(x00, x01, s); auto y0 = Lerp(x00, x01, s);
auto y1 = Lerp(x10, x11, s); auto y1 = Lerp(x10, x11, s);
@ -631,42 +656,42 @@ inline auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x1
// Utility vector factories // Utility vector factories
template <typename T> template <typename T>
static inline Vec2<T> MakeVec(const T& x, const T& y) { constexpr Vec2<T> MakeVec(const T& x, const T& y) {
return Vec2<T>{x, y}; return Vec2<T>{x, y};
} }
template <typename T> template <typename T>
static inline Vec3<T> MakeVec(const T& x, const T& y, const T& z) { constexpr Vec3<T> MakeVec(const T& x, const T& y, const T& z) {
return Vec3<T>{x, y, z}; return Vec3<T>{x, y, z};
} }
template <typename T> template <typename T>
static inline Vec4<T> MakeVec(const T& x, const T& y, const Vec2<T>& zw) { constexpr Vec4<T> MakeVec(const T& x, const T& y, const Vec2<T>& zw) {
return MakeVec(x, y, zw[0], zw[1]); return MakeVec(x, y, zw[0], zw[1]);
} }
template <typename T> template <typename T>
static inline Vec3<T> MakeVec(const Vec2<T>& xy, const T& z) { constexpr Vec3<T> MakeVec(const Vec2<T>& xy, const T& z) {
return MakeVec(xy[0], xy[1], z); return MakeVec(xy[0], xy[1], z);
} }
template <typename T> template <typename T>
static inline Vec3<T> MakeVec(const T& x, const Vec2<T>& yz) { constexpr Vec3<T> MakeVec(const T& x, const Vec2<T>& yz) {
return MakeVec(x, yz[0], yz[1]); return MakeVec(x, yz[0], yz[1]);
} }
template <typename T> template <typename T>
static inline Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w) { constexpr Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w) {
return Vec4<T>{x, y, z, w}; return Vec4<T>{x, y, z, w};
} }
template <typename T> template <typename T>
static inline Vec4<T> MakeVec(const Vec2<T>& xy, const T& z, const T& w) { constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const T& z, const T& w) {
return MakeVec(xy[0], xy[1], z, w); return MakeVec(xy[0], xy[1], z, w);
} }
template <typename T> template <typename T>
static inline Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) { constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) {
return MakeVec(x, yz[0], yz[1], w); return MakeVec(x, yz[0], yz[1], w);
} }
@ -674,17 +699,17 @@ static inline Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) {
// Even if someone wanted to use an odd object like Vec2<Vec2<T>>, the compiler would error // Even if someone wanted to use an odd object like Vec2<Vec2<T>>, the compiler would error
// out soon enough due to misuse of the returned structure. // out soon enough due to misuse of the returned structure.
template <typename T> template <typename T>
static inline Vec4<T> MakeVec(const Vec2<T>& xy, const Vec2<T>& zw) { constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const Vec2<T>& zw) {
return MakeVec(xy[0], xy[1], zw[0], zw[1]); return MakeVec(xy[0], xy[1], zw[0], zw[1]);
} }
template <typename T> template <typename T>
static inline Vec4<T> MakeVec(const Vec3<T>& xyz, const T& w) { constexpr Vec4<T> MakeVec(const Vec3<T>& xyz, const T& w) {
return MakeVec(xyz[0], xyz[1], xyz[2], w); return MakeVec(xyz[0], xyz[1], xyz[2], w);
} }
template <typename T> template <typename T>
static inline Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) { constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) {
return MakeVec(x, yzw[0], yzw[1], yzw[2]); return MakeVec(x, yzw[0], yzw[1], yzw[2]);
} }