aboutsummaryrefslogtreecommitdiff
path: root/src/common.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2025-05-17 18:03:44 -0700
committerrtk0c <[email protected]>2025-05-17 18:03:44 -0700
commite041b2a3ea3835a6b3a59dfbd1f24a86fd104396 (patch)
tree876f22bcc7710864d32ea0d61150bfc6c3a8ad17 /src/common.hpp
parent152580faf7e7665a04be69b4a0e0538cf39c975c (diff)
Dirty rect & UI features
- dirty rectangle (and the math library thereof) - drawing it - no more std::vector in Sandbox - single step - cycle counter display
Diffstat (limited to 'src/common.hpp')
-rw-r--r--src/common.hpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/common.hpp b/src/common.hpp
index 1c64c34..e745ece 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -7,5 +7,42 @@
// clang-format on
struct Pt {
- int x, y;
+ int x{}, y{};
+
+ Pt operator+(Pt o) const { return { x + o.x, y + o.y }; }
+ Pt operator-(Pt o) const { return { x - o.x, y - o.y }; }
+ Pt operator*(int k) const { return { x * k, y * k }; }
+ Pt operator/(int k) const { return { x / k, y / k }; }
+ bool operator==(const Pt&) const = default;
};
+
+// avoid including <algorithm>
+#define MMIN(x, y) ((x) < (y) ? (x) : (y))
+#define MMAX(x, y) ((x) > (y) ? (x) : (y))
+inline Pt pt_min(Pt a, Pt b) {
+ return Pt{ MMIN(a.x, b.x), MMIN(a.y, b.y) };
+}
+inline Pt pt_max(Pt a, Pt b) {
+ return Pt{ MMAX(a.x, b.x), MMAX(a.y, b.y) };
+}
+#undef MMIN
+#undef MMAX
+
+struct Rect {
+ Pt bl, tr;
+
+ Rect() {}
+ Rect(Pt tl, Pt br)
+ : bl(tl), tr(br) {}
+ Rect(int x0, int y0, int x1, int y1)
+ : bl(x0, y0), tr(x1, y1) {}
+
+ bool operator==(const Rect&) const = default;
+};
+
+inline Rect rect_union(Rect a, Rect b) {
+ return Rect(pt_min(a.bl, b.bl), pt_max(a.tr, b.tr));
+}
+inline Rect rect_union(Rect a, Pt b) {
+ return Rect(pt_min(a.bl, b), pt_max(a.tr, b));
+}