From 39100e7292d3ee12d387fddfa0f0d7b712e31e1c Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 30 Jun 2024 18:24:01 +1000 Subject: initial commit. --- rect.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 rect.c (limited to 'rect.c') 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; +} -- cgit v1.2.3-54-g00ecf