51 std::enable_if_t<std::is_floating_point_v<Value_type> &&
79 return Vector2F(magnitude * std::cos(radians), magnitude * std::sin(radians));
113 explicit operator pointer() noexcept {
return &
x; }
135 {
x=vx;
y=vy;
return *
this; }
139 {
x=xy[0];
y=xy[1];
return *
this; }
143 {
x+=dx;
y+=dy;
return *
this; }
147 {
x*=sx;
y*=sy;
return *
this; }
151 {
x*=s;
y*=s;
return *
this; }
187 return rotate(std::sin(radians), std::cos(radians), ctr);
194 x = x0 * cos - y0 * sin + ctr.x;
195 y = x0 * sin + y0 * cos + ctr.y;
201 return rotate(std::sin(radians), std::cos(radians));
207 x = x0 * cos -
y * sin;
208 y = x0 * sin +
y * cos;
212 std::string
toString() const noexcept {
return std::to_string(
x)+
", "+std::to_string(
y); }
251 return std::atan2(
y,
x );
264 return dx*dx + dy*dy;
279 return x*o.x +
y*o.y;
290 return x * o.y -
y * o.x;
297 return dot(o) / (
length() * o.length() ) ;
315 const value_type eps = std::numeric_limits<value_type>::epsilon();
316 if( std::abs(
x-o.x) >= eps || std::abs(
y-o.y) >= eps ) {
324 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
336 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
342 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
350 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
356 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
362 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
368 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
370 return Vector2F<T>(std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y));
374 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
376 return Vector2F<T>(std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y));
380 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
382 return out << v.toString();
385 static_assert(
sizeof(float) ==
alignof(float));
390 static_assert(
sizeof(float) ==
alignof(
Vec2f));
392 static_assert(
sizeof(float)*2 ==
sizeof(
Vec2f));
398 std::enable_if_t<std::is_floating_point_v<Value_type> &&
405 static_assert(
sizeof(float) ==
alignof(
Point2f));
407 static_assert(
sizeof(float)*2 ==
sizeof(
Point2f));
422 std::enable_if_t<std::is_floating_point_v<Value_type> &&
424 class alignas(sizeof(Value_type))
Ray2F {
445 std::string
toString() const noexcept {
return "Ray[orig "+
orig.toString()+
", dir "+
dir.toString() +
"]"; }
449 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
451 return out << v.toString();
457 static_assert(
sizeof(float) ==
alignof(
Ray2f));
459 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}, returns this.
static constexpr const value_type one
constexpr Vector2F & operator-=(const Vector2F &rhs) noexcept
this = this - rhs, returns this.
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 bool operator<=>(const vec2f_t& rhs ) const noexcept { return ... }...
constexpr iterator begin() noexcept
constexpr Vector2F & add(const value_type dx, const value_type dy) noexcept
this = this + {sx, sy}, returns this.
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_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 & 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, returns this.
static constexpr const size_t components
constexpr Vector2F & operator/=(const value_type s) noexcept
Divide this vector with given scale factor.
constexpr Vector2F & operator+=(const Vector2F &rhs) noexcept
this = this + rhs, returns this.
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
Scale this vector with given scale factor.
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(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