48 std::enable_if_t<std::is_floating_point_v<Value_type>,
bool> =
true>
63 constexpr static const size_t components = 2;
66 constexpr static const size_t byte_size = components *
sizeof(
value_type);
72 return Vector2F(magnitude * std::cos(radians), magnitude * std::sin(radians));
90 constexpr
value_type operator[](
size_t i) const noexcept {
104 explicit operator pointer() noexcept {
return &x; }
126 { x=vx; y=vy;
return *
this; }
130 { x=xy[0]; y=xy[1];
return *
this; }
134 { x+=dx; y+=dy;
return *
this; }
138 { x*=sx; y*=sy;
return *
this; }
142 { x*=s; y*=s;
return *
this; }
178 return rotate(std::sin(radians), std::cos(radians), ctr);
185 x = x0 * cos - y0 * sin + ctr.x;
186 y = x0 * sin + y0 * cos + ctr.y;
192 return rotate(std::sin(radians), std::cos(radians));
198 x = x0 * cos - y * sin;
199 y = x0 * sin + y * cos;
220 return std::sqrt(length_sq());
242 return std::atan2( y, x );
255 return dx*dx + dy*dy;
262 return std::sqrt(dist_sq(o));
270 return x*o.x + y*o.y;
281 return x * o.y - y * o.x;
288 return dot(o) / ( length() * o.length() ) ;
295 return std::acos( cos_angle(o) );
306 const value_type eps = std::numeric_limits<value_type>::epsilon();
315 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
327 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
333 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
339 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
345 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>
353 return out << v.toString();
357 static_assert(
alignof(float) ==
alignof(
Vec2f));
358 static_assert(
sizeof(float)*2 ==
sizeof(
Vec2f));
364 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
368 static_assert(
alignof(float) ==
alignof(
Point2f));
369 static_assert(
sizeof(float)*2 ==
sizeof(
Point2f));
383 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
392 std::string
toString() const noexcept {
return "Ray[orig "+orig.
toString()+
", dir "+dir.toString() +
"]"; }
396 std::enable_if_t<std::is_floating_point_v<T>,
bool> =
true>
398 return out << v.toString();
402 static_assert(
alignof(float) ==
alignof(
Ray2f));
403 static_assert(
sizeof(float)*4 ==
sizeof(
Ray2f));
Simple compound denoting a ray.
std::string toString() const noexcept
Vector2F< T > dir
Normalized direction vector of ray.
Point2F< T > orig
Origin of Ray.
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.
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.
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.
constexpr const_iterator cbegin() const noexcept
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 dist(const Vector2F &o) const noexcept
Return the distance between this vector and the given one.
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::string to_string(const alphabet &v) noexcept
std::enable_if< std::is_floating_point_v< T >, bool >::type 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 T abs(const T x) noexcept
Returns the absolute value of an arithmetic number (w/ branching) in O(1)
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 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 const jau::fraction_i64 zero(0l, 1lu)
zero is 0/1
constexpr const jau::fraction_i64 one(1l, 1lu)
one is 10^0 or 1/1