mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-04 17:00:28 -04:00
Fully support object literal arguments in Shape constructors.
This commit is contained in:
parent
95ecab8a6f
commit
5250281ab1
1 changed files with 29 additions and 16 deletions
|
@ -44,6 +44,7 @@ var Shape = Item.extend(/** @lends Shape# */{
|
||||||
ctx.arc(0, 0, (width + height) / 4, 0, Math.PI * 2, true);
|
ctx.arc(0, 0, (width + height) / 4, 0, Math.PI * 2, true);
|
||||||
break;
|
break;
|
||||||
case 'ellipse':
|
case 'ellipse':
|
||||||
|
// Use four bezier curves and KAPPA value to aproximate ellipse
|
||||||
var mx = width / 2,
|
var mx = width / 2,
|
||||||
my = height / 2,
|
my = height / 2,
|
||||||
kappa = Numerical.KAPPA,
|
kappa = Numerical.KAPPA,
|
||||||
|
@ -86,22 +87,34 @@ var Shape = Item.extend(/** @lends Shape# */{
|
||||||
return _hitTest.base.apply(this, arguments);
|
return _hitTest.base.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: new function() {
|
||||||
Circle: function(/* center, radius */) {
|
function createShape(type, point, size, args) {
|
||||||
var center = Point.readNamed(arguments, 'center'),
|
var shape = new Shape(type, point, size),
|
||||||
radius = Base.readNamed(arguments, 'radius');
|
named = Base.getNamed(args);
|
||||||
return new Shape('circle', center, new Size(radius * 2));
|
if (named)
|
||||||
},
|
shape._set(named);
|
||||||
|
return shape;
|
||||||
Rectangle: function(/* rectangle */) {
|
|
||||||
var rect = Rectangle.readNamed(arguments, 'rectangle');
|
|
||||||
return new Shape('rect', rect.getCenter(true), rect.getSize(true));
|
|
||||||
},
|
|
||||||
|
|
||||||
Ellipse: function(/* rectangle */) {
|
|
||||||
var rect = Rectangle.readNamed(arguments, 'rectangle');
|
|
||||||
return new Shape('ellipse', rect.getCenter(true),
|
|
||||||
rect.getSize(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
Circle: function(/* center, radius */) {
|
||||||
|
var center = Point.readNamed(arguments, 'center'),
|
||||||
|
radius = Base.readNamed(arguments, 'radius');
|
||||||
|
return createShape('circle', center, new Size(radius * 2),
|
||||||
|
arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
Rectangle: function(/* rectangle */) {
|
||||||
|
var rect = Rectangle.readNamed(arguments, 'rectangle');
|
||||||
|
return createShape('rect', rect.getCenter(true),
|
||||||
|
rect.getSize(true), arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
Ellipse: function(/* rectangle */) {
|
||||||
|
var rect = Rectangle.readNamed(arguments, 'rectangle');
|
||||||
|
return createShape('ellipse', rect.getCenter(true),
|
||||||
|
rect.getSize(true), arguments);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue