]> Dogcows Code - chaz/openbox/blob - openbox/geom.h
add some interesection shit, and RECT_LEFT/RIGHT/TOP/BOTTOM
[chaz/openbox] / openbox / geom.h
1 #ifndef __geom_h
2 #define __geom_h
3
4 typedef struct _Point {
5 int x;
6 int y;
7 } Point;
8
9 #define POINT_SET(pt, nx, ny) (pt).x = (nx), (pt).y = (ny)
10
11 typedef struct _Size {
12 int width;
13 int height;
14 } Size;
15
16 #define SIZE_SET(sz, w, h) (sz).width = (w), (sz).height = (h)
17
18 typedef struct _Rect {
19 int x;
20 int y;
21 int width;
22 int height;
23 } Rect;
24
25 #define RECT_LEFT(r) ((r).x)
26 #define RECT_TOP(r) ((r).y)
27 #define RECT_RIGHT(r) ((r).x + (r).width - 1)
28 #define RECT_BOTTOM(r) ((r).y + (r).height - 1)
29
30 #define RECT_SET_POINT(r, nx, ny) \
31 (r).x = (nx), (r).y = (ny)
32 #define RECT_SET_SIZE(r, w, h) \
33 (r).width = (w), (r).height = (h)
34 #define RECT_SET(r, nx, ny, w, h) \
35 (r).x = (nx), (r).y = (ny), (r).width = (w), (r).height = (h)
36
37 #define RECT_EQUAL(r1, r2) ((r1).x == (r2).x && (r1).y == (r2).y && \
38 (r1).width == (r2).width && \
39 (r1).height == (r2).height)
40
41 #define RECT_CONTAINS(r, px, py) \
42 ((px) >= (r).x && (px) < (r).x + (r).width && \
43 (py) >= (r).y && (py) < (r).y + (r).height)
44 #define RECT_CONTAINS_RECT(r, o) \
45 ((o).x >= (r).x && (o).x + (o).width <= (r).x + (r).width && \
46 (o).y >= (r).y && (o).y + (o).height <= (r).y + (r).height)
47 #define RECT_INTERSECTS_RECT(r, o) \
48 ((o).x < (r).x + (r).width && (o).x + (o).width > (r).x && \
49 (o).y < (r).y + (r).height && (o).y + (o).height > (r).y)
50
51 #define RECT_SET_INTERSECTION(r, a, b) \
52 ((r).x = MAX((a).x, (b).x), \
53 (r).y = MAX((a).y, (b).y), \
54 (r).width = MIN((a).x + (a).width - 1, \
55 (b).x + (b).width - 1) - (r).x + 1, \
56 (r).height = MIN((a).y + (a).height - 1, \
57 (b).y + (b).height - 1) - (r).y + 1)
58
59 typedef struct _Strut {
60 int left;
61 int top;
62 int right;
63 int bottom;
64 } Strut;
65
66 typedef struct _StrutPartial {
67 int left;
68 int top;
69 int right;
70 int bottom;
71
72 int left_start, left_end;
73 int top_start, top_end;
74 int right_start, right_end;
75 int bottom_start, bottom_end;
76 } StrutPartial;
77
78 #define STRUT_SET(s, l, t, r, b) \
79 (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b)
80
81 #define STRUT_PARTIAL_SET(s, l, t, r, b, ls, le, ts, te, rs, re, bs, be) \
82 (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b), \
83 (s).left_start = (ls), (s).left_end = (le), \
84 (s).top_start = (ts), (s).top_end = (te), \
85 (s).right_start = (rs), (s).right_end = (re), \
86 (s).bottom_start = (bs), (s).bottom_end = (be)
87
88 #define STRUT_ADD(s1, s2) \
89 (s1).left = MAX((s1).left, (s2).left), \
90 (s1).right = MAX((s1).right, (s2).right), \
91 (s1).top = MAX((s1).top, (s2).top), \
92 (s1).bottom = MAX((s1).bottom, (s2).bottom)
93
94 #define STRUT_EQUAL(s1, s2) \
95 ((s1).left == (s2).left && \
96 (s1).top == (s2).top && \
97 (s1).right == (s2).right && \
98 (s1).bottom == (s2).bottom && \
99 (s1).left_start == (s2).left_start && \
100 (s1).left_end == (s2).left_end && \
101 (s1).top_start == (s2).top_start && \
102 (s1).top_end == (s2).top_end && \
103 (s1).right_start == (s2).right_start && \
104 (s1).right_end == (s2).right_end && \
105 (s1).bottom_start == (s2).bottom_start && \
106 (s1).bottom_end == (s2).bottom_end)
107
108 #endif
This page took 0.038674 seconds and 5 git commands to generate.