aboutsummaryrefslogtreecommitdiff
path: root/rect.c
blob: aafa64561e161dcf1743c862ab3d48cd7b9c2791 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "rect.h"

Rectangle make_rect(int x, int y, int w, int h) {
	Rectangle r;
	r.x = x;
	r.y = y;
	r.w = w;
	r.h = h;
	return r;
}

int rects_overlap(const Rectangle* a, const Rectangle* b) {
	return
		a->x + a->w > b->x &&
		a->y + a->h > b->y &&
		a->x < b->x + b->w &&
		a->y < b->y + b->h;
}

int rects_overlap2(
	int x0,
	int y0,
	int w0,
	int h0,
	int x1,
	int y1,
	int w1,
	int h1
) {
	return
		x0 + w0 > x1 &&
		y0 + h0 > y1 &&
		x0 < x1 + w1 &&
		y0 < y1 + h1;
}