2 * Rectangle-related functions
4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
11 #define MIN(a,b) ((a) < (b) ? (a) : (b))
12 #define MAX(a,b) ((a) > (b) ? (a) : (b))
15 /***********************************************************************
18 void SetRect( LPRECT rect
, short left
, short top
, short right
, short bottom
)
23 rect
->bottom
= bottom
;
27 /***********************************************************************
28 * SetRectEmpty (USER.73)
30 void SetRectEmpty( LPRECT rect
)
32 rect
->left
= rect
->right
= rect
->top
= rect
->bottom
= 0;
36 /***********************************************************************
39 void CopyRect( LPRECT dest
, LPRECT src
)
45 /***********************************************************************
46 * IsRectEmpty (USER.75)
48 BOOL
IsRectEmpty( LPRECT rect
)
50 return ((rect
->left
== rect
->right
) || (rect
->top
== rect
->bottom
));
54 /***********************************************************************
57 BOOL
PtInRect( LPRECT rect
, POINT pt
)
59 return ((pt
.x
>= rect
->left
) && (pt
.x
< rect
->right
) &&
60 (pt
.y
>= rect
->top
) && (pt
.y
< rect
->bottom
));
64 /***********************************************************************
65 * OffsetRect (USER.77)
67 void OffsetRect( LPRECT rect
, short x
, short y
)
76 /***********************************************************************
77 * InflateRect (USER.78)
79 void InflateRect( LPRECT rect
, short x
, short y
)
88 /***********************************************************************
89 * IntersectRect (USER.79)
91 BOOL
IntersectRect( LPRECT dest
, LPRECT src1
, LPRECT src2
)
93 if (IsRectEmpty(src1
) || IsRectEmpty(src2
) ||
94 (src1
->left
>= src2
->right
) || (src2
->left
>= src1
->right
) ||
95 (src1
->top
>= src2
->bottom
) || (src2
->top
>= src1
->bottom
))
100 dest
->left
= MAX( src1
->left
, src2
->left
);
101 dest
->right
= MIN( src1
->right
, src2
->right
);
102 dest
->top
= MAX( src1
->top
, src2
->top
);
103 dest
->bottom
= MIN( src1
->bottom
, src2
->bottom
);
108 /***********************************************************************
109 * UnionRect (USER.80)
111 BOOL
UnionRect( LPRECT dest
, LPRECT src1
, LPRECT src2
)
113 if (IsRectEmpty(src1
))
115 if (IsRectEmpty(src2
))
117 SetRectEmpty( dest
);
124 if (IsRectEmpty(src2
)) *dest
= *src1
;
127 dest
->left
= MIN( src1
->left
, src2
->left
);
128 dest
->right
= MAX( src1
->right
, src2
->right
);
129 dest
->top
= MIN( src1
->top
, src2
->top
);
130 dest
->bottom
= MAX( src1
->bottom
, src2
->bottom
);
137 /***********************************************************************
138 * EqualRect (USER.244)
140 BOOL
EqualRect( LPRECT rect1
, LPRECT rect2
)
142 return ((rect1
->left
== rect2
->left
) && (rect1
->right
== rect2
->right
) &&
143 (rect1
->top
== rect2
->top
) && (rect1
->bottom
== rect2
->bottom
));
147 /***********************************************************************
148 * SubtractRect (USER.373)
150 BOOL
SubtractRect( LPRECT dest
, LPRECT src1
, LPRECT src2
)
154 if (IsRectEmpty( src1
))
156 SetRectEmpty( dest
);
160 if (IntersectRect( &tmp
, src1
, src2
))
162 if (EqualRect( &tmp
, dest
))
164 SetRectEmpty( dest
);
167 if ((tmp
.top
== dest
->top
) && (tmp
.bottom
== dest
->bottom
))
169 if (tmp
.left
== dest
->left
) dest
->left
= tmp
.right
;
170 else if (tmp
.right
== dest
->right
) dest
->right
= tmp
.left
;
172 else if ((tmp
.left
== dest
->left
) && (tmp
.right
== dest
->right
))
174 if (tmp
.top
== dest
->top
) dest
->top
= tmp
.bottom
;
175 else if (tmp
.bottom
== dest
->bottom
) dest
->bottom
= tmp
.top
;