summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-25 20:12:55 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-25 20:12:55 -0500
commitbf9a22bfff4051a70dcebbcd471eddb7b7724f7a (patch)
tree45c1864c78c6744977e39a994a1736712c419e9b /math.c
parent261c177480a0379e77af6ad36a6259f751a504c7 (diff)
clip selector, save as
Diffstat (limited to 'math.c')
-rw-r--r--math.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/math.c b/math.c
index 9d72aa2..78f1ecc 100644
--- a/math.c
+++ b/math.c
@@ -771,8 +771,11 @@ static float rects_intersect(Rect r1, Rect r2) {
// returns whether or not there is any of the clipped rectangle left
static bool rect_clip_to_rect(Rect *clipped, Rect clipper) {
+ v2 start_pos = clipped->pos;
clipped->pos.x = maxf(clipped->pos.x, clipper.pos.x);
clipped->pos.y = maxf(clipped->pos.y, clipper.pos.y);
+ clipped->size = v2_add(clipped->size, v2_sub(start_pos, clipped->pos));
+
clipped->size.x = clampf(clipped->size.x, 0, clipper.pos.x + clipper.size.x - clipped->pos.x);
clipped->size.y = clampf(clipped->size.y, 0, clipper.pos.y + clipper.size.y - clipped->pos.y);
return clipped->size.x > 0 && clipped->size.y > 0;