summaryrefslogtreecommitdiff
path: root/rect.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-06-30 18:24:01 +1000
committerquou <quou@disroot.org>2024-06-30 18:27:11 +1000
commit39100e7292d3ee12d387fddfa0f0d7b712e31e1c (patch)
tree28f26b19de857868aeb9ecf23a7fecfc170addf9 /rect.c
initial commit.
Diffstat (limited to 'rect.c')
-rw-r--r--rect.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/rect.c b/rect.c
new file mode 100644
index 0000000..c72c66e
--- /dev/null
+++ b/rect.c
@@ -0,0 +1,46 @@
+#include "maths.h"
+#include "rect.h"
+
+Rect* rect_clip(Rect* r, const Rect* c) {
+ int n;
+ int x = r->x, y = r->y;
+ if ((n = c->x - r->x) > 0) {
+ r->w -= n;
+ r->x += n;
+ }
+ if ((n = c->y - r->y) > 0) {
+ r->h -= n;
+ r->y += n;
+ }
+ if ((n = x + r->w - (c->x + c->w)) > 0)
+ r->w -= n;
+ if ((n = y + r->h - (c->y + c->h)) > 0)
+ r->h -= n;
+ return r;
+}
+
+Rect* rect_clips(Rect* r, Rect* s, const Rect* c) {
+ int n;
+ int x = r->x, y = r->y;
+ if ((n = c->x - r->x) > 0) {
+ r->w -= n;
+ r->x += n;
+ s->w -= n;
+ s->x += n;
+ }
+ if ((n = c->y - r->y) > 0) {
+ r->h -= n;
+ r->y += n;
+ s->h -= n;
+ s->y += n;
+ }
+ if ((n = x + r->w - (c->x + c->w)) > 0) {
+ r->w -= n;
+ s->w -= n;
+ }
+ if ((n = y + r->h - (c->y + c->h)) > 0) {
+ r->h -= n;
+ s->h -= n;
+ }
+ return r;
+}