* ============================================================================ *
*	UnionRect: Calculate a rectangle which surround two others
*
*	struct IBox *UnionRect(struct IBox *a, struct IBox *b, struct IBox *result);
*                              a0              a1                   a2
* ============================================================================ *

			include		'intuition/intuition.i'

			SECTION		unionrect.asm,CODE

			xdef		_UnionRect
_UnionRect:			; (a0, a1, a2)

;	x1 = MIN(a->Left, b->Left);

			move.w		ibox_Left(a0),d0
			move.w		ibox_Left(a1),d1
			move.w		d0,ibox_Left(a2)
			cmp.w		d0,d1
			bgt.s		1$
			move.w		d1,ibox_Left(a2)
1$

;	x2 = MAX(a->Left + a->Width, b->Left + b->Width) - x1;

			add.w		ibox_Width(a0),d0
			add.w		ibox_Width(a1),d1
			cmp.w		d0,d1
			blt.s		2$
			move.w		d1,d0
2$			sub.w		ibox_Left(a2),d0
			move.w		d0,ibox_Width(a2)

;	y1 = MIN(a->Top, b->Top);

			move.w		ibox_Top(a0),d0
			move.w		ibox_Top(a1),d1
			move.w		d0,ibox_Top(a2)
			cmp.w		d0,d1
			bgt.s		3$
			move.w		d1,ibox_Top(a2)
3$
;	y2 = MAX(a->Top + a->Height, b->Top + b->Height) - y1;

			add.w		ibox_Height(a0),d0
			add.w		ibox_Height(a1),d1
			cmp.w		d0,d1
			blt.s		4$
			move.w		d1,d0
4$			sub.w		ibox_Top(a2),d0
			move.w		d0,ibox_Height(a2)
			
			move.l		a2,d0					; return address of result

			rts
