5#include <Infinity/Types/Core/Value.hpp>
6#include <Infinity/Types/Containers/Array.hpp>
145 constexpr t_Vector4(T x, T y, T z, T w) : value{x, y, z, w} {}
163 value{static_cast<T>(v.x), static_cast<T>(v.y), static_cast<T>(v.z), static_cast<T>(v.w)} {}
189 void set(T in_x, T in_y, T in_z, T in_w)
215 const T*
data()
const {
return value; }
230 value[0] =
static_cast<T
>(rhs[0]);
231 value[1] =
static_cast<T
>(rhs[1]);
232 value[2] =
static_cast<T
>(rhs[2]);
233 value[3] =
static_cast<T
>(rhs[3]);
245 value[0] += rhs.
value[0];
246 value[1] += rhs.
value[1];
247 value[2] += rhs.
value[2];
248 value[3] += rhs.
value[3];
260 value[0] -= rhs.
value[0];
261 value[1] -= rhs.
value[1];
262 value[2] -= rhs.
value[2];
263 value[3] -= rhs.
value[3];
290 value[0] *= rhs.
value[0];
291 value[1] *= rhs.
value[1];
292 value[2] *= rhs.
value[2];
293 value[3] *= rhs.
value[3];
310 if constexpr (std::is_floating_point_v<T>)
312 T inv =
static_cast<T
>(1.0) / rhs;
342 explicit operator bool() const noexcept {
return value[0] != 0.0 || value[1] != 0.0 || value[2] != 0.0 || value[3] != 0.0; }
364 float len = length();
367 float invLength = 1.0f / len;
368 return t_Vector4<T>(x * invLength, y * invLength, z * invLength, w * invLength);
397 y * other.
z - z * other.
y,
398 z * other.
x - x * other.
z,
399 x * other.
y - y * other.
x,
418 return std::sqrt(squaredMagnitude());
430 return std::sqrt(squaredMagnitude());
455 return x * x + y * y + z * z + w * w;
474 return (*
this - other).magnitude();
499 return x * other.
x + y * other.
y + z * other.
z + w * other.
w;
520 float dotProduct = dot(other);
521 float lengths = length() * other.
length();
522 if (lengths == 0.0f)
return 0.0f;
523 return std::acos(dotProduct / lengths);
543 if constexpr (std::is_unsigned<T>::value) {
546 return t_Vector4<T>(std::abs(x), std::abs(y), std::abs(z), std::abs(w));
640 return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2] && lhs[3] == rhs[3];
654 return lhs[0] != rhs[0] || lhs[1] != rhs[1] || lhs[2] != rhs[2] || lhs[3] != rhs[3];
671 if (lhs[0] < rhs[0])
return true;
672 if (lhs[0] > rhs[0])
return false;
673 if (lhs[1] < rhs[1])
return true;
674 if (lhs[1] > rhs[1])
return false;
675 if (lhs[2] < rhs[2])
return true;
676 if (lhs[2] > rhs[2])
return false;
677 return lhs[3] < rhs[3];
691 return t_Vector4<T>(lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2], lhs[3] - rhs[3]);
718 return t_Vector4<T>(lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2], lhs[3] + rhs[3]);
732 return t_Vector4<T>(lhs[0] * rhs, lhs[1] * rhs, lhs[2] * rhs, lhs[3] * rhs);
746 return t_Vector4<T>(lhs[0] * rhs[0], lhs[1] * rhs[1], lhs[2] * rhs[2], lhs[3] * rhs[3]);
764 if constexpr (std::is_floating_point_v<T>)
766 T inv =
static_cast<T
>(1.0) / rhs;
767 return t_Vector4<T>(lhs[0] * inv, lhs[1] * inv, lhs[2] * inv, lhs[3] * inv);
771 return t_Vector4<T>(lhs[0] / rhs, lhs[1] / rhs, lhs[2] / rhs, lhs[3] / rhs);
788 out << v.
x <<
" " << v.
y <<
" " << v.
z <<
" " << v.
w;
805 in >> v.
x >> v.
y >> v.
z >> v.
w;
822 int temp_x, temp_y, temp_z, temp_w;
823 in >> temp_x >> temp_y >> temp_z >> temp_w;
825 v.
x =
static_cast<uint8_t
>(temp_x);
826 v.
y =
static_cast<uint8_t
>(temp_y);
827 v.
z =
static_cast<uint8_t
>(temp_z);
828 v.
w =
static_cast<uint8_t
>(temp_w);
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Definition Array.hpp:77
Template wrapper for primitive types to integrate with the Infinity type system.
Definition Value.hpp:89
std::istream & operator>>(std::istream &in, t_Matrix3< T > &m)
Stream extraction operator for single-line text input.
Definition Matrix3.hpp:726
constexpr Rect operator-(const Rect &lhs, const Rect &rhs)
Rectangle subtraction operator.
Definition Rect.hpp:371
constexpr bool operator<(const t_Vector2< T > &lhs, const t_Vector2< T > &rhs)
Less-than comparison operator for ordering.
Definition Vector2.hpp:589
constexpr t_Vector2< T > operator/(const t_Vector2< T > &lhs, T rhs)
Scalar division.
Definition Vector2.hpp:678
constexpr t_Vector2< T > operator*(const t_Vector2< T > &lhs, T rhs)
Scalar multiplication.
Definition Vector2.hpp:646
constexpr Rect operator+(const Rect &lhs, const Rect &rhs)
Rectangle addition operator.
Definition Rect.hpp:398
std::ostream & operator<<(std::ostream &out, const t_Matrix3< T > &m)
Stream insertion operator for single-line text output.
Definition Matrix3.hpp:709
constexpr bool operator!=(const Rect &lhs, const Rect &rhs)
Inequality comparison operator.
Definition Rect.hpp:357
constexpr bool operator==(const Rect &lhs, const Rect &rhs)
Equality comparison operator.
Definition Rect.hpp:345
Template structure representing a 4-component vector.
Definition Vector4.hpp:85
constexpr t_Vector4(const t_Vector4< R > &v)
Explicit type-converting constructor.
Definition Vector4.hpp:162
T y
Definition Vector4.hpp:100
T x
Definition Vector4.hpp:100
constexpr t_Vector4()
Default constructor.
Definition Vector4.hpp:117
const T * data() const
Gets a const pointer to the underlying data.
Definition Vector4.hpp:215
float dot(const t_Vector4< T > &other) const
Computes the dot product with another vector.
Definition Vector4.hpp:497
T a
Color with alpha interpretation.
Definition Vector4.hpp:104
T w
Homogeneous coordinate or quaternion interpretation.
Definition Vector4.hpp:100
T & operator[](size_t i)
Array subscript operator (mutable).
Definition Vector4.hpp:171
T operator[](size_t i) const
Array subscript operator (const).
Definition Vector4.hpp:179
constexpr t_Vector4(T x, T y, T z, T w)
Constructs a vector from component values.
Definition Vector4.hpp:145
T * data()
Gets a mutable pointer to the underlying data.
Definition Vector4.hpp:208
t_Vector4 & operator*=(T rhs)
Scalar multiplication assignment.
Definition Vector4.hpp:273
t_Vector4< T > cross(const t_Vector4< T > &other) const
Computes the cross product treating xyz as a 3D vector.
Definition Vector4.hpp:394
T p
Definition Vector4.hpp:108
T z
Definition Vector4.hpp:100
t_Vector4 & operator*=(const t_Vector4 &rhs)
Component-wise multiplication assignment.
Definition Vector4.hpp:288
T value[4]
Array access to components.
Definition Vector4.hpp:97
t_Vector4 & operator=(const t_Vector4< R > &rhs)
Type-converting assignment operator.
Definition Vector4.hpp:228
t_Vector4< T > abs() const
Computes the component-wise absolute value.
Definition Vector4.hpp:541
float distance(const t_Vector4< T > &other) const
Computes the Euclidean distance to another vector.
Definition Vector4.hpp:472
t_Vector4 & operator/=(T rhs)
Scalar division assignment.
Definition Vector4.hpp:308
constexpr t_Vector4 & operator=(const t_Vector4 &)=default
Copy assignment operator.
void set(T in_x, T in_y, T in_z, T in_w)
Sets all four components simultaneously.
Definition Vector4.hpp:189
float squaredMagnitude() const
Computes the squared magnitude of this vector.
Definition Vector4.hpp:453
t_Vector4 & operator-=(const t_Vector4 &rhs)
Component-wise subtraction assignment.
Definition Vector4.hpp:258
float angle(const t_Vector4< T > &other) const
Computes the angle between this vector and another.
Definition Vector4.hpp:518
float length() const
Computes the length (magnitude) of this vector.
Definition Vector4.hpp:416
constexpr t_Vector4(const t_Vector4 &v)
Copy constructor.
Definition Vector4.hpp:124
float magnitude() const
Computes the magnitude of this vector.
Definition Vector4.hpp:428
t_Vector4< T > normalized() const
Computes the normalized version of this vector.
Definition Vector4.hpp:362
t_Vector4 & operator+=(const t_Vector4 &rhs)
Component-wise addition assignment.
Definition Vector4.hpp:243