//===========================================================================//
// File:	Rect2D.hh                                                           //
// Project: MUNGA           Brick: Math Library                              //
// Contents: Interface specification for two-dimensional rectangle class     //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
//  2/01/95  CPB  Initial coding (started from Vector2D.hh)                  //
//---------------------------------------------------------------------------//
// Copyright (C) 1995, Virtual World Entertainment, Inc. All rights reserved //
//                      PROPRIETARY and CONFIDENTIAL                         //
//===========================================================================//

#if !defined(RECT2D_HPP)
#	define RECT2D_HPP

#	if !defined(VECTOR2D_HPP)
#		include <vector2d.hpp>
#	endif

	// Note that the coordinate system used here is such that
   // (0,0) is in the lower left corner.

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Rectangle2D ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	class Rectangle2D SIGNATURED
	{
	 public:
		Vector2DOf<int> bottomLeft, topRight;

		Rectangle2D();
		Rectangle2D(Vector2DOf<int> bl, Vector2DOf<int> tr);
		Rectangle2D(int x1, int y1, int x2, int y2);
		~Rectangle2D()
      	{}

		Logical
			operator==(const Rectangle2D& r) const
				{return ((bottomLeft == r.bottomLeft) && (topRight == r.topRight));}
		Logical
			operator!=(const Rectangle2D& r) const
				{return ((bottomLeft != r.bottomLeft) || (topRight != r.topRight));}

		void
			Union(
				const Rectangle2D& r1,
				const Rectangle2D& r2
			);

		void
			Intersection(
				const Rectangle2D& r1,
				const Rectangle2D& r2
			);

		void
			MakeEmpty()
				{
					Check(this);
					bottomLeft.x =  1;
					topRight.x =  0;
				}

		Logical
			IsEmpty() const
				{
					if ((bottomLeft.x > topRight.x) || (bottomLeft.y > topRight.y))
					{
						return True;
					}
					else
					{
						return False;
					}
				}


		friend ostream&
			operator<<(
				ostream& stream,
				const Rectangle2D& r
			);

		Logical
			TestInstance() const;

		static Logical
      	TestClass();
	};
#endif
