diff options
author | quou <quou@disroot.org> | 2024-06-30 18:24:01 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-06-30 18:27:11 +1000 |
commit | 39100e7292d3ee12d387fddfa0f0d7b712e31e1c (patch) | |
tree | 28f26b19de857868aeb9ecf23a7fecfc170addf9 /rect.c |
initial commit.
Diffstat (limited to 'rect.c')
-rw-r--r-- | rect.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -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; +} |