5#include <Infinity/Types/Core/Value.hpp>
6#include <Infinity/Types/Containers/Array.hpp>
159 value{static_cast<T>(v.x), static_cast<T>(v.y), static_cast<T>(v.z)} {}
184 void set(T in_x, T in_y, T in_z)
209 const T*
data()
const {
return value; }
224 value[0] =
static_cast<T
>(rhs[0]);
225 value[1] =
static_cast<T
>(rhs[1]);
226 value[2] =
static_cast<T
>(rhs[2]);
238 value[0] += rhs.
value[0];
239 value[1] += rhs.
value[1];
240 value[2] += rhs.
value[2];
252 value[0] -= rhs.
value[0];
253 value[1] -= rhs.
value[1];
254 value[2] -= rhs.
value[2];
280 value[0] *= rhs.
value[0];
281 value[1] *= rhs.
value[1];
282 value[2] *= rhs.
value[2];
299 if constexpr (std::is_floating_point_v<T>)
301 T inv =
static_cast<T
>(1.0) / rhs;
329 explicit operator bool() const noexcept {
return value[0] != 0.0 || value[1] != 0.0 || value[2] != 0.0; }
346 float len = length();
373 y * other.
z - z * other.
y,
374 z * other.
x - x * other.
z,
375 x * other.
y - y * other.
x
391 return std::sqrt(squaredMagnitude());
403 return std::sqrt(squaredMagnitude());
423 return x * x + y * y + z * z;
440 return (*
this - other).magnitude();
466 return x * other.
x + y * other.
y + z * other.
z;
487 float dotProduct = dot(other);
488 float lengths = length() * other.
length();
489 if (lengths == 0.0f)
return 0.0f;
490 return std::acos(dotProduct / lengths);
510 if constexpr (std::is_unsigned<T>::value) {
513 return t_Vector3<T>(std::abs(x), std::abs(y), std::abs(z));
653 return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2];
667 return lhs[0] != rhs[0] || lhs[1] != rhs[1] || lhs[2] != rhs[2];
684 if (lhs[0] < rhs[0])
return true;
685 if (lhs[0] > rhs[0])
return false;
686 if (lhs[1] < rhs[1])
return true;
687 if (lhs[1] > rhs[1])
return false;
688 return lhs[2] < rhs[2];
702 return t_Vector3<T>(lhs[0] - rhs[0], lhs[1] - rhs[1], lhs[2] - rhs[2]);
729 return t_Vector3<T>(lhs[0] + rhs[0], lhs[1] + rhs[1], lhs[2] + rhs[2]);
743 return t_Vector3<T>(lhs[0] * rhs, lhs[1] * rhs, lhs[2] * rhs);
757 return t_Vector3<T>(lhs[0] * rhs[0], lhs[1] * rhs[1], lhs[2] * rhs[2]);
775 if constexpr (std::is_floating_point_v<T>)
777 T inv =
static_cast<T
>(1.0) / rhs;
778 return t_Vector3<T>(lhs[0] * inv, lhs[1] * inv, lhs[2] * inv);
782 return t_Vector3<T>(lhs[0] / rhs, lhs[1] / rhs, lhs[2] / rhs);
799 out << v.
x <<
" " << v.
y <<
" " << v.
z;
816 in >> v.
x >> v.
y >> v.
z;
832 int temp_x, temp_y, temp_z;
833 in >> temp_x >> temp_y >> temp_z;
835 v.
x =
static_cast<uint8_t
>(temp_x);
836 v.
y =
static_cast<uint8_t
>(temp_y);
837 v.
z =
static_cast<uint8_t
>(temp_z);
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 3-component vector.
Definition Vector3.hpp:82
static constexpr t_Vector3< T > front()
Returns the front/forward direction vector (0, 0, 1).
Definition Vector3.hpp:566
T * data()
Gets a mutable pointer to the underlying data.
Definition Vector3.hpp:202
constexpr t_Vector3 & operator=(const t_Vector3 &)=default
Copy assignment operator.
constexpr t_Vector3(const t_Vector3< R > &v)
Explicit type-converting constructor.
Definition Vector3.hpp:158
t_Vector3 & operator*=(T rhs)
Scalar multiplication assignment.
Definition Vector3.hpp:264
T p
Texture coordinate interpretation.
Definition Vector3.hpp:105
void set(T in_x, T in_y, T in_z)
Sets all three components simultaneously.
Definition Vector3.hpp:184
constexpr t_Vector3()
Default constructor.
Definition Vector3.hpp:114
float squaredMagnitude() const
Computes the squared magnitude of this vector.
Definition Vector3.hpp:421
static constexpr t_Vector3< T > right()
Returns the right direction vector (1, 0, 0).
Definition Vector3.hpp:545
T x
Definition Vector3.hpp:97
float magnitude() const
Computes the magnitude of this vector.
Definition Vector3.hpp:401
t_Vector3 & operator+=(const t_Vector3 &rhs)
Component-wise addition assignment.
Definition Vector3.hpp:236
T z
Cartesian coordinate interpretation.
Definition Vector3.hpp:97
float angle(const t_Vector3< T > &other) const
Computes the angle between this vector and another.
Definition Vector3.hpp:485
T value[3]
Array access to components.
Definition Vector3.hpp:94
float length() const
Computes the length (magnitude) of this vector.
Definition Vector3.hpp:389
static constexpr t_Vector3< T > zero()
Returns a zero vector (0, 0, 0).
Definition Vector3.hpp:522
t_Vector3 & operator*=(const t_Vector3 &rhs)
Component-wise multiplication assignment.
Definition Vector3.hpp:278
static constexpr t_Vector3< T > identity()
Returns an identity/zero vector (0, 0, 0).
Definition Vector3.hpp:531
const T * data() const
Gets a const pointer to the underlying data.
Definition Vector3.hpp:209
t_Vector3 & operator=(const t_Vector3< R > &rhs)
Type-converting assignment operator.
Definition Vector3.hpp:222
t_Vector3< T > cross(const t_Vector3< T > &other) const
Computes the cross product with another vector.
Definition Vector3.hpp:370
t_Vector3< T > abs() const
Computes the component-wise absolute value.
Definition Vector3.hpp:508
constexpr t_Vector3(T x, T y, T z)
Constructs a vector from component values.
Definition Vector3.hpp:141
t_Vector3< T > normalized() const
Computes the normalized version of this vector.
Definition Vector3.hpp:344
T b
Color component interpretation.
Definition Vector3.hpp:101
static constexpr t_Vector3< T > left()
Returns the left direction vector (-1, 0, 0).
Definition Vector3.hpp:538
t_Vector3 & operator/=(T rhs)
Scalar division assignment.
Definition Vector3.hpp:297
constexpr t_Vector3(const t_Vector3 &v)
Copy constructor.
Definition Vector3.hpp:121
float distance(const t_Vector3< T > &other) const
Computes the Euclidean distance to another vector.
Definition Vector3.hpp:438
T y
Definition Vector3.hpp:97
static constexpr t_Vector3< T > down()
Returns the down direction vector (0, -1, 0).
Definition Vector3.hpp:559
T operator[](size_t i) const
Array subscript operator (const).
Definition Vector3.hpp:175
float dot(const t_Vector3< T > &other) const
Computes the dot product with another vector.
Definition Vector3.hpp:464
T & operator[](size_t i)
Array subscript operator (mutable).
Definition Vector3.hpp:167
static constexpr t_Vector3< T > up()
Returns the up direction vector (0, 1, 0).
Definition Vector3.hpp:552
static constexpr t_Vector3< T > back()
Returns the back/backward direction vector (0, 0, -1).
Definition Vector3.hpp:573
t_Vector3 & operator-=(const t_Vector3 &rhs)
Component-wise subtraction assignment.
Definition Vector3.hpp:250