| 9 | namespace OpenLoco::Ui |
| 10 | { |
| 11 | class Rect |
| 12 | { |
| 13 | public: |
| 14 | Ui::Size size; |
| 15 | Ui::Point origin; |
| 16 | Rect(int32_t x, int32_t y, int32_t width, int32_t height) |
| 17 | : size{ width, height } |
| 18 | , origin{ x, y } |
| 19 | { |
| 20 | } |
| 21 | |
| 22 | static Rect fromLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) |
| 23 | { |
| 24 | return Rect(left, top, right - left, bottom - top); |
| 25 | } |
| 26 | |
| 27 | bool intersects(const Rect& r2) const |
| 28 | { |
| 29 | if (origin.x + size.width <= r2.origin.x) |
| 30 | { |
| 31 | return false; |
| 32 | } |
| 33 | if (origin.y + size.height <= r2.origin.y) |
| 34 | { |
| 35 | return false; |
| 36 | } |
| 37 | if (origin.x >= r2.origin.x + r2.size.width) |
| 38 | { |
| 39 | return false; |
| 40 | } |
| 41 | if (origin.y >= r2.origin.y + r2.size.height) |
| 42 | { |
| 43 | return false; |
| 44 | } |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | Rect intersection(const Rect r2) const |
| 49 | { |
| 50 | int left = std::max(this->origin.x, r2.origin.x); |
| 51 | int top = std::max(this->origin.y, r2.origin.y); |
| 52 | int right = std::min(this->origin.x + this->size.width, r2.origin.x + r2.size.width); |
| 53 | int bottom = std::min(this->origin.y + this->size.height, r2.origin.y + r2.size.height); |
| 54 | |
| 55 | return Rect(left, top, right - left, bottom - top); |
| 56 | } |
| 57 | |
| 58 | int32_t width() const |
| 59 | { |
| 60 | return this->size.width; |
| 61 | } |
| 62 | |
| 63 | int32_t height() const |
| 64 | { |
| 65 | return this->size.height; |
| 66 | } |
| 67 | |
| 68 | int32_t left() const |
no outgoing calls
no test coverage detected