devilutionX/Source/engine/size.hpp
ephphatha c4c664c6be Add class to allow iterating over all points in a rectangle
Co-authored-by: Gleb Mazovetskiy <glex.spb@gmail.com>
2022-01-19 03:05:27 +01:00

61 lines
1,010 B
C++

#pragma once
namespace devilution {
struct Size {
int width;
int height;
Size() = default;
constexpr Size(int width, int height)
: width(width)
, height(height)
{
}
explicit constexpr Size(int size)
: width(size)
, height(size)
{
}
bool operator==(const Size &other) const
{
return width == other.width && height == other.height;
}
bool operator!=(const Size &other) const
{
return !(*this == other);
}
constexpr Size &operator*=(const int factor)
{
width *= factor;
height *= factor;
return *this;
}
constexpr Size &operator*=(const float factor)
{
width = static_cast<int>(width * factor);
height = static_cast<int>(height * factor);
return *this;
}
constexpr Size &operator/=(const int factor)
{
width /= factor;
height /= factor;
return *this;
}
constexpr friend Size operator/(Size a, const int factor)
{
a /= factor;
return a;
}
};
} // namespace devilution