63 lines
1.0 KiB
C++
63 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
|
|
namespace math
|
|
{
|
|
|
|
class Vector
|
|
{
|
|
public:
|
|
Vector() : x{0.0f}, y{0.0f}
|
|
{
|
|
}
|
|
|
|
Vector(float x, float y) : x{x}, y{y}
|
|
{
|
|
}
|
|
|
|
// float& operator[](size_t idx) { return m_v[idx]; }
|
|
// const float& operator[](size_t idx) const { return m_v[idx]; }
|
|
|
|
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
|