12#ifndef JAU_MATH_VEC4F_HPP_
13#define JAU_MATH_VEC4F_HPP_
21#include <initializer_list>
43 std::enable_if_t<std::is_floating_point_v<Value_type> &&
78 :
x(v),
y(v),
z(v),
w(v) {}
81 :
x(x_),
y(y_),
z(z_),
w(w_) {}
84 :
x(o3.x),
y(o3.y),
z(o3.z),
w(w_) {}
87 :
x(v[0]),
y(v[1]),
z(v[2]),
w(v[3]) {}
89 constexpr Vector4F(std::initializer_list<value_type> v) noexcept
90 :
x(v[0]),
y(v[1]),
z(v[2]),
w(v[3]) {}
114 explicit operator pointer() noexcept {
return &
x; }
119 { xyzw[0] =
x; xyzw[1] =
y; xyzw[2] =
z; xyzw[3] =
w;
return xyzw; }
123 { out.x =
x; out.y =
y; out.z =
z;
return out; }
139 {
x = o.x;
y = o.y;
z = o.z;
w = w_;
return *
this; }
142 {
x=vx;
y=vy;
z=vz;
w=vw;
return *
this; }
146 {
x=xyzw[0];
y=xyzw[1];
z=xyzw[2];
z=xyzw[3];
return *
this; }
150 {
x+=d.x;
y+=d.y;
z+=d.z;
w+=d.w;
return *
this; }
154 {
x+=dx;
y+=dy;
z+=dz;
w+=dw;
return *
this; }
158 {
x*=s.x;
y*=s.y;
z*=s.z;
w*=s.w;
return *
this; }
162 {
x*=sx;
y*=sy;
z*=sz;
w*=sw;
return *
this; }
166 {
x*=s;
y*=s;
z*=s;
w*=s;
return *
this; }
170 x+=rhs.x;
y+=rhs.y;
z+=rhs.z;
w+=rhs.w;
176 {
x-=rhs.x;
y-=rhs.y;
z-=rhs.z;
w-=rhs.w;
return *
this;
185 x*=s.x;
y*=s.y;
z*=s.z;
w*=s.w;
194 x/=s.x;
y/=s.y;
z/=s.z;
w/=s.w;
204 {
x*=s;
y*=s;
z*=s;
w*=s;
return *
this; }
212 {
x/=s;
y/=s;
z/=s;
w/=s;
return *
this; }
214 std::string
toString() const noexcept {
return std::to_string(
x) +
", " + std::to_string(
y) +
", " + std::to_string(
z) +
", " + std::to_string(
w); }
266 return dx*dx + dy*dy + dz*dz + dw*dw;
277 const value_type eps = std::numeric_limits<value_type>::epsilon();
278 if (std::abs(
x - o.x) >= eps || std::abs(
y - o.y) >= eps ||
279 std::abs(
z - o.z) >= eps || std::abs(
w - o.w) >= eps) {
286 template <
typename T,
287 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
299 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
305 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
313 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
319 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
325 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
331 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
334 r.
x=s/r.
x; r.
y=s/r.
y; r.
z=s/r.
z; r.
w=s/r.
w;
339 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
341 return Vector4F<T>(std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y), std::min(lhs.z, rhs.z), std::min(lhs.w, rhs.w));
345 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
347 return Vector4F<T>(std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y), std::max(lhs.z, rhs.z), std::max(lhs.w, rhs.w));
351 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
353 return Vector4F<T>(std::abs(lhs.x), std::abs(lhs.y), std::abs(lhs.z), std::abs(lhs.w));
358 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
363 template <
typename T,
364 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
366 return out << v.toString();
371 static_assert(
sizeof(double) ==
alignof(Vector4F<double>));
373 static_assert(
sizeof(double) * 4 ==
sizeof(Vector4F<double>));
378 static_assert(
sizeof(float) ==
alignof(
Vec4f));
380 static_assert(
sizeof(float) * 4 ==
sizeof(
Vec4f));
386 std::enable_if_t<std::is_floating_point_v<Value_type> &&
393 static_assert(
sizeof(float) ==
alignof(
Point4f));
395 static_assert(
sizeof(float) * 4 ==
sizeof(
Point4f));
3D vector using three value_type components.
4D vector using four value_type components.
static constexpr const value_type zero
const value_type & const_reference
constexpr Vector4F & operator+=(const Vector4F &rhs) noexcept
this = this + rhs, component wise.
constexpr Vector4F & operator*=(const Vector4F &s) noexcept
this = this * {s.x, s.y, s.z, s.w}, component wise.
constexpr Vector4F & operator/=(const Vector4F &s) noexcept
this = this / {s.x, s.y, s.z, s.w}, component wise.
constexpr Vector4F & set(const value_type vx, const value_type vy, const value_type vz, const value_type vw) noexcept
constexpr Vector4F & operator*=(const value_type s) noexcept
this = this * s, component wise.
Vector3F< value_type, std::is_floating_point_v< value_type > > Vec3
constexpr Vector4F & set(const_iterator xyzw) noexcept
this = xyzw, returns this.
constexpr_cxx23 bool intersects(const Vector4F &o) const noexcept
constexpr Vector4F & mul(const value_type sx, const value_type sy, const value_type sz, const value_type sw) noexcept
this = this * {sx, sy, sz, sw}, component wise.
constexpr Vector4F copy() noexcept
constexpr Vector4F & set(const Vec3f &o, const value_type w_) noexcept
TODO constexpr std::strong_ordering operator<=>(const vec4f_t& rhs) const noexcept { return ....
constexpr Vector4F() noexcept
constexpr value_type length_sq() const noexcept
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
const value_type * const_iterator
static constexpr const value_type one
constexpr Vec3 & getVec3(Vec3 &out) const noexcept
out = { this.x, this.y, this.z } dropping w, returns out.
constexpr value_type length() const noexcept
Return the length of a vector, a.k.a the norm or magnitude
constexpr bool is_zero() const noexcept
constexpr value_type operator[](size_t i) const noexcept
Returns read-only component.
constexpr Vector4F & add(const value_type dx, const value_type dy, const value_type dz, const value_type dw) noexcept
this = this + {dx, dy, dz, dw}, component wise.
constexpr Vector4F(const_iterator v) noexcept
const value_type * const_pointer
constexpr value_type dist(const Vector4F &o) const noexcept
Return the distance between this vector and the given one.
constexpr Vector4F & mul(const Vector4F &s) noexcept
this = this * {s.x, s.y, s.z}, component wise.
constexpr const_iterator cbegin() const noexcept
constexpr Vector4F & normalize() noexcept
Normalize this vector in place.
static constexpr int value_alignment
static constexpr const size_t components
constexpr Vector4F(const value_type x_, const value_type y_, const value_type z_, const value_type w_) noexcept
constexpr Vector4F(std::initializer_list< value_type > v) noexcept
constexpr Vector4F(Vector4F &&o) noexcept=default
constexpr iterator get(iterator xyzw) const noexcept
xyzw = this, returns xyzw.
constexpr Vector4F & add(const Vector4F &d) noexcept
this = this + {d.x, d.y, d.z, d.w}, component wise.
constexpr Vector4F(const value_type v) noexcept
constexpr Vector4F & scale(const value_type s) noexcept
this = this * s, component wise.
constexpr Vector4F(const Vector4F &o) noexcept=default
constexpr Vector4F & operator=(const Vector4F &) noexcept=default
constexpr Vector4F & operator=(Vector4F &&) noexcept=default
std::string toString() const noexcept
constexpr Vector4F(const Vec3 &o3, const value_type w_) noexcept
constexpr iterator begin() noexcept
static constexpr const size_t byte_size
constexpr bool operator==(const Vector4F &rhs) const noexcept
constexpr value_type dist_sq(const Vector4F &o) const noexcept
Return the squared distance between this vector and the given one.
constexpr reference operator[](size_t i) noexcept
Returns writeable reference to component.
constexpr Vector4F & operator-=(const Vector4F &rhs) noexcept
this = this - rhs, component wise.
constexpr Vector4F & operator/=(const value_type s) noexcept
this = this / s, component wise.
std::enable_if_t< std::is_floating_point_v< T >, bool > constexpr is_zero(const T &a, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if the given value is less than epsilon, w/ epsilon > 0.
constexpr Vector3F< T > to_vec3(const Vector4F< T > &v) noexcept
out = { this.x, this.y, this.z } dropping w, returns out.
constexpr Quaternion< T > operator-(const Quaternion< T > &lhs, const Quaternion< T > &rhs) noexcept
constexpr Vector2F< T > operator/(const Vector2F< T > &lhs, const T s) noexcept
constexpr Vector2F< T > max(const Vector2F< T > &lhs, const Vector2F< T > &rhs) noexcept
constexpr Vector2F< T > min(const Vector2F< T > &lhs, const Vector2F< T > &rhs) noexcept
constexpr Matrix4< T > operator*(const Matrix4< T > &lhs, const Matrix4< T > &rhs) noexcept
constexpr Quaternion< T > operator+(const Quaternion< T > &lhs, const Quaternion< T > &rhs) noexcept
std::ostream & operator<<(std::ostream &out, const Matrix4< T > &v) noexcept
constexpr Vector2F< T > abs(const Vector2F< T > &lhs) noexcept
Vector4F< Value_type > Point4F
Point4F alias of Vector4F.