65 e{T(other.
x), T(other.
y)}
74 s <<
"[" <<
e[0] <<
", " <<
e[1] <<
"]";
84 return {
e[0]+val.
e[0],
e[1]+val.
e[1]};
93 return {
e[0]-val.
e[0],
e[1]-val.
e[1]};
102 return {
e[0]*val.
e[0],
e[1]*val.
e[1]};
111 return {
e[0]/val.
e[0],
e[1]/val.
e[1]};
120 return {
e[0]*val,
e[1]*val};
129 return {
e[0]/val,
e[1]/val};
138 return {
e[0]+val,
e[1]+val};
147 return {
e[0]-val,
e[1]-val};
181 return e[0]*
e[0]+
e[1]*
e[1];
189 operator T*(void) {
return e.data();}
195 operator const T*(void)
const {
return e.data();}
213 const float l = a.
length();
214 return (l != T(0)) ? a/l :
Vec2t{T(0),T(0)};
226 return { std::clamp(val.
x, minVal, maxVal),
227 std::clamp(val.
y, minVal, maxVal)
Random staticRand
Global PRNG instance for convenience functions.
Definition Rand.cpp:52
Simple random number utility wrapping std::mt19937 with common ranges.
Vec2t< T > operator*(float scalar, const Vec2t< T > &vec)
Scalar multiplication with scalar on the left.
Definition Vec2.h:253
Vec2t< float > Vec2
Float vector (x,y).
Definition Vec2.h:258
Vec2t< int32_t > Vec2i
32-bit signed integer vector (x,y).
Definition Vec2.h:260
std::ostream & operator<<(std::ostream &os, const Vec2t< T > &v)
Stream insertion for string representation of a vector.
Definition Vec2.h:240
Vec2t< uint32_t > Vec2ui
32-bit unsigned integer vector (x,y).
Definition Vec2.h:262
Vec2t(const Vec2t< U > &other)
Explicitly convert from another Vec2t with different component type.
Definition Vec2.h:64
Vec2t operator/(const Vec2t &val) const
Component-wise division.
Definition Vec2.h:110
T length() const
Euclidean length (magnitude).
Definition Vec2.h:172
Vec2t(T x, T y)
Construct from two component values.
Definition Vec2.h:46
Vec2t operator*(const T &val) const
Scalar multiplication.
Definition Vec2.h:119
float y
Definition Vec2.h:31
float g
Definition Vec2.h:32
T sqlength() const
Squared length (avoids sqrt).
Definition Vec2.h:180
static Vec2t normalize(const Vec2t &a)
Return the normalized (unit-length) version of a vector.
Definition Vec2.h:212
Vec2t()
Default-construct to (0, 0).
Definition Vec2.h:37
float x
Definition Vec2.h:31
const std::string toString() const
String representation "[x, y]".
Definition Vec2.h:72
Vec2t(const Vec2t &other)
Copy-construct from another vector of the same type.
Definition Vec2.h:54
static Vec2t random()
Create a vector with components sampled from [0,1).
Definition Vec2.h:203
Vec2t operator/(const T &val) const
Scalar division.
Definition Vec2.h:128
Vec2t operator+(const T &val) const
Add scalar to both components.
Definition Vec2.h:137
Vec2t operator+(const Vec2t &val) const
Component-wise addition.
Definition Vec2.h:83
bool operator!=(const Vec2t &other) const
Inequality comparison (component-wise inequality).
Definition Vec2.h:164
static Vec2t< float > clamp(const Vec2t &val, float minVal, float maxVal)
Clamp both components to [minVal, maxVal].
Definition Vec2.h:225
float r
Definition Vec2.h:32
std::array< float, 2 > e
Definition Vec2.h:30
Vec2t operator-(const Vec2t &val) const
Component-wise subtraction.
Definition Vec2.h:92
Vec2t operator*(const Vec2t &val) const
Component-wise multiplication.
Definition Vec2.h:101
Vec2t operator-(const T &val) const
Subtract scalar from both components.
Definition Vec2.h:146
bool operator==(const Vec2t &other) const
Equality comparison (component-wise equality).
Definition Vec2.h:155