summaryrefslogtreecommitdiff
path: root/src/size.hh
blob: 8fcc53f05cee28ee839a7858abb8f3154e45a517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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