12#ifndef JAU_MATH_VEC2F_HPP_
13#define JAU_MATH_VEC2F_HPP_
39 std::enable_if_t<std::is_floating_point_v<Value_type> &&
67 return Vector2F(magnitude * std::cos(radians), magnitude * std::sin(radians));
101 explicit operator pointer() noexcept {
return &
x; }
123 {
x=vx;
y=vy;
return *
this; }
127 {
x=xy[0];
y=xy[1];
return *
this; }
131 {
x+=d.x;
y+=d.y;
return *
this; }
135 {
x+=dx;
y+=dy;
return *
this; }
139 {
x*=s.x;
y*=s.y;
return *
this; }
143 {
x*=sx;
y*=sy;
return *
this; }
147 {
x*=s;
y*=s;
return *
this; }
202 return rotate(std::sin(radians), std::cos(radians), ctr);
209 x = x0 * cos - y0 * sin + ctr.x;
210 y = x0 * sin + y0 * cos + ctr.y;
216 return rotate(std::sin(radians), std::cos(radians));
222 x = x0 * cos -
y * sin;
223 y = x0 * sin +
y * cos;
227 std::string
toString() const noexcept {
return std::to_string(
x)+
", "+std::to_string(
y); }
266 return std::atan2(
y,
x );
279 return dx*dx + dy*dy;
294 return x*o.x +
y*o.y;
305 return x * o.y -
y * o.x;
312 return dot(o) / (
length() * o.length() ) ;
330 const value_type eps = std::numeric_limits<value_type>::epsilon();
331 if( std::abs(
x-o.x) >= eps || std::abs(
y-o.y) >= eps ) {
339 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
351 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
357 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
365 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
371 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
377 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
383 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
386 r.
x=s/r.
x; r.
y=s/r.
y;
391 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
393 return Vector2F<T>(std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y));
397 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
399 return Vector2F<T>(std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y));
403 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
405 return Vector2F<T>(std::abs(lhs.x), std::abs(lhs.y));
409 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
411 return out << v.toString();
414 static_assert(
sizeof(float) ==
alignof(float));
419 static_assert(
sizeof(float) ==
alignof(
Vec2f));
421 static_assert(
sizeof(float)*2 ==
sizeof(
Vec2f));
427 std::enable_if_t<std::is_floating_point_v<Value_type> &&
434 static_assert(
sizeof(float) ==
alignof(
Point2f));
436 static_assert(
sizeof(float)*2 ==
sizeof(
Point2f));
451 std::enable_if_t<std::is_floating_point_v<Value_type> &&
453 class alignas(sizeof(Value_type))
Ray2F {
474 std::string
toString() const noexcept {
return "Ray[orig "+
orig.toString()+
", dir "+
dir.toString() +
"]"; }
478 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
480 return out << v.toString();
486 static_assert(
sizeof(float) ==
alignof(
Ray2f));
488 static_assert(
sizeof(float)*4 ==
sizeof(
Ray2f));
Simple compound denoting a ray.
const value_type * const_pointer
Point2F< value_type > orig
static constexpr const size_t components
Vector2F< value_type > dir
static constexpr const size_t byte_size
static constexpr int value_alignment
std::string toString() const noexcept
2D vector using two value_type components.
const value_type * const_pointer
constexpr Vector2F & mul(const value_type sx, const value_type sy) noexcept
this = this * {sx, sy}, component wise.
static constexpr const value_type one
constexpr Vector2F & operator-=(const Vector2F &rhs) noexcept
this = this - rhs, component wise.
constexpr Vector2F & normalize() noexcept
Normalize this vector in place, returns *this.
constexpr Vector2F & set(const value_type vx, const value_type vy) noexcept
TODO constexpr std::strong_ordering operator<=>(const vec2f_t& rhs) const noexcept { return ....
constexpr Vector2F & operator*=(const Vector2F &s) noexcept
this = this * {s.x, s.y}, component wise.
constexpr iterator begin() noexcept
constexpr Vector2F & add(const value_type dx, const value_type dy) noexcept
this = this + {dx, dy}, component wise.
constexpr Vector2F(Vector2F &&o) noexcept=default
constexpr_cxx26 Vector2F & rotate(const value_type radians, const Vector2F &ctr) noexcept
Rotates this vector in place, returns *this.
constexpr value_type length_sq() const noexcept
Return the squared length of this vector, a.k.a the squared norm or squared magnitude
constexpr Vector2F normal_ccw() const noexcept
Return the counter-clock-wise (CCW) normal of this vector, i.e.
constexpr reference operator[](size_t i) noexcept
Returns writeable reference to component.
constexpr value_type cross(const Vector2F &o) const noexcept
Returns cross product of this vectors and the given one, i.e.
constexpr Vector2F & mul(const Vector2F &s) noexcept
this = this * {s.x, s.y}, component wise.
constexpr_cxx26 value_type angle() const noexcept
Return the direction angle of this vector in radians.
constexpr iterator get(iterator xy) const noexcept
xy = this, returns xy.
constexpr Vector2F(const value_type x_, const value_type y_) noexcept
const value_type & const_reference
std::string toString() const noexcept
constexpr Vector2F & add(const Vector2F &d) noexcept
this = this + {d.x, d.y}, component wise.
constexpr Vector2F & rotate(const value_type sin, const value_type cos, const Vector2F &ctr) noexcept
Rotates this vector in place, returns *this.
constexpr Vector2F() noexcept
constexpr Vector2F & scale(const value_type s) noexcept
this = this * s, component wise.
static constexpr const size_t components
constexpr Vector2F & operator/=(const value_type s) noexcept
this = this / s, component wise.
constexpr Vector2F & operator+=(const Vector2F &rhs) noexcept
this = this + rhs, component wise.
constexpr value_type length() const noexcept
Return the length of this vector, a.k.a the norm or magnitude
constexpr Vector2F & rotate(const value_type sin, const value_type cos) noexcept
Rotates this vector in place, returns *this.
static constexpr const value_type zero
constexpr const_iterator cbegin() const noexcept
static constexpr const size_t byte_size
constexpr_cxx23 bool intersects(const Vector2F &o) const noexcept
constexpr Vector2F & operator*=(const value_type s) noexcept
this = this * s, component wise.
constexpr Vector2F & set(const_iterator xy) noexcept
this = xy, returns this.
constexpr Vector2F & operator=(const Vector2F &) noexcept=default
const value_type * const_iterator
constexpr bool operator==(const Vector2F &rhs) const noexcept
constexpr value_type dot(const Vector2F &o) const noexcept
Return the dot product of this vector and the given one.
constexpr Vector2F & operator=(Vector2F &&) noexcept=default
constexpr_cxx26 Vector2F & rotate(const value_type radians) noexcept
Rotates this vector in place, returns *this.
constexpr_cxx26 value_type angle(const Vector2F &o) const noexcept
Return the angle between two vectors in radians.
constexpr value_type cos_angle(const Vector2F &o) const noexcept
Return the cosines of the angle between two vectors.
static constexpr_cxx26 Vector2F from_length_angle(const value_type magnitude, const value_type radians) noexcept
constexpr value_type operator[](size_t i) const noexcept
Returns read-only component.
constexpr value_type dist(const Vector2F &o) const noexcept
Return the distance between this vector and the given one.
constexpr Vector2F copy() noexcept
static constexpr int value_alignment
constexpr Vector2F & operator/=(const Vector2F &s) noexcept
this = this / {s.x, s.y}, component wise.
constexpr Vector2F(const value_type v) noexcept
constexpr Vector2F(const Vector2F &o) noexcept=default
constexpr value_type dist_sq(const Vector2F &o) const noexcept
Return the squared distance between this vector and the given one.
constexpr bool is_zero() const noexcept
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 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
Vector2F< Value_type > Point2F
Point2F alias of Vector2F.
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