15 :
x(std::numeric_limits<f32>::signaling_NaN()),
16 y(std::numeric_limits<f32>::signaling_NaN()) {}
41 return *
this = *
this + rhs;
49 return *
this = *
this * scalar;
53 return Vector2f(scalar * rhs.
x, scalar * rhs.
y);
57 return x * rhs.
y -
y * rhs.
x;
61 return x * rhs.
x +
y * rhs.
y;
64 [[nodiscard]]
constexpr f32 dot()
const {
69 return dot() > std::numeric_limits<f32>::epsilon() ? Mathf::sqrt(
dot()) : 0.0f;
76 *
this = *
this * (1.0f / len);
85 if (sqLen > std::numeric_limits<f32>::epsilon()) {
86 *
this *= EGG::Mathf::frsqrt(sqLen);
111 :
x(std::numeric_limits<f32>::signaling_NaN()),
112 y(std::numeric_limits<f32>::signaling_NaN()),
113 z(std::numeric_limits<f32>::signaling_NaN()) {}
139 return *
this = *
this - rhs;
147 return *
this = *
this + rhs;
155 return *
this = *
this + val;
163 return Vector3f(
x * scalar,
y * scalar,
z * scalar);
171 return *
this = *
this * scalar;
175 return Vector3f(
x / scalar,
y / scalar,
z / scalar);
179 return *
this = *
this / scalar;
183 return x == rhs.
x &&
y == rhs.
y &&
z == rhs.
z;
187 return !(*
this == rhs);
191 [[nodiscard]]
explicit operator std::string()
const {
192 return std::format(
"[0x{:08X}, 0x{:08X}, 0x{:08X}] | [{}, {}, {}]", f2u(
x), f2u(
y), f2u(
z),
203 return x *
x +
y *
y +
z *
z;
208 return x * rhs.
x +
y * rhs.
y +
z * rhs.
z;
219 return dot == 0.0f ? 0.0f : Mathf::sqrt(
dot);
225 return rhs * rhs.
dot(*
this);
231 return *
this -
proj(rhs);
236 return std::pair(
proj(rhs),
rej(rhs));
241 return Vector3f(Mathf::abs(
x), Mathf::abs(
y), Mathf::abs(
z));
253 return *
this * (1.0f / val);
265 f32 xy = Mathf::fma(
x, rhs.
x, y_);
266 return xy +
z * rhs.
z;
272 f32 zx = Mathf::fma(
z,
z, x_);
284 *
this *= (1.0f / len);
293 return *
this * EGG::Mathf::frsqrt(
dot);
303 return std::make_pair(mag, *
this * (1.0f / mag));
309 if (sqLen > std::numeric_limits<f32>::epsilon()) {
310 *
this *= Mathf::frsqrt(sqLen);
319 out.
x =
x > rhs.
x ?
x : rhs.
x;
320 out.
y =
y > rhs.
y ?
y : rhs.
y;
321 out.
z =
z > rhs.
z ?
z : rhs.
z;
331 out.
x =
x < rhs.
x ?
x : rhs.
x;
332 out.
y =
y < rhs.
y ?
y : rhs.
y;
333 out.
z =
z < rhs.
z ?
z : rhs.
z;
348 if (Mathf::abs(
dot(rhs)) == 1.0f) {
352 f32 _x = (rhs.
z *
x - rhs.
x *
z) * rhs.
z - (rhs.
x *
y - rhs.
y *
x) * rhs.
y;
353 f32 _y = (rhs.
x *
y - rhs.
y *
x) * rhs.
x - (rhs.
y *
z - rhs.
z *
y) * rhs.
z;
354 f32 _z = (rhs.
y *
z - rhs.
z *
y) * rhs.
y - (rhs.
z *
x - rhs.
x *
z) * rhs.
x;
372 return *
this + (v - *
this) * t;
400 std::numeric_limits<f32>::infinity(), std::numeric_limits<f32>::infinity());
A stream of data, abstracted to allow for continuous seeking.
static const Vector2f zero
constexpr void normalise2()
constexpr Vector2f & operator*=(const f32 scalar)
void read(Stream &stream)
Initializes a Vector2f by reading 8 bytes from the stream.
constexpr Vector2f operator-(const Vector2f &rhs) const
constexpr Vector2f operator+(const Vector2f &rhs) const
constexpr void set(f32 val)
constexpr f32 length() const
constexpr f32 dot() const
friend constexpr Vector2f operator*(f32 scalar, const Vector2f &rhs)
constexpr f32 cross(const Vector2f &rhs) const
constexpr f32 normalise()
constexpr Vector2f(f32 x_, f32 y_)
constexpr Vector2f()=default
constexpr Vector2f operator-() const
constexpr ~Vector2f()=default
constexpr Vector2f operator*(const f32 scalar) const
constexpr Vector2f & operator+=(const Vector2f &rhs)
constexpr f32 dot(const Vector2f &rhs) const
constexpr std::pair< f32, EGG::Vector3f > ps_normalized()
constexpr EGG::Vector3f multInv(f32 val) const
Multiplies a vector by the inverse of val.
constexpr void normalise2()
constexpr f32 squaredLength() const
The dot product between the vector and itself.
constexpr f32 ps_dot() const
Paired-singles dot product implementation.
constexpr Vector3f & operator-=(const Vector3f &rhs)
constexpr Vector3f & operator+=(const Vector3f &rhs)
constexpr f32 ps_length() const
constexpr Vector3f()=default
void read(Stream &stream)
Initializes a Vector3f by reading 12 bytes from the stream.
constexpr Vector3f abs() const
Returns the absolute value of each element of the vector.
static const Vector3f zero
constexpr Vector3f & operator+=(f32 val)
constexpr Vector3f operator-(const Vector3f &rhs) const
constexpr Vector3f operator-() const
static const Vector3f inf
constexpr Vector3f operator+(f32 val) const
constexpr Vector3f operator+(const Vector3f &rhs) const
constexpr f32 ps_sqDistance(const Vector3f &rhs) const
Paired-singles impl. of sqDistance.
constexpr void set(f32 val)
constexpr f32 sqDistance(const Vector3f &rhs) const
The square of the distance between two vectors.
constexpr f32 dot(const Vector3f &rhs) const
The dot product between two vectors.
constexpr f32 length() const
The square root of the vector's dot product.
constexpr Vector3f proj(const Vector3f &rhs) const
The projection of this vector onto rhs.
constexpr f32 ps_dot(const Vector3f &rhs) const
Paired-singles dot product implementation.
constexpr Vector3f operator*(const Vector3f &rhs) const
friend constexpr Vector3f operator*(f32 scalar, const Vector3f &rhs)
constexpr f32 normalise()
Normalizes the vector and returns the original length.
constexpr Vector3f cross(const Vector3f &rhs) const
constexpr Vector3f(f32 x_, f32 y_, f32 z_)
constexpr Vector3f minimize(const Vector3f &rhs) const
Returns a vector whose elements are the min of the elements of both vectors.
constexpr EGG::Vector3f ps_normalize() const
constexpr Vector3f & operator*=(f32 scalar)
constexpr Vector3f & operator/=(f32 scalar)
constexpr EGG::Vector3f interpolate(f32 t, const EGG::Vector3f &v) const
Linearly interpolates this vector towards the provided vector at the provided rate.
constexpr bool operator==(const Vector3f &rhs) const
constexpr Vector3f rej(const Vector3f &rhs) const
The rejection of this vector onto rhs.
static const Vector3f unit
constexpr Vector3f maximize(const Vector3f &rhs) const
Returns a vector whose elements are the max of the elements of both vectors.
constexpr ~Vector3f()=default
constexpr Vector3f perpInPlane(const EGG::Vector3f &rhs, bool normalise) const
Calculates the orthogonal vector, based on the plane defined by this vector and rhs.
constexpr Vector3f operator*(f32 scalar) const
constexpr std::pair< Vector3f, Vector3f > projAndRej(const Vector3f &rhs) const
constexpr bool operator!=(const Vector3f &rhs) const
constexpr f32 ps_squareMag() const
Differs from ps_dot due to variation in which operands are fused.
constexpr Vector3f operator/(f32 scalar) const