Optimise Path.Rectangle constructor.

This commit is contained in:
Jürg Lehni 2011-08-16 13:39:37 +02:00
parent 3c5a46a8af
commit 8f8188a091

View file

@ -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;
},