ReactOS 0.4.15-dev-8096-ga0eec98
rect.h
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/winsrv/consrv/include/rect.h
5 * PURPOSE: Rectangle helper functions
6 * PROGRAMMERS: Gé van Geldorp
7 * Jeffrey Morlan
8 */
9
10#pragma once
11
12#define ConioInitLongRect(Rect, Top, Left, Bottom, Right) \
13do { \
14 ((Rect)->top) = Top; \
15 ((Rect)->left) = Left; \
16 ((Rect)->bottom) = Bottom; \
17 ((Rect)->right) = Right; \
18} while (0)
19
20#define ConioInitRect(Rect, top, left, bottom, right) \
21do { \
22 ((Rect)->Top) = top; \
23 ((Rect)->Left) = left; \
24 ((Rect)->Bottom) = bottom; \
25 ((Rect)->Right) = right; \
26} while (0)
27
28#define ConioIsRectEmpty(Rect) \
29 (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
30
31#define ConioRectHeight(Rect) \
32 (((Rect)->Top > (Rect)->Bottom) ? 0 : ((Rect)->Bottom - (Rect)->Top + 1))
33#define ConioRectWidth(Rect) \
34 (((Rect)->Left > (Rect)->Right) ? 0 : ((Rect)->Right - (Rect)->Left + 1))
35
36
37static __inline BOOLEAN
39 IN PSMALL_RECT Rect1,
40 IN PSMALL_RECT Rect2)
41{
42 if ( ConioIsRectEmpty(Rect1) ||
43 ConioIsRectEmpty(Rect2) ||
44 (Rect1->Top > Rect2->Bottom) ||
45 (Rect1->Left > Rect2->Right) ||
46 (Rect1->Bottom < Rect2->Top) ||
47 (Rect1->Right < Rect2->Left) )
48 {
49 /* The rectangles do not intersect */
50 ConioInitRect(Intersection, 0, -1, 0, -1);
51 return FALSE;
52 }
53
54 ConioInitRect(Intersection,
55 max(Rect1->Top , Rect2->Top ),
56 max(Rect1->Left , Rect2->Left ),
57 min(Rect1->Bottom, Rect2->Bottom),
58 min(Rect1->Right , Rect2->Right ));
59
60 return TRUE;
61}
62
63static __inline BOOLEAN
65 IN PSMALL_RECT Rect1,
66 IN PSMALL_RECT Rect2)
67{
68 if (ConioIsRectEmpty(Rect1))
69 {
70 if (ConioIsRectEmpty(Rect2))
71 {
72 ConioInitRect(Union, 0, -1, 0, -1);
73 return FALSE;
74 }
75 else
76 {
77 *Union = *Rect2;
78 }
79 }
80 else if (ConioIsRectEmpty(Rect2))
81 {
82 *Union = *Rect1;
83 }
84 else
85 {
86 ConioInitRect(Union,
87 min(Rect1->Top , Rect2->Top ),
88 min(Rect1->Left , Rect2->Left ),
89 max(Rect1->Bottom, Rect2->Bottom),
90 max(Rect1->Right , Rect2->Right ));
91 }
92
93 return TRUE;
94}
unsigned char BOOLEAN
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define min(a, b)
Definition: monoChain.cc:55
#define max(a, b)
Definition: svc.c:63
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
static __inline BOOLEAN ConioGetIntersection(OUT PSMALL_RECT Intersection, IN PSMALL_RECT Rect1, IN PSMALL_RECT Rect2)
Definition: rect.h:38
#define ConioInitRect(Rect, top, left, bottom, right)
Definition: rect.h:20
#define ConioIsRectEmpty(Rect)
Definition: rect.h:28
static __inline BOOLEAN ConioGetUnion(OUT PSMALL_RECT Union, IN PSMALL_RECT Rect1, IN PSMALL_RECT Rect2)
Definition: rect.h:64