Files
Frame/frame/src/Vector.hpp
2022-03-03 22:24:30 +01:00

68 lines
1.2 KiB
C++

#pragma once
#include "Size.hpp"
#include <iostream>
namespace frame
{
struct Vector
{
int32_t x;
int32_t y;
Vector() = default;
Vector(int32_t x, int32_t y)
: x(x)
, y(y)
{
}
Vector(Size const& size)
: x(size.width)
, y(size.height)
{
}
void operator=(Size const& size)
{
x = size.width;
y = size.height;
}
};
inline bool operator==(Vector const& a, Vector const& b)
{
return a.x == b.x && a.y == b.y;
}
inline bool operator!=(Vector const& a, Vector const& b)
{
return !(a == b);
}
inline Vector& operator+=(Vector& a, Vector const& b)
{
a.x += b.x;
a.y += b.y;
return a;
}
inline Vector& operator-=(Vector& a, Vector const& b)
{
a.x -= b.x;
a.y -= b.y;
return a;
}
inline std::ostream& operator<<(std::ostream& os, Vector const& v)
{
return os << "x: " << v.x << " y: " << v.y;
}
inline Vector operator+(Vector const& a, Vector const& b)
{
return {a.x + b.x, a.y + b.y};
}
} // namespace frame