From 8f8188a0912298d2f413a18b0905b906dc27e729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 16 Aug 2011 13:39:37 +0200 Subject: [PATCH] Optimise Path.Rectangle constructor. --- src/path/Path.Constructors.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/path/Path.Constructors.js b/src/path/Path.Constructors.js index 47241fef..2b4fde2c 100644 --- a/src/path/Path.Constructors.js +++ b/src/path/Path.Constructors.js @@ -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; },