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
|
#include <fitz.h>
fz_rect fz_infiniterect = { { 1, 1}, {-1, -1} };
fz_rect fz_emptyrect = { { 0, 0}, {0, 0} };
static fz_irect infinite = { { 1, 1}, {-1, -1} };
static fz_irect empty = { { 0, 0}, {0, 0} };
fz_irect
fz_roundrect(fz_rect f)
{
fz_irect i;
i.min.x = fz_floor(f.min.x);
i.min.y = fz_floor(f.min.y);
i.max.x = fz_ceil(f.max.x);
i.max.y = fz_ceil(f.max.y);
return i;
}
fz_rect
fz_intersectrects(fz_rect a, fz_rect b)
{
fz_rect r;
if (fz_isinfiniterect(a)) return b;
if (fz_isinfiniterect(b)) return a;
r.min.x = MAX(a.min.x, b.min.x);
r.min.y = MAX(a.min.y, b.min.y);
r.max.x = MIN(a.max.x, b.max.x);
r.max.y = MIN(a.max.y, b.max.y);
return (r.max.x < r.min.x || r.max.y < r.min.y) ? fz_emptyrect : r;
}
fz_rect
fz_mergerects(fz_rect a, fz_rect b)
{
fz_rect r;
if (fz_isinfiniterect(a) || fz_isinfiniterect(b))
return fz_infiniterect;
if (fz_isemptyrect(a)) return b;
if (fz_isemptyrect(b)) return a;
r.min.x = MIN(a.min.x, b.min.x);
r.min.y = MIN(a.min.y, b.min.y);
r.max.x = MAX(a.max.x, b.max.x);
r.max.y = MAX(a.max.y, b.max.y);
return r;
}
fz_irect
fz_intersectirects(fz_irect a, fz_irect b)
{
fz_irect r;
if (fz_isinfiniterect(a)) return b;
if (fz_isinfiniterect(b)) return a;
r.min.x = MAX(a.min.x, b.min.x);
r.min.y = MAX(a.min.y, b.min.y);
r.max.x = MIN(a.max.x, b.max.x);
r.max.y = MIN(a.max.y, b.max.y);
return (r.max.x < r.min.x || r.max.y < r.min.y) ? empty : r;
}
fz_irect
fz_mergeirects(fz_irect a, fz_irect b)
{
fz_irect r;
if (fz_isinfiniterect(a) || fz_isinfiniterect(b))
return infinite;
if (fz_isemptyrect(a)) return b;
if (fz_isemptyrect(b)) return a;
r.min.x = MIN(a.min.x, b.min.x);
r.min.y = MIN(a.min.y, b.min.y);
r.max.x = MAX(a.max.x, b.max.x);
r.max.y = MAX(a.max.y, b.max.y);
return r;
}
|