mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Use center and radius in all ellipse code, rather than bounding rect.
Simplifies things.
This commit is contained in:
parent
fc9cad009f
commit
c3aed5277d
2 changed files with 20 additions and 25 deletions
|
@ -436,19 +436,17 @@ statics: new function() {
|
|||
*/
|
||||
Ellipse: function(/* rectangle */) {
|
||||
var center,
|
||||
size,
|
||||
radius;
|
||||
if (Base.hasNamed(arguments, 'center')) {
|
||||
center = Point.readNamed(arguments, 'center');
|
||||
radius = Size.readNamed(arguments, 'radius');
|
||||
size = radius.multiply(2);
|
||||
} else {
|
||||
var rect = Rectangle.readNamed(arguments, 'rectangle');
|
||||
center = rect.getCenter(true);
|
||||
size = rect.getSize(true);
|
||||
radius = size.divide(2);
|
||||
radius = rect.getSize(true).divide(2);
|
||||
}
|
||||
return createShape('ellipse', center, size, radius, arguments);
|
||||
return createShape('ellipse', center, radius.multiply(2), radius,
|
||||
arguments);
|
||||
}
|
||||
};
|
||||
}});
|
||||
|
|
|
@ -13,25 +13,22 @@
|
|||
Path.inject({ statics: new function() {
|
||||
|
||||
var kappa = Numerical.KAPPA,
|
||||
halfKappa = kappa / 2,
|
||||
ellipseSegments = [
|
||||
new Segment([0, 0.5], [0, halfKappa ], [0, -halfKappa]),
|
||||
new Segment([0.5, 0], [-halfKappa, 0], [halfKappa, 0 ]),
|
||||
new Segment([1, 0.5], [0, -halfKappa], [0, halfKappa ]),
|
||||
new Segment([0.5, 1], [halfKappa, 0 ], [-halfKappa, 0])
|
||||
new Segment([-1, 0], [0, kappa ], [0, -kappa]),
|
||||
new Segment([0, -1], [-kappa, 0], [kappa, 0 ]),
|
||||
new Segment([1, 0], [0, -kappa], [0, kappa ]),
|
||||
new Segment([0, 1], [kappa, 0 ], [-kappa, 0])
|
||||
];
|
||||
|
||||
function createEllipse(rect, args) {
|
||||
function createEllipse(center, radius, args) {
|
||||
var path = new Path(),
|
||||
point = rect.getPoint(true),
|
||||
size = rect.getSize(true),
|
||||
segments = new Array(4);
|
||||
for (var i = 0; i < 4; i++) {
|
||||
var segment = ellipseSegments[i];
|
||||
segments[i] = new Segment(
|
||||
segment._point.multiply(size).add(point),
|
||||
segment._handleIn.multiply(size),
|
||||
segment._handleOut.multiply(size)
|
||||
segment._point.multiply(radius).add(center),
|
||||
segment._handleIn.multiply(radius),
|
||||
segment._handleOut.multiply(radius)
|
||||
);
|
||||
}
|
||||
path._add(segments);
|
||||
|
@ -113,8 +110,7 @@ Path.inject({ statics: new function() {
|
|||
Circle: function(/* center, radius */) {
|
||||
var center = Point.readNamed(arguments, 'center'),
|
||||
radius = Base.readNamed(arguments, 'radius');
|
||||
return createEllipse(new Rectangle(center.subtract(radius),
|
||||
new Size(radius * 2, radius * 2)), arguments);
|
||||
return createEllipse(center, new Size(radius), arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -286,16 +282,17 @@ Path.inject({ statics: new function() {
|
|||
* });
|
||||
*/
|
||||
Ellipse: function(/* rectangle */) {
|
||||
var rect;
|
||||
var center,
|
||||
radius;
|
||||
if (Base.hasNamed(arguments, 'center')) {
|
||||
var center = Point.readNamed(arguments, 'center'),
|
||||
radius = Size.readNamed(arguments, 'radius');
|
||||
rect = new Rectangle(center.subtract(radius),
|
||||
center.add(radius));
|
||||
center = Point.readNamed(arguments, 'center');
|
||||
radius = Size.readNamed(arguments, 'radius');
|
||||
} else {
|
||||
rect = Rectangle.readNamed(arguments, 'rectangle');
|
||||
var rect = Rectangle.readNamed(arguments, 'rectangle');
|
||||
center = rect.getCenter(true);
|
||||
radius = rect.getSize(true).divide(2);
|
||||
}
|
||||
return createEllipse(rect, arguments);
|
||||
return createEllipse(center, radius, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue