/*********************************************************************
 * This file is part of the PRAPI library.
 *
 * Copyright (C) 2002 Topi Mäenpää
 * All rights reserved.
 *
 * This program is free software. You can redistribute and/or modify
 * it under the terms of the free software licence found in the
 * accompanying file "COPYING". The licence terms must always be
 * redistributed with this source file. The above copyright notice
 * must be reproduced in all modified and unmodified copies of this
 * source file.
 *
 * $Revision: 1.1.1.1 $
 *********************************************************************/

#ifndef _SHAPE_H
#define _SHAPE_H

#include "Dimension.h"

namespace prapi { namespace graphics {

	/**
	 * Shape is a superclass for all forms of geometric shapes.
	 **/
	class Shape : virtual public util::Object
	{
	public:
		/**
		 * Return true if (and only if) the given coordinates lie within
		 * or on the boundaries of the shape.
		 **/
		virtual bool contains(double x, double y) const = 0;
	};

	/**
	 * Rectagle is a specialization of Shape for rectangular objects.
	 **/
	template <class T> class Rectangle : public Shape
	{
	public:
		/**
		 * Create a new Rectangle with the given upper left corner
		 * coordinates, width, and height.
		 **/
		Rectangle(T startX=0, T startY=0, T w=0, T h=0) :
			x(startX), y(startY), width(w), height(h) {}

		/**
		 * Create a new Rectangle with the upper left corner coordinates
		 * set to zero and width and height set according to the given
		 * Dimension object.
		 **/
		Rectangle(Dimension<T> dimension) :
			x(0), y(0), width(dimension.x), height(dimension.y) {}
		
		bool contains(double xc, double yc) const { return xc >= x && xc < x+width && yc >= y && yc < y+height; }

		/**
		 * The x coordinate of the upper left corner of the rectangle.
		 **/
		T x;
		/**
		 * The y coordinate of the upper left corner of the rectangle.
		 **/
		T y;
		/**
		 * The width of the rectangle.
		 **/
		T width;
		/**
		 * The height of the rectangle.
		 **/
		T height;
	};
}}

#endif
