cpp_drawing/math/vector.hpp
2025-09-26 15:42:44 +02:00

67 lines
1.1 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}
{
}
Vector(int x, int y) : x{static_cast<float>(x)}, y{static_cast<float>(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