mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
Define fast Rectangle.create() and use it internally where applicable.
This commit is contained in:
parent
4070f98374
commit
deb78b78cf
3 changed files with 17 additions and 5 deletions
|
@ -255,7 +255,7 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
var y1 = Math.max(this.y, rect.y);
|
var y1 = Math.max(this.y, rect.y);
|
||||||
var x2 = Math.min(this.x + this.width, rect.x + rect.width);
|
var x2 = Math.min(this.x + this.width, rect.x + rect.width);
|
||||||
var y2 = Math.min(this.y + this.height, rect.y + rect.height);
|
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() {
|
unite: function() {
|
||||||
|
@ -264,7 +264,7 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
var y1 = Math.min(this.y, rect.y);
|
var y1 = Math.min(this.y, rect.y);
|
||||||
var x2 = Math.max(this.x + this.width, rect.x + rect.width);
|
var x2 = Math.max(this.x + this.width, rect.x + rect.width);
|
||||||
var y2 = Math.max(this.y + this.height, rect.y + rect.height);
|
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() {
|
include: function() {
|
||||||
|
@ -273,7 +273,7 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
var y1 = Math.min(this.y, point.y);
|
var y1 = Math.min(this.y, point.y);
|
||||||
var x2 = Math.max(this.x + this.width, point.x);
|
var x2 = Math.max(this.x + this.width, point.x);
|
||||||
var y2 = Math.max(this.y + this.height, point.y);
|
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() {
|
toString: function() {
|
||||||
|
@ -282,5 +282,17 @@ var Rectangle = this.Rectangle = Base.extend({
|
||||||
+ ', width: ' + this.width
|
+ ', width: ' + this.width
|
||||||
+ ', height: ' + this.height
|
+ ', 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ var Group = this.Group = Item.extend({
|
||||||
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
|
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);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,7 +26,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({
|
||||||
y2 = Math.max(rect2.y + rect2.height, y1 + y2 - y1);
|
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);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue