33#include <initializer_list>
55 std::enable_if_t<std::is_floating_point_v<Value_type> &&
90 :
x(v),
y(v),
z(v),
w(v) {}
93 :
x(x_),
y(y_),
z(z_),
w(w_) {}
96 :
x(o3.x),
y(o3.y),
z(o3.z),
w(w_) {}
99 :
x(v[0]),
y(v[1]),
z(v[2]),
w(v[3]) {}
101 constexpr Vector4F(std::initializer_list<value_type> v) noexcept
102 :
x(v[0]),
y(v[1]),
z(v[2]),
w(v[3]) {}
126 explicit operator pointer() noexcept {
return &
x; }
131 { xyzw[0] =
x; xyzw[1] =
y; xyzw[2] =
z; xyzw[3] =
w;
return xyzw; }
135 { out.x =
x; out.y =
y; out.z =
z;
return out; }
151 {
x = o.x;
y = o.y;
z = o.z;
w = w_;
return *
this; }
154 {
x=vx;
y=vy;
z=vz;
w=vw;
return *
this; }
158 {
x=xyzw[0];
y=xyzw[1];
z=xyzw[2];
z=xyzw[3];
return *
this; }
162 {
x+=dx;
y+=dy;
z+=dz;
w+=dw;
return *
this; }
166 {
x*=sx;
y*=sy;
z*=sz;
w*=sw;
return *
this; }
170 {
x*=s;
y*=s;
z*=s;
w*=s;
return *
this; }
174 x+=rhs.x;
y+=rhs.y;
z+=rhs.z;
w+=rhs.w;
180 {
x-=rhs.x;
y-=rhs.y;
z-=rhs.z;
w-=rhs.w;
return *
this;
189 {
x*=s;
y*=s;
z*=s;
w*=s;
return *
this; }
197 {
x/=s;
y/=s;
z/=s;
w/=s;
return *
this; }
199 std::string
toString() const noexcept {
return std::to_string(
x) +
", " + std::to_string(
y) +
", " + std::to_string(
z) +
", " + std::to_string(
w); }
251 return dx*dx + dy*dy + dz*dz + dw*dw;
262 const value_type eps = std::numeric_limits<value_type>::epsilon();
263 if (std::abs(
x - o.x) >= eps || std::abs(
y - o.y) >= eps ||
264 std::abs(
z - o.z) >= eps || std::abs(
w - o.w) >= eps) {
271 template <
typename T,
272 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
284 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
290 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
298 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
304 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
310 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
316 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
318 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));
322 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
324 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));
329 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
334 template <
typename T,
335 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
337 return out << v.toString();
342 static_assert(
sizeof(double) ==
alignof(Vector4F<double>));
344 static_assert(
sizeof(double) * 4 ==
sizeof(Vector4F<double>));
349 static_assert(
sizeof(float) ==
alignof(
Vec4f));
351 static_assert(
sizeof(float) * 4 ==
sizeof(
Vec4f));
357 std::enable_if_t<std::is_floating_point_v<Value_type> &&
364 static_assert(
sizeof(float) ==
alignof(
Point4f));
366 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, returns this.
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
Scale this vector with given scale factor.
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}, returns this.
constexpr Vector4F copy() noexcept
constexpr Vector4F & set(const Vec3f &o, const value_type w_) noexcept
TODO constexpr bool 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}, returns this.
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 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(const value_type v) noexcept
constexpr Vector4F & scale(const value_type s) noexcept
this = this * s, returns this.
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, returns this.
constexpr Vector4F & operator/=(const value_type s) noexcept
Divide this vector with given scale factor.
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
Vector4F< Value_type > Point4F
Point4F alias of Vector4F.