#pragma once

#include "vector2d.h"

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

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
	{
		return ((bottomLeft.x > topRight.x) || (bottomLeft.y > topRight.y));
	}


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

	Logical TestInstance() const;

	static Logical TestClass();
};