revert between 56095 -> 55830 in arch
[AROS.git] / compiler / alib / andrectrect.c
blobff733d005138c9fa113301064f1509584dc84414
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function AndRectRect()
6 Lang: english
7 */
9 #include <graphics/gfx.h>
10 #include <clib/macros.h>
12 /*****************************************************************************
14 NAME */
15 #include <proto/alib.h>
17 BOOL AndRectRect(
19 /* SYNOPSIS */
20 struct Rectangle *rect1,
21 struct Rectangle *rect2,
22 struct Rectangle *intersect)
24 /* FUNCTION
25 Calculate the intersection rectangle between the
26 given Rectangle rect1 and the given Rectangle rect2
27 leaving the result in intersect (if intersect != NULL).
29 INPUTS
30 rect1 - pointer to 1st Rectangle
31 rect2 - pointer to 2nd Rectangle
32 intersect - pointer to rectangle which will hold result.
34 RESULT
35 TRUE if rect1 and rect2 do intersect. In this case intersect
36 will contain the intersection rectangle.
38 FALSE if rect1 and rect2 do not overlap. "intersect" will
39 then be left unchanged.
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
49 INTERNALS
51 HISTORY
52 15-12-2000 stegerg implemented
54 *****************************************************************************/
56 WORD MinX = MAX(rect1->MinX, rect2->MinX);
57 WORD MinY = MAX(rect1->MinY, rect2->MinY);
58 WORD MaxX = MIN(rect1->MaxX, rect2->MaxX);
59 WORD MaxY = MIN(rect1->MaxY, rect2->MaxY);
61 if ((MinX > MaxX) || (MinY > MaxY))
62 return FALSE;
63 else
65 if (intersect) {
66 intersect->MinX = MinX;
67 intersect->MinY = MinY;
68 intersect->MaxX = MaxX;
69 intersect->MaxY = MaxY;
72 return TRUE;
74 } /* AndRectRect */