12#ifndef JAU_MATH_VEC3F_HPP_
13#define JAU_MATH_VEC3F_HPP_
24#include <initializer_list>
43 std::enable_if_t<std::is_floating_point_v<Value_type> &&
80 :
x(x_),
y(y_),
z(z_) {}
83 :
x(o2.x),
y(o2.y),
z(z_) {}
86 :
x(v[0]),
y(v[1]),
z(v[2]) {}
88 constexpr Vector3F(std::initializer_list<value_type> v) noexcept
89 :
x(v[0]),
y(v[1]),
z(v[2]) {}
113 explicit operator pointer() noexcept {
return &
x; }
118 { xyz[0] =
x; xyz[1] =
y; xyz[2] =
z;
return xyz; }
146 {
x=vx;
y=vy;
z=vz;
return *
this; }
150 {
x=xyz[0];
y=xyz[1];
z=xyz[2];
return *
this; }
154 {
x+=d.x;
y+=d.y;
z+=d.z;
return *
this; }
158 {
x+=dx;
y+=dy;
z+=dz;
return *
this; }
162 {
x*=s.x;
y*=s.y;
z*=s.z;
return *
this; }
166 {
x*=sx;
y*=sy;
z*=sz;
return *
this; }
170 {
x*=s;
y*=s;
z*=s;
return *
this; }
174 x+=rhs.x;
y+=rhs.y;
z+=rhs.z;
180 x-=rhs.x;
y-=rhs.y;
z-=rhs.z;
190 x*=s.x;
y*=s.y;
z*=s.z;
199 x/=s.x;
y/=s.y;
z/=s.z;
225 return rotateZ(std::sin(radians), std::cos(radians));
231 x = x0 * cos -
y * sin;
232 y = x0 * sin +
y * cos;
236 std::string
toString() const noexcept {
return std::to_string(
x)+
", "+std::to_string(
y)+
", "+std::to_string(
z); }
285 return dx*dx + dy*dy + dz*dz;
300 return x*o.
x +
y*o.
y +
z*o.
z;
318 x = a.y * b.z - a.z * b.y;
319 y = a.z * b.x - a.x * b.z;
320 z = a.x * b.y - a.y * b.x;
343 const value_type eps = std::numeric_limits<value_type>::epsilon();
344 if( std::abs(
x-o.
x) >= eps || std::abs(
y-o.
y) >= eps || std::abs(
z-o.
z) >= eps ) {
352 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
364 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
370 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
378 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
384 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
390 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
396 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
399 r.
x=s/r.
x; r.
y=s/r.
y; r.
z=s/r.
z;
404 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
406 return Vector3F<T>(std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y), std::min(lhs.z, rhs.z));
410 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
412 return Vector3F<T>(std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y), std::max(lhs.z, rhs.z));
416 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
418 return Vector3F<T>(std::abs(lhs.x), std::abs(lhs.y), std::abs(lhs.z));
422 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
424 return out << v.toString();
429 static_assert(
sizeof(double) ==
alignof(Vector3F<double>));
431 static_assert(
sizeof(double)*3 ==
sizeof(Vector3F<double>));
436 static_assert(
sizeof(float) ==
alignof(
Vec3f));
438 static_assert(
sizeof(float)*3 ==
sizeof(
Vec3f));
444 std::enable_if_t<std::is_floating_point_v<Value_type> &&
451 static_assert(
sizeof(float) ==
alignof(
Point3f));
453 static_assert(
sizeof(float)*3 ==
sizeof(
Point3f));
468 std::enable_if_t<std::is_floating_point_v<Value_type>,
bool> =
true>
469 class alignas(sizeof(Value_type))
Ray3F {
490 std::string
toString() const noexcept {
return "Ray[orig "+
orig.toString()+
", dir "+
dir.toString() +
"]"; }
494 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
496 return out << v.toString();
502 static_assert(
sizeof(float) ==
alignof(
Ray3f));
504 static_assert(
sizeof(float)*6 ==
sizeof(
Ray3f));
Simple compound denoting a ray.
static constexpr const size_t byte_size
std::string toString() const noexcept
Point3F< value_type > orig
static constexpr const size_t components
const value_type * const_pointer
static constexpr int value_alignment
Vector3F< value_type > dir
2D vector using two value_type components.
3D vector using three value_type components.
constexpr Vector3F(const value_type v) noexcept
constexpr Vector3F & operator*=(const Vector3F &s) noexcept
this = this * {s.x, s.y, s.z}, component wise.
constexpr reference operator[](size_t i) noexcept
Returns writeable reference to component.
constexpr Vector3F & cross(const Vector3F &a, const Vector3F &b) noexcept
cross product this = a x b, with a, b different from this
constexpr Vector3F() noexcept
constexpr_cxx26 Vector3F & rotateZ(const value_type radians) noexcept
Rotates this vector around the Z-axis in place, returns *this.
constexpr Vector3F & set(const Vec2f &o, const value_type z_) noexcept
TODO constexpr bool operator<=>(const vec3f_t& rhs ) const noexcept { return ... }...
const value_type & const_reference
constexpr bool operator==(const Vector3F &rhs) const noexcept
constexpr Vector3F & operator/=(const value_type s) noexcept
this = this / s, component wise.
constexpr_cxx26 value_type angle(const Vector3F &o) const noexcept
Return the angle between to vectors in radians.
constexpr Vector3F & operator=(const Vector3F &) noexcept=default
constexpr value_type cos_angle(const Vector3F &o) const noexcept
Return the cosines of the angle between to vectors.
constexpr Vector3F & normalize() noexcept
Normalize this vector in place.
constexpr Vector3F copy() noexcept
const value_type * const_pointer
constexpr Vector3F & operator=(Vector3F &&) noexcept=default
Vector2F< value_type, std::is_floating_point_v< value_type > > Vec2
constexpr value_type operator[](size_t i) const noexcept
Returns read-only component.
constexpr Vector3F(const_iterator v) noexcept
constexpr Vector3F & operator-=(const Vector3F &rhs) noexcept
this = this - rhs, component wise.
static constexpr const value_type zero
constexpr_cxx23 bool intersects(const Vector3F &o) const noexcept
constexpr iterator get(iterator xyz) const noexcept
xyz = this, returns xyz.
constexpr Vector3F & set(const value_type vx, const value_type vy, const value_type vz) noexcept
constexpr value_type length() const noexcept
Return the length of a vector, a.k.a the norm or magnitude
static constexpr const value_type one
constexpr Vector3F & scale(const value_type s) noexcept
this = this * s, component wise.
constexpr value_type dist(const Vector3F &o) const noexcept
Return the distance between this vector and the given one.
constexpr Vector3F & mul(const value_type sx, const value_type sy, const value_type sz) noexcept
this = this * {sx, sy, sz}, component wise.
constexpr Vector3F & rotateZ(const value_type sin, const value_type cos) noexcept
Rotates this vector in place, returns *this.
constexpr Vector3F & operator+=(const Vector3F &rhs) noexcept
this = this + rhs, component wise.
constexpr Vector3F & mul(const Vector3F &s) noexcept
this = this * {s.x, s.y, s.z}, component wise.
constexpr value_type dist_sq(const Vector3F &o) const noexcept
Return the squared distance between this vector and the given one.
constexpr Vector3F(std::initializer_list< value_type > v) noexcept
constexpr Vector3F(const Vec2 &o2, const value_type z_) noexcept
static constexpr const size_t components
static constexpr int value_alignment
static constexpr const size_t byte_size
constexpr Vector3F & add(const value_type dx, const value_type dy, const value_type dz) noexcept
this = this + {dx, dy, dz}, component wise.
constexpr const_iterator cbegin() const noexcept
constexpr bool is_zero() const noexcept
constexpr value_type dot(const Vector3F &o) const noexcept
Return the dot product of this vector and the given one.
constexpr value_type length_sq() const noexcept
Return the squared length of a vector, a.k.a the squared norm or squared magnitude
constexpr Vector3F(const Vector3F &o) noexcept=default
constexpr Vector3F cross(const Vector3F &b) const noexcept
cross product this x b
constexpr Vector3F & set(const_iterator xyz) noexcept
this = xyz, returns this.
const value_type * const_iterator
constexpr Vector3F(const value_type x_, const value_type y_, const value_type z_) noexcept
constexpr Vector3F & operator*=(const value_type s) noexcept
this = this * s, component wise.
constexpr Vector3F & operator/=(const Vector3F &s) noexcept
this = this / {s.x, s.y, s.z}, component wise.
constexpr Vector3F(Vector3F &&o) noexcept=default
constexpr iterator begin() noexcept
std::string toString() const noexcept
constexpr bool equals(const Vector3F &o, const value_type epsilon=std::numeric_limits< value_type >::epsilon()) const noexcept
constexpr Vector3F & add(const Vector3F &d) noexcept
this = this + {d.x, d.y, d.z}, component wise.
std::enable_if_t< std::is_floating_point_v< T >, bool > constexpr equals(const T &a, const T &b, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if both values are equal, i.e.
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.
Vector3F< Value_type > Point3F
Point3F alias of Vector3F.
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