21template <
typename T>
class Vec2 {
44 return std::atan2(
y - other.
y,
x - other.
x);
53 if (
x == 0 &&
y == 0) {
56 return std::atan2(
y,
x);
65 return std::hypot(
x - other.
x,
y - other.
y);
75 return (
x * other.
x) + (
y * other.
y);
85 return (
x * other.
y) - (
y * other.
x);
94 return std::sqrt((
x *
x) + (
y *
y));
104 return Vec2(
x + other.
x,
y + other.
y);
114 return Vec2(
x - other.
x,
y - other.
y);
124 return Vec2(
x * scalar,
y * scalar);
134 return Vec2(
x / scalar,
y / scalar);
144 return Vec2(
x % scalar,
y % scalar);
226template <
typename T>
class Vec3 {
251 T dot_product =
dot(other);
253 return std::acos(dot_product / magnitudes);
262 return std::sqrt((
x - other.
x) * (
x - other.
x) + (
y - other.
y) * (
y - other.
y)
263 + (
z - other.
z) * (
z - other.
z));
273 return (
x * other.
x) + (
y * other.
y) + (
z * other.
z);
283 return Vec3((
y * other.
z) - (
z * other.
y), (
z * other.
x) - (
x * other.
z),
284 (
x * other.
y) - (
y * other.
x));
293 return std::sqrt((
x *
x) + (
y *
y) + (
z *
z));
303 return Vec3(
x + other.
x,
y + other.
y,
z + other.
z);
313 return Vec3(
x - other.
x,
y - other.
y,
z - other.
z);
323 return Vec3(
x * scalar,
y * scalar,
z * scalar);
333 return Vec3(
x / scalar,
y / scalar,
z / scalar);
343 return Vec3(
x % scalar,
y % scalar,
z % scalar);
433template <
typename T>
class Quad {
461 Quad(T x, T y, T width, T height)
463 ,
size(width, height)
Quad operator-(const Quad< T > &quad) const
Subtract a vector from the rectangle.
bool collides_top(const Quad &other) const
Quad operator+(const Quad< T > &quad) const
Add a vector to the rectangle.
Quad operator/(const T scalar) const
Divide the rectangle by a scalar.
Quad()
Default constructor for the Quad class.
bool collides(const Quad &other) const
Check if a rectangle is inside the rectangle.
Quad(const Vec2< T > &position, const Vec2< T > &size)
Constructor for the Quad class.
bool collides_left(const Quad &other) const
Vec2< T > get_center() const
Get center of the rectangle.
bool collides_bottom(const Quad &other) const
Quad(T x, T y, T width, T height)
Constructor for the Quad class.
Vec2< T > size
The size of the rectangle.
Vec2< T > position
The position of the rectangle.
void set_size(T width, T height)
Set the size of the rectangle.
bool collides_right(const Quad &other) const
Quad operator*(const T scalar) const
Multiply the rectangle by a scalar.
bool contains(const Vec2< T > &point) const
Check if a point is inside the rectangle.
bool contains(T x, T y) const
Check if coordinates are inside the rectangle.
void set_position(T x, T y)
Set the position of the rectangle.
T cross(const Vec2 &other) const
Calculate the cross product of two vectors.
bool operator==(const Vec2 &other) const =default
Equality operator for the Vec2 class.
Vec2 operator+(const Vec2 &other) const
Addition operator for the Vec2 class.
Vec2 operator/(const T scalar) const
Division operator for the Vec2 class.
Vec2 & operator-=(const Vec2 &other)
Subtraction assignment operator for the Vec2 class.
Vec2()=default
Default constructor for the Vec2 class.
Vec2 operator%(const T scalar) const
Modulo the Vec2 object by a scalar.
Vec2 & operator%=(const T scalar)
Modulo assignment operator for the Vec2 class.
T y
The y component of the vector.
T x
The x component of the vector.
Vec2 operator*(const T scalar) const
Multiplication operator for the Vec2 class.
T distance(const Vec2 &other) const
Get distance between two vectors.
Vec2 & operator/=(const T scalar)
Division assignment operator for the Vec2 class.
Vec2(T x, T y)
Constructor for the Vec2 class.
Vec2 & operator*=(const T scalar)
Multiplication assignment operator for the Vec2 class.
T angle(const Vec2 &other) const
Get angle of two vectors.
T magnitude() const
Calculate the magnitude of the vector.
Vec2 operator-(const Vec2 &other) const
Subtraction operator for the Vec2 class.
T angle() const
Calculate the angle of the vector.
Vec2 & operator+=(const Vec2 &other)
Addition assignment operator for the Vec2 class.
T dot(const Vec2 &other) const
Calculate the dot product of two vectors.
T z
The z component of the vector.
Vec3()=default
Default constructor for the Vec3 class.
Vec3(T x, T y, T z)
Constructor for the Vec3 class.
Vec3 operator/(const T scalar) const
Division operator for the Vec3 class.
T x
The x component of the vector.
Vec3 cross(const Vec3 &other) const
Calculate the cross product of two vectors.
Vec3 & operator-=(const Vec3 &other)
Subtraction assignment operator for the Vec3 class.
T dot(const Vec3 &other) const
Calculate the dot product of two vectors.
Vec3 operator%(const T scalar) const
Modulo the Vec3 object by a scalar.
Vec3 operator+(const Vec3 &other) const
Addition operator for the Vec3 class.
T magnitude() const
Calculate the magnitude of the vector.
T y
The y component of the vector.
T angle(const Vec3 &other) const
Get angle between two vectors (in 3D space).
Vec3 & operator*=(const T scalar)
Multiplication assignment operator for the Vec3 class.
Vec3 & operator/=(const T scalar)
Division assignment operator for the Vec3 class.
bool operator==(const Vec3 &other) const =default
Equality operator for the Vec3 class.
Vec3 operator-(const Vec3 &other) const
Subtraction operator for the Vec3 class.
Vec3 & operator+=(const Vec3 &other)
Addition assignment operator for the Vec3 class.
T distance(const Vec3 &other) const
Get distance between two vectors.
Vec3 & operator%=(const T scalar)
Modulo assignment operator for the Vec3 class.
Vec3 operator*(const T scalar) const
Multiplication operator for the Vec3 class.