aboutsummaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-07-09 17:02:42 +0200
committerFederico Angelilli <code@fedang.net>2024-07-09 17:02:42 +0200
commit0c567c67933cc48ac57f08167d88a57ce0504524 (patch)
treeda7c5ccc0935093cf5ecc661371db324ea0005cb /src/util.h
parent28adc6b395d2fb7545189636cec3651b9c2a5f73 (diff)
Add event handling
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..9e84a7c
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,29 @@
+#ifndef COMET_UTIL_H
+#define COMET_UTIL_H
+
+#include <time.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+struct timespec timespec_diff(struct timespec a, struct timespec b);
+
+bool timespec_greater(struct timespec a, struct timespec b);
+
+// Check if point (px, py) is inside a rectangle in (x, y), (x+w, y), (x, y+h) and (w+h, y+h)
+static inline bool in_rect(int px, int py, int x, int y, int w, int h)
+{
+ return px >= x && px <= x + w && py >= y && py <= y + h;
+}
+
+// Check if point (px, py) is inside a circle of radius r and center (x, y)
+static inline bool in_circle(int px, int py, int x, int y, int r)
+{
+ int dx = x - px;
+ int dy = y - py;
+ return (dx * dx + dy * dy) <= r * r;
+}
+
+// Check if point (px, py) is inside a capsule in (x, y), (x+w, y), (x, y+h) and (w+h, y+h)
+bool in_capsule(int px, int py, int x, int y, int w, int h);
+
+#endif