12#ifndef JAU_MATH_VEC2I_HPP_
13#define JAU_MATH_VEC2I_HPP_
38 template<jau::req::packed_
integral Value_type>
97 explicit operator pointer() noexcept {
return &
x; }
111 return x == rhs.x &&
y == rhs.y;
120 const size_t hash =
x;
121 return ((hash << 5) - hash) +
y;
125 {
x=vx;
y=vy;
return *
this; }
129 {
x=xy[0];
y=xy[1];
return *
this; }
133 {
x+=d.x;
y+=d.y;
return *
this; }
137 {
x+=dx;
y+=dy;
return *
this; }
141 {
x*=s.x;
y*=s.y;
return *
this; }
145 {
x*=sx;
y*=sy;
return *
this; }
149 {
x*=s;
y*=s;
return *
this; }
215 std::string
toString() const noexcept {
return std::to_string(
x)+
", "+std::to_string(
y); }
252 return x == o.
x &&
y == o.
y;
256 template<jau::req::packed_
integral T>
267 template<jau::req::packed_
integral T>
272 template<jau::req::packed_
integral T>
279 template<jau::req::packed_
integral T>
284 template<jau::req::packed_
integral T>
289 template<jau::req::packed_
integral T>
294 template<jau::req::packed_
integral T>
297 r.
x=s/r.
x; r.
y=s/r.
y;
301 template<jau::req::packed_
integral T>
303 return Vector2I<T>(std::min(lhs.x, rhs.x), std::min(lhs.y, rhs.y));
306 template<jau::req::packed_
integral T>
308 return Vector2I<T>(std::max(lhs.x, rhs.x), std::max(lhs.y, rhs.y));
311 template<jau::req::packed_
integral T>
313 return Vector2I<T>(std::abs(lhs.x), std::abs(lhs.y));
316 template<jau::req::packed_
integral T>
318 return out << v.toString();
324 static_assert(
sizeof(int) ==
alignof(
Vec2i));
326 static_assert(
sizeof(int)*2 ==
sizeof(
Vec2i));
331 template<jau::req::packed_
integral T>
337 static_assert(
sizeof(int) ==
alignof(
Point2i));
339 static_assert(
sizeof(int)*2 ==
sizeof(
Point2i));
344 static_assert(
sizeof(int32_t) ==
alignof(
Point2i32));
346 static_assert(
sizeof(int32_t)*2 ==
sizeof(
Point2i32));
351 static_assert(
sizeof(uint32_t) ==
alignof(
Point2u32));
353 static_assert(
sizeof(uint32_t)*2 ==
sizeof(
Point2u32));
2D vector using two value_type components.
constexpr bool operator==(const Vector2I &rhs) const noexcept
const value_type * const_iterator
constexpr Vector2I & normalize() noexcept
Normalize this vector in place, returns *this.
size_t hashCode() const noexcept
TODO constexpr bool operator<=>(const vec2i_t& rhs ) const noexcept { return ... }...
constexpr Vector2I & scale(const value_type s) noexcept
this = this * s, component wise.
constexpr Vector2I & operator/=(const Vector2I &s) noexcept
this = this / {s.x, s.y}, component wise.
constexpr Vector2I(const value_type v) noexcept
constexpr_cxx26 void rotate(const float_type radians, const Vector2I &ctr)
constexpr Vector2I & mul(const value_type sx, const value_type sy) noexcept
this = this * {sx, sy}, component wise.
constexpr Vector2I & operator+=(const Vector2I &rhs) noexcept
this = this + rhs, component wise.
static constexpr const size_t components
const value_type & const_reference
constexpr const_iterator cbegin() const noexcept
constexpr Vector2I & set(const_iterator xy) noexcept
this = xy, returns this.
std::string toString() const noexcept
const value_type * const_pointer
void rotate(const float_type sin, const float_type cos, const Vector2I &ctr)
constexpr Vector2I & set(const value_type vx, const value_type vy) noexcept
constexpr Vector2I & mul(const Vector2I &s) noexcept
this = this * {s.x, s.y}, component wise.
static constexpr int value_alignment
constexpr value_type operator[](size_t i) const noexcept
Returns read-only component.
constexpr value_type length() const noexcept
Return the length of this vector, a.k.a the norm or magnitude
constexpr Vector2I & operator=(const Vector2I &) noexcept=default
constexpr Vector2I & operator*=(const value_type s) noexcept
this = this * s, component wise.
constexpr Vector2I & operator/=(const value_type s) noexcept
this = this * s, component wise.
static constexpr const value_type one
bool intersects(const Vector2I &o)
constexpr Vector2I & add(const value_type dx, const value_type dy) noexcept
this = this + {sx, sy}, component wise.
constexpr Vector2I & operator*=(const Vector2I &s) noexcept
this = this * {s.x, s.y}, component wise.
constexpr Vector2I & operator-=(const Vector2I &rhs) noexcept
this = this - rhs, component wise.
constexpr Vector2I copy() noexcept
constexpr Vector2I & operator=(Vector2I &&) noexcept=default
constexpr Vector2I & add(const Vector2I &d) noexcept
this = this + {d.x, d.y}, component wise.
constexpr Vector2I(Vector2I &&o) noexcept=default
static constexpr const size_t byte_size
jau::float_bytes< sizeof(value_type)>::type float_type
constexpr bool is_zero() const noexcept
constexpr Vector2I() noexcept
constexpr Vector2I(const Vector2I &o) noexcept=default
static constexpr const value_type zero
constexpr iterator get(iterator xy) const noexcept
xy = this, returns xy.
constexpr reference operator[](size_t i) noexcept
Returns writeable reference to component.
constexpr iterator begin() noexcept
constexpr value_type length_sq() const noexcept
Return the squared length of this vector, a.k.a the squared norm or squared magnitude
constexpr Vector2I(const value_type x_, const value_type y_) noexcept
constexpr jau::sint_bytes_t< sizeof(T)> round_to_int(const T v) noexcept
Returns the rounded value cast to signed int.
constexpr bool 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 Matrix4< T > operator*(const Matrix4< T > &lhs, const Matrix4< T > &rhs) noexcept
constexpr Vector2F< T > abs(const Vector2F< T > &lhs) noexcept
constexpr Quaternion< T > operator+(const Quaternion< T > &lhs, const Quaternion< T > &rhs) noexcept
constexpr Vector2F< T > max(const Vector2F< T > &lhs, const Vector2F< T > &rhs) noexcept
Vector2I< T > Point2I
Point2I alias of Vector2I.
Point2I< int32_t > Point2i32
std::ostream & operator<<(std::ostream &out, const Matrix4< T > &v) noexcept
constexpr Vector2F< T > min(const Vector2F< T > &lhs, const Vector2F< T > &rhs) noexcept
Point2I< uint32_t > Point2u32
constexpr Vector2F< T > operator/(const Vector2F< T > &lhs, const T s) noexcept