mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -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 */) {
|
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);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}});
|
}});
|
||||||
|
|
|
@ -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);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue