/***************************************************************************
	Rectangle - Rectangle object.
	
	A rectangle in 2D Cartesian space.
	
	Version:
		v0.1, Monday, July 08, 2002
	
	Requires:
		Point v0.1
		
	Author:
		Alexander Whillas

	Copyright (C) 2002 Taylor Square Designs
***************************************************************************/

// Constructor
function Rectangle (p_top, p_left, p_width, p_height) {
	this.topleft = new Point(p_left, p_top);
	this.width = p_width || 0;
	this.height = p_height || 0;
	
	return this;
}

// Assignmen operator.
Rectangle.prototype.setEqualTo = function (p_rectangle) {
	this.topleft.setEqualTo(p_rectangle.topleft);
	this.width = p_rectangle.width;
	this.height = p_rectangle.height;
	
	return true;
}

// Comparison operator. Compare this object to the passed one.
Rectangle.prototype.isEqualTo = function (p_rectangle) {
	return (this.topleft.isEqualTo(p_rectangle.topleft) && this.width == p_rectangle.width && this.height == p_rectangle.height) ? true : false;
}

// The distance in pixes apart from this Rectangels topleft to the given Point.
Rectangle.prototype.distanceTo = function (p_point) {
	return this.topleft.distanceTo(p_point);
}

// Returns a Point object that is at the center of the Rectangles current position and size.
Rectangle.prototype.centerPoint = function () {
	return new Point(this.topleft.getX() + this.width / 2, this.topleft.getY() + this.height / 2);
}

Rectangle.prototype.toString = function () {
	return this.topleft.toString() + " height: " + this.height + " width: " + this.width;
}

Rectangle.prototype.moveTo = function (p_point) {
	this.topleft.setEqualTo(p_point);
}

Rectangle.prototype.moveBy = function (p_x, p_y) {
	this.topleft.moveBy(p_x, p_y);
}

Rectangle.prototype.getX = function () {
	return this.topleft.getX();
}

Rectangle.prototype.getY = function () {
	return this.topleft.getY();
}