From fd96447ac137807791bc0ceba17f4d7429cffe0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 29 Oct 2013 21:15:28 +0100 Subject: [PATCH] Share ellipse reading code between Shape.Ellipse and Path.Ellipse. --- src/item/Shape.js | 20 ++++++++++++++------ src/path/Path.Constructors.js | 13 ++----------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/item/Shape.js b/src/item/Shape.js index 9fe3936e..81e71de6 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -480,18 +480,26 @@ statics: new function() { * }); */ Ellipse: function(/* rectangle */) { + var ellipse = Shape._readEllipse(arguments); + radius = ellipse.radius; + return createShape('ellipse', ellipse.center, radius.multiply(2), + radius, arguments); + }, + + // Private method to read ellipse center and radius from arguments list, + // shared with Path.Ellipse constructor. + _readEllipse: function(args) { var center, radius; - if (Base.hasNamed(arguments, 'radius')) { - center = Point.readNamed(arguments, 'center'); - radius = Size.readNamed(arguments, 'radius'); + if (Base.hasNamed(args, 'radius')) { + center = Point.readNamed(args, 'center'); + radius = Size.readNamed(args, 'radius'); } else { - var rect = Rectangle.readNamed(arguments, 'rectangle'); + var rect = Rectangle.readNamed(args, 'rectangle'); center = rect.getCenter(true); radius = rect.getSize(true).divide(2); } - return createShape('ellipse', center, radius.multiply(2), radius, - arguments); + return { center: center, radius: radius }; } }; }}); diff --git a/src/path/Path.Constructors.js b/src/path/Path.Constructors.js index c20be35f..004f4b71 100644 --- a/src/path/Path.Constructors.js +++ b/src/path/Path.Constructors.js @@ -282,17 +282,8 @@ Path.inject({ statics: new function() { * }); */ Ellipse: function(/* rectangle */) { - var center, - radius; - if (Base.hasNamed(arguments, 'radius')) { - center = Point.readNamed(arguments, 'center'); - radius = Size.readNamed(arguments, 'radius'); - } else { - var rect = Rectangle.readNamed(arguments, 'rectangle'); - center = rect.getCenter(true); - radius = rect.getSize(true).divide(2); - } - return createEllipse(center, radius, arguments); + var ellipse = Shape._readEllipse(arguments); + return createEllipse(ellipse.center, ellipse.radius, arguments); }, /**