Define fast Rectangle.create() and use it internally where applicable.

This commit is contained in:
Jürg Lehni 2011-03-06 18:45:56 +00:00
parent 4070f98374
commit deb78b78cf
3 changed files with 17 additions and 5 deletions

View file

@ -255,7 +255,7 @@ var Rectangle = this.Rectangle = Base.extend({
var y1 = Math.max(this.y, rect.y);
var x2 = Math.min(this.x + this.width, rect.x + rect.width);
var y2 = Math.min(this.y + this.height, rect.y + rect.height);
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
},
unite: function() {
@ -264,7 +264,7 @@ var Rectangle = this.Rectangle = Base.extend({
var y1 = Math.min(this.y, rect.y);
var x2 = Math.max(this.x + this.width, rect.x + rect.width);
var y2 = Math.max(this.y + this.height, rect.y + rect.height);
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
},
include: function() {
@ -273,7 +273,7 @@ var Rectangle = this.Rectangle = Base.extend({
var y1 = Math.min(this.y, point.y);
var x2 = Math.max(this.x + this.width, point.x);
var y2 = Math.max(this.y + this.height, point.y);
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
},
toString: function() {
@ -282,5 +282,17 @@ var Rectangle = this.Rectangle = Base.extend({
+ ', width: ' + this.width
+ ', height: ' + this.height
+ ' }';
},
statics: {
// See Point.create()
create: function(x, y, width, height) {
var rect = new Rectangle(Size.dont);
rect.x = x;
rect.y = y;
rect.width = width;
rect.height = height;
return rect;
}
}
});

View file

@ -27,7 +27,7 @@ var Group = this.Group = Item.extend({
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
}
}
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
},
/**

View file

@ -26,7 +26,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
}
}
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
},
/**