blob: 847f6f4ae4f4c57e64599086e03d982c89d27802 (
plain) (
blame)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright 2021 yuzu Emulator Project
// Copyright 2006 The Android Open Source Project
// Parts of this implementation were base on:
// https://cs.android.com/android/platform/superproject/+/android-5.1.1_r38:frameworks/native/include/ui/Rect.h
#pragma once
#include <cstdint>
#include <utility>
#include "common/common_types.h"
namespace android {
class Rect final {
public:
constexpr Rect() = default;
constexpr Rect(s32 width_, s32 height_) : right{width_}, bottom{height_} {}
constexpr s32 Left() const {
return left;
}
constexpr s32 Top() const {
return top;
}
constexpr s32 Right() const {
return right;
}
constexpr s32 Bottom() const {
return bottom;
}
constexpr bool IsEmpty() const {
return (GetWidth() <= 0) || (GetHeight() <= 0);
}
constexpr s32 GetWidth() const {
return right - left;
}
constexpr s32 GetHeight() const {
return bottom - top;
}
constexpr bool operator==(const Rect& rhs) const {
return (left == rhs.left) && (top == rhs.top) && (right == rhs.right) &&
(bottom == rhs.bottom);
}
constexpr bool operator!=(const Rect& rhs) const {
return !operator==(rhs);
}
constexpr bool Intersect(const Rect& with, Rect* result) const {
result->left = std::max(left, with.left);
result->top = std::max(top, with.top);
result->right = std::min(right, with.right);
result->bottom = std::min(bottom, with.bottom);
return !result->IsEmpty();
}
private:
s32 left{};
s32 top{};
s32 right{};
s32 bottom{};
};
static_assert(sizeof(Rect) == 16, "Rect has wrong size");
} // namespace android
|