diff options
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; +} |