Share ellipse reading code between Shape.Ellipse and Path.Ellipse.

This commit is contained in:
Jürg Lehni 2013-10-29 21:15:28 +01:00
parent aca9968164
commit fd96447ac1
2 changed files with 16 additions and 17 deletions

View file

@ -480,18 +480,26 @@ statics: new function() {
* }); * });
*/ */
Ellipse: function(/* rectangle */) { 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, var center,
radius; radius;
if (Base.hasNamed(arguments, 'radius')) { if (Base.hasNamed(args, 'radius')) {
center = Point.readNamed(arguments, 'center'); center = Point.readNamed(args, 'center');
radius = Size.readNamed(arguments, 'radius'); radius = Size.readNamed(args, 'radius');
} else { } else {
var rect = Rectangle.readNamed(arguments, 'rectangle'); var rect = Rectangle.readNamed(args, 'rectangle');
center = rect.getCenter(true); center = rect.getCenter(true);
radius = rect.getSize(true).divide(2); radius = rect.getSize(true).divide(2);
} }
return createShape('ellipse', center, radius.multiply(2), radius, return { center: center, radius: radius };
arguments);
} }
}; };
}}); }});

View file

@ -282,17 +282,8 @@ Path.inject({ statics: new function() {
* }); * });
*/ */
Ellipse: function(/* rectangle */) { Ellipse: function(/* rectangle */) {
var center, var ellipse = Shape._readEllipse(arguments);
radius; return createEllipse(ellipse.center, ellipse.radius, arguments);
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);
}, },
/** /**