aboutsummaryrefslogtreecommitdiff
path: root/rect.c
blob: 69758c15a224db6509765edab09c031069075653 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "rect.h"

Rect* rect_clip(Rect* r, const Rect* c) {
	int n;
	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 = r->x + r->w - (c->x + c->w)) > 0)
		r->w -= n;
	if ((n = r->y + r->h - (c->y + c->h)) > 0)
		r->h -= n;
	return r;
}

Rect* rect_clipr(Rect* r, const int* c) {
	int n;
	if ((n = c[0] - r->x) > 0) {
		r->w -= n;
		r->x += n;
	}
	if ((n = c[1] - r->y) > 0) {
		r->h -= n;
		r->y += n;
	}
	if ((n = r->x + r->w - c[2]) > 0)
		r->w -= n;
	if ((n = r->y + r->h - c[3]) > 0)
		r->h -= n;
	return r;
}

Rect* rect_clips(Rect* r, Rect* s, const Rect* c) {
	int n;
	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 = r->x + r->w - (c->x + c->w)) > 0) {
		r->w -= n;
		s->w -= n;
	}
	if ((n = r->y + r->h - (c->y + c->h)) > 0) {
		r->h -= n;
		s->h -= n;
	}
	return r;
}

Rect* rect_clipsr(Rect* r, Rect* s, const int* c) {
	int n;
	if ((n = c[0] - r->x) > 0) {
		r->w -= n;
		r->x += n;
		s->w -= n;
		s->x += n;
	}
	if ((n = c[1] - r->y) > 0) {
		r->h -= n;
		r->y += n;
		s->h -= n;
		s->y += n;
	}
	if ((n = r->x + r->w - c[2]) > 0) {
		r->w -= n;
		s->w -= n;
	}
	if ((n = r->y + r->h - c[3]) > 0) {
		r->h -= n;
		s->h -= n;
	}
	return r;
}