
// übernommen und geändert von J. Strübig
// http://javascript.jstruebig.de/bibliotheken/rectjs/

red.prototype.rect = {
	
	create : function(left, top, width, height){
		var rect = new Object();
		rect.left 		= left;
		rect.top 		= top;
		rect.width 		= width;
		rect.height 	= height;
		rect.right 		= left+width;
		rect.bottom		= top+height;
								
		return rect;
	},
	
	/* holt sich die maße direkt vom element */
	
	get : function(elem){
		var xy 		= red.prototype.css.getxy(elem);
		var size 	= red.prototype.css.getsizexy(elem);
		var rect 	= red.prototype.rect.create(xy[0],xy[1],size[0],size[1]);
		
		return rect;
	},
	
	touch : function(rect1,rect2){
		return (rect2.bottom > rect1.top && rect2.top < rect1.bottom)&&
		(rect2.right > rect1.left && rect2.left < rect1.right);
	},
	
	/* zuerst das innere */
	
	isin : function(rect1,rect2){	
		return (rect2.bottom >= rect1.bottom && rect2.right >= rect1.right)&&
		(rect2.left <= rect1.left && rect2.top <= rect1.top);
	},
	
	xyin : function(xy,rect){
		return (xy[1] > rect.top && xy[1] < rect.bottom)&&
		(xy[0] > rect.left && xy[0] < rect.right);
	}

}