mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Share ellipse reading code between Shape.Ellipse and Path.Ellipse.
This commit is contained in:
parent
aca9968164
commit
fd96447ac1
2 changed files with 16 additions and 17 deletions
|
@ -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 };
|
||||
}
|
||||
};
|
||||
}});
|
||||
|
|
|
@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue