2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
11 /***********************************************************************
14 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
15 INT16 right, INT16 bottom )
20 rect->bottom = bottom;
24 /***********************************************************************
25 * SetRect32 (USER32.499)
27 void WINAPI SetRect32( LPRECT32 rect, INT32 left, INT32 top,
28 INT32 right, INT32 bottom )
33 rect->bottom = bottom;
37 /***********************************************************************
38 * SetRectEmpty16 (USER.73)
40 void WINAPI SetRectEmpty16( LPRECT16 rect )
42 rect->left = rect->right = rect->top = rect->bottom = 0;
46 /***********************************************************************
47 * SetRectEmpty32 (USER32.500)
49 void WINAPI SetRectEmpty32( LPRECT32 rect )
51 rect->left = rect->right = rect->top = rect->bottom = 0;
55 /***********************************************************************
56 * CopyRect16 (USER.74)
58 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
65 /***********************************************************************
66 * CopyRect32 (USER32.62)
68 BOOL32 WINAPI CopyRect32( RECT32 *dest, const RECT32 *src )
75 /***********************************************************************
76 * IsRectEmpty16 (USER.75)
78 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
80 return ((rect->left == rect->right) || (rect->top == rect->bottom));
84 /***********************************************************************
85 * IsRectEmpty32 (USER32.347)
87 BOOL32 WINAPI IsRectEmpty32( const RECT32 *rect )
89 return ((rect->left == rect->right) || (rect->top == rect->bottom));
93 /***********************************************************************
94 * PtInRect16 (USER.76)
96 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
98 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
99 (pt.y >= rect->top) && (pt.y < rect->bottom));
103 /***********************************************************************
104 * PtInRect32 (USER32.424)
106 BOOL32 WINAPI PtInRect32( const RECT32 *rect, POINT32 pt )
108 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
109 (pt.y >= rect->top) && (pt.y < rect->bottom));
113 /***********************************************************************
114 * OffsetRect16 (USER.77)
116 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
125 /***********************************************************************
126 * OffsetRect32 (USER32.406)
128 void WINAPI OffsetRect32( LPRECT32 rect, INT32 x, INT32 y )
137 /***********************************************************************
138 * InflateRect16 (USER.78)
140 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
149 /***********************************************************************
150 * InflateRect32 (USER32.321)
152 void WINAPI InflateRect32( LPRECT32 rect, INT32 x, INT32 y )
161 /***********************************************************************
162 * IntersectRect16 (USER.79)
164 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
167 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
168 (src1->left >= src2->right) || (src2->left >= src1->right) ||
169 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
171 SetRectEmpty16( dest );
174 dest->left = MAX( src1->left, src2->left );
175 dest->right = MIN( src1->right, src2->right );
176 dest->top = MAX( src1->top, src2->top );
177 dest->bottom = MIN( src1->bottom, src2->bottom );
182 /***********************************************************************
183 * IntersectRect32 (USER32.327)
185 BOOL32 WINAPI IntersectRect32( LPRECT32 dest, const RECT32 *src1,
188 if (IsRectEmpty32(src1) || IsRectEmpty32(src2) ||
189 (src1->left >= src2->right) || (src2->left >= src1->right) ||
190 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
192 SetRectEmpty32( dest );
195 dest->left = MAX( src1->left, src2->left );
196 dest->right = MIN( src1->right, src2->right );
197 dest->top = MAX( src1->top, src2->top );
198 dest->bottom = MIN( src1->bottom, src2->bottom );
203 /***********************************************************************
204 * UnionRect16 (USER.80)
206 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
209 if (IsRectEmpty16(src1))
211 if (IsRectEmpty16(src2))
213 SetRectEmpty16( dest );
220 if (IsRectEmpty16(src2)) *dest = *src1;
223 dest->left = MIN( src1->left, src2->left );
224 dest->right = MAX( src1->right, src2->right );
225 dest->top = MIN( src1->top, src2->top );
226 dest->bottom = MAX( src1->bottom, src2->bottom );
233 /***********************************************************************
234 * UnionRect32 (USER32.559)
236 BOOL32 WINAPI UnionRect32( LPRECT32 dest, const RECT32 *src1,
239 if (IsRectEmpty32(src1))
241 if (IsRectEmpty32(src2))
243 SetRectEmpty32( dest );
250 if (IsRectEmpty32(src2)) *dest = *src1;
253 dest->left = MIN( src1->left, src2->left );
254 dest->right = MAX( src1->right, src2->right );
255 dest->top = MIN( src1->top, src2->top );
256 dest->bottom = MAX( src1->bottom, src2->bottom );
263 /***********************************************************************
264 * EqualRect16 (USER.244)
266 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
268 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
269 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
273 /***********************************************************************
274 * EqualRect32 (USER32.194)
276 BOOL32 WINAPI EqualRect32( const RECT32* rect1, const RECT32* rect2 )
278 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
279 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
283 /***********************************************************************
284 * SubtractRect16 (USER.373)
286 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
291 if (IsRectEmpty16( src1 ))
293 SetRectEmpty16( dest );
297 if (IntersectRect16( &tmp, src1, src2 ))
299 if (EqualRect16( &tmp, dest ))
301 SetRectEmpty16( dest );
304 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
306 if (tmp.left == dest->left) dest->left = tmp.right;
307 else if (tmp.right == dest->right) dest->right = tmp.left;
309 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
311 if (tmp.top == dest->top) dest->top = tmp.bottom;
312 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
319 /***********************************************************************
320 * SubtractRect32 (USER32.536)
322 BOOL32 WINAPI SubtractRect32( LPRECT32 dest, const RECT32 *src1,
327 if (IsRectEmpty32( src1 ))
329 SetRectEmpty32( dest );
333 if (IntersectRect32( &tmp, src1, src2 ))
335 if (EqualRect32( &tmp, dest ))
337 SetRectEmpty32( dest );
340 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
342 if (tmp.left == dest->left) dest->left = tmp.right;
343 else if (tmp.right == dest->right) dest->right = tmp.left;
345 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
347 if (tmp.top == dest->top) dest->top = tmp.bottom;
348 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;