Undo previous compressing of Rectangle functions.

This commit is contained in:
Jonathan Puckey 2011-04-28 15:44:05 +02:00
parent 3916db4eb8
commit 4b4e092f90

View file

@ -193,6 +193,33 @@ var Rectangle = this.Rectangle = Base.extend({
&& rect.y < this.y + this.height;
},
intersect: function(rect) {
rect = Rectangle.read(arguments);
var x1 = Math.max(this.x, rect.x),
y1 = Math.max(this.y, rect.y),
x2 = Math.min(this.x + this.width, rect.x + rect.width),
y2 = Math.min(this.y + this.height, rect.y + rect.height);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
},
unite: function(rect) {
rect = Rectangle.read(arguments);
var x1 = Math.min(this.x, rect.x),
y1 = Math.min(this.y, rect.y),
x2 = Math.max(this.x + this.width, rect.x + rect.width),
y2 = Math.max(this.y + this.height, rect.y + rect.height);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
},
include: function(point) {
point = Point.read(arguments);
var x1 = Math.min(this.x, point.x),
y1 = Math.min(this.y, point.y),
x2 = Math.max(this.x + this.width, point.x),
y2 = Math.max(this.y + this.height, point.y);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
},
toString: function() {
return '{ x: ' + this.x
+ ', y: ' + this.y
@ -207,28 +234,6 @@ var Rectangle = this.Rectangle = Base.extend({
return new Rectangle(Rectangle.dont).set(x, y, width, height);
}
}
}, new function() { // Scope for injecting intersect, unite and include.
return Base.each({
// 1st = intersect, 2nd = isPoint
intersect: [true, false],
unite: [false, false],
include: [false, true]
}, function(values, name) {
var intersect = values[0],
isPoint = values[1],
op1 = Math[intersect ? 'max' : 'min'],
op2 = Math[intersect ? 'min' : 'max'];
this[name] = function() {
var object = (isPoint ? Point : Rectangle).read(arguments),
x1 = op1(this.x, object.x),
y1 = op1(this.y, object.y),
x2 = op2(this.x + this.width,
object.x + (isPoint ? 0 : object.width)),
y2 = op2(this.y + this.height,
object.y + (isPoint ? 0 : object.height));
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
};
}, {});
}, new function() {
return Base.each([
['Top', 'Left'], ['Top', 'Right'],