diff options
Diffstat (limited to 'src/size.hh')
| -rw-r--r-- | src/size.hh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/size.hh b/src/size.hh new file mode 100644 index 0000000..8fcc53f --- /dev/null +++ b/src/size.hh @@ -0,0 +1,30 @@ +#ifndef SIZE_HH +#define SIZE_HH + +#include <compare> +#include <cstdint> + +struct Size final { + Size() : width(0), height(0) {} + Size(uint32_t width, uint32_t height) : width(width), height(height) {} + + bool empty() const { return width == 0 || height == 0; } + + operator bool() const { return !empty(); } + + std::strong_ordering operator<=>(Size const& other) const { + if (empty()) { + return other.empty() ? std::strong_ordering::equal + : std::strong_ordering::less; + } + if (other.empty()) + return std::strong_ordering::greater; + auto ret = width <=> other.width; + return ret == std::strong_ordering::equal ? height <=> other.height : ret; + } + + uint32_t width; + uint32_t height; +}; + +#endif // SIZE_HH |
