5#include <Infinity/Types/Core/Value.hpp>
6#include <Infinity/Types/Containers/Array.hpp>
150 value{static_cast<T>(v.x), static_cast<T>(v.y)} {}
198 const T*
data()
const {
return value; }
213 value[0] =
static_cast<T
>(rhs[0]);
214 value[1] =
static_cast<T
>(rhs[1]);
226 value[0] += rhs.
value[0];
227 value[1] += rhs.
value[1];
239 value[0] -= rhs.
value[0];
240 value[1] -= rhs.
value[1];
265 value[0] *= rhs.
value[0];
266 value[1] *= rhs.
value[1];
283 if constexpr (std::is_floating_point_v<T>)
285 T inv =
static_cast<T
>(1.0) / rhs;
311 explicit operator bool() const noexcept {
return value[0] != 0.0 || value[1] != 0.0; }
328 float len = length();
361 return std::sqrt(squaredMagnitude());
373 return std::sqrt(squaredMagnitude());
393 return x * x + y * y;
410 return (*
this - other).magnitude();
431 return x * other.
x + y * other.
y;
452 float dotProduct = dot(other);
453 float lengths = length() * other.
length();
454 if (lengths == 0.0f)
return 0.0f;
455 return std::acos(dotProduct / lengths);
475 if constexpr (std::is_unsigned<T>::value) {
560 return lhs[0] == rhs[0] && lhs[1] == rhs[1];
574 return lhs[0] != rhs[0] || lhs[1] != rhs[1];
591 if (lhs[0] < rhs[0])
return true;
592 if (lhs[0] > rhs[0])
return false;
593 return lhs[1] < rhs[1];
680 if constexpr (std::is_floating_point_v<T>)
682 T inv =
static_cast<T
>(1.0) / rhs;
704 out << v.
x <<
" " << v.
y;
738 in >> temp_x >> temp_y;
740 v.
x =
static_cast<uint8_t
>(temp_x);
741 v.
y =
static_cast<uint8_t
>(temp_y);
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 2-component vector.
Definition Vector2.hpp:75
constexpr t_Vector2()
Default constructor.
Definition Vector2.hpp:107
void set(T in_x, T in_y)
Sets both components simultaneously.
Definition Vector2.hpp:174
t_Vector2< T > normalized() const
Computes the normalized version of this vector.
Definition Vector2.hpp:326
constexpr t_Vector2(const t_Vector2 &v)
Copy constructor.
Definition Vector2.hpp:114
t_Vector2 & operator+=(const t_Vector2 &rhs)
Component-wise addition assignment.
Definition Vector2.hpp:224
float length() const
Computes the length (magnitude) of this vector.
Definition Vector2.hpp:359
float angle(const t_Vector2< T > &other) const
Computes the angle between this vector and another.
Definition Vector2.hpp:450
t_Vector2< T > abs() const
Computes the component-wise absolute value.
Definition Vector2.hpp:473
constexpr t_Vector2(const t_Vector2< R > &v)
Explicit type-converting constructor.
Definition Vector2.hpp:149
t_Vector2< T > cross(const t_Vector2< T > &other) const
Computes the 2D cross product with another vector.
Definition Vector2.hpp:344
t_Vector2 & operator-=(const t_Vector2 &rhs)
Component-wise subtraction assignment.
Definition Vector2.hpp:237
T value[2]
Array access to components.
Definition Vector2.hpp:87
float distance(const t_Vector2< T > &other) const
Computes the Euclidean distance to another vector.
Definition Vector2.hpp:408
t_Vector2 & operator=(const t_Vector2< R > &rhs)
Type-converting assignment operator.
Definition Vector2.hpp:211
float dot(const t_Vector2< T > &other) const
Computes the dot product with another vector.
Definition Vector2.hpp:429
const T * data() const
Gets a const pointer to the underlying data.
Definition Vector2.hpp:198
t_Vector2 & operator/=(T rhs)
Scalar division assignment.
Definition Vector2.hpp:281
constexpr t_Vector2(T x, T y)
Constructs a vector from component values.
Definition Vector2.hpp:132
T operator[](size_t i) const
Array subscript operator (const).
Definition Vector2.hpp:166
T * data()
Gets a mutable pointer to the underlying data.
Definition Vector2.hpp:191
T g
Color component interpretation.
Definition Vector2.hpp:94
t_Vector2 & operator*=(const t_Vector2 &rhs)
Component-wise multiplication assignment.
Definition Vector2.hpp:263
T s
Definition Vector2.hpp:98
float magnitude() const
Computes the magnitude of this vector.
Definition Vector2.hpp:371
T y
Cartesian coordinate interpretation.
Definition Vector2.hpp:90
float squaredMagnitude() const
Computes the squared magnitude of this vector.
Definition Vector2.hpp:391
T x
Definition Vector2.hpp:90
T & operator[](size_t i)
Array subscript operator (mutable).
Definition Vector2.hpp:158
constexpr t_Vector2 & operator=(const t_Vector2 &)=default
Copy assignment operator.
t_Vector2 & operator*=(T rhs)
Scalar multiplication assignment.
Definition Vector2.hpp:250