mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Optimise Path.Rectangle constructor.
This commit is contained in:
parent
3c5a46a8af
commit
8f8188a091
1 changed files with 11 additions and 7 deletions
|
@ -95,13 +95,17 @@ Path.inject({ statics: new function() {
|
|||
*/
|
||||
Rectangle: function(rect) {
|
||||
rect = Rectangle.read(arguments);
|
||||
var path = new Path(),
|
||||
corners = ['getBottomLeft', 'getTopLeft', 'getTopRight',
|
||||
'getBottomRight'],
|
||||
segments = new Array(4);
|
||||
for (var i = 0; i < 4; i++)
|
||||
segments[i] = new Segment(rect[corners[i]]());
|
||||
path._add(segments);
|
||||
var left = rect.x,
|
||||
top = rect.y
|
||||
right = left + rect.width,
|
||||
bottom = top + rect.height,
|
||||
path = new Path();
|
||||
path._add([
|
||||
new Segment(Point.create(left, bottom)),
|
||||
new Segment(Point.create(left, top)),
|
||||
new Segment(Point.create(right, top)),
|
||||
new Segment(Point.create(right, bottom))
|
||||
]);
|
||||
path._closed = true;
|
||||
return path;
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue