50 lines
1004 B
C++
50 lines
1004 B
C++
#pragma once
|
|
|
|
namespace math
|
|
{
|
|
|
|
/**
|
|
* @brief 2D Vector
|
|
*
|
|
* Represents a point or a vector in 2D. Provides basic vector operations.
|
|
*/
|
|
class Vector
|
|
{
|
|
public:
|
|
Vector() : x{0.0f}, y{0.0f} {}
|
|
Vector(float x, float y) : x{x}, y{y} {}
|
|
Vector(int x, int y) : x{static_cast<float>(x)}, y{static_cast<float>(y)} {}
|
|
|
|
Vector operator+(const Vector& other) const { return Vector(x + other.x, y + other.y); }
|
|
|
|
Vector& operator+=(const Vector& other)
|
|
{
|
|
x += other.x;
|
|
y += other.y;
|
|
return *this;
|
|
}
|
|
|
|
Vector operator-(const Vector& other) const { return Vector(x - other.x, y - other.y); }
|
|
|
|
Vector& operator-=(const Vector& other)
|
|
{
|
|
x -= other.x;
|
|
y -= other.y;
|
|
return *this;
|
|
}
|
|
|
|
Vector operator*(float factor) const { return Vector(x * factor, y * factor); }
|
|
|
|
Vector& operator*=(float factor)
|
|
{
|
|
x *= factor;
|
|
y *= factor;
|
|
return *this;
|
|
}
|
|
|
|
public:
|
|
float x, y;
|
|
};
|
|
|
|
} // namespace math
|