mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Various simplificiations and clean-ups in Path constructors.
This commit is contained in:
parent
deb78b78cf
commit
90b94a8d83
1 changed files with 27 additions and 27 deletions
|
@ -22,44 +22,44 @@ Path.inject({ statics: new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
Rectangle: function() {
|
Rectangle: function() {
|
||||||
var path = new Path();
|
var path = new Path(),
|
||||||
path.closed = true;
|
rectangle = Rectangle.read(arguments),
|
||||||
var rectangle = Rectangle.read(arguments);
|
corners = ['getBottomLeft', 'getTopLeft', 'getTopRight',
|
||||||
var corners = ['bottomLeft', 'topLeft', 'topRight',
|
'getBottomRight'];
|
||||||
'bottomRight'];
|
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
path.add(rectangle[corners[i]]);
|
path.add(rectangle[corners[i]]());
|
||||||
}
|
}
|
||||||
|
path.closed = true;
|
||||||
return path;
|
return path;
|
||||||
},
|
},
|
||||||
|
|
||||||
RoundRectangle: function() {
|
RoundRectangle: function() {
|
||||||
var path = new Path();
|
var path = new Path(),
|
||||||
var rect, size;
|
rect, size;
|
||||||
if (arguments.length == 2) {
|
if (arguments.length == 2) {
|
||||||
rect = new Rectangle(arguments[0]);
|
rect = Rectangle.read(arguments, 0, 1);
|
||||||
size = new Size(arguments[1]);
|
size = Size.read(arguments, 1, 1);
|
||||||
} else {
|
} else if (arguments.length == 6) {
|
||||||
rect = new Rectangle(arguments[0], arguments[1],
|
rect = Rectangle.read(arguments, 0, 4);
|
||||||
arguments[2], arguments[3]);
|
size = Size.read(arguments, 4, 2);
|
||||||
size = new Size(arguments[4], arguments[5]);
|
|
||||||
}
|
}
|
||||||
size = Size.min(size, rect.getSize().divide(2));
|
size = Size.min(size, rect.getSize().divide(2));
|
||||||
uSize = size.multiply(kappa * 2);
|
var uSize = size.multiply(kappa * 2),
|
||||||
|
|
||||||
|
bl = rect.getBottomLeft(),
|
||||||
|
tl = rect.getTopLeft(),
|
||||||
|
tr = rect.getTopRight(),
|
||||||
|
br = rect.getBottomRight();
|
||||||
|
|
||||||
var bl = rect.getBottomLeft();
|
|
||||||
path.add(bl.add(size.width, 0), null, [-uSize.width, 0]);
|
path.add(bl.add(size.width, 0), null, [-uSize.width, 0]);
|
||||||
path.add(bl.subtract(0, size.height), [0, uSize.height], null);
|
path.add(bl.subtract(0, size.height), [0, uSize.height], null);
|
||||||
|
|
||||||
var tl = rect.getTopLeft();
|
|
||||||
path.add(tl.add(0, size.height), null, [0, -uSize.height]);
|
path.add(tl.add(0, size.height), null, [0, -uSize.height]);
|
||||||
path.add(tl.add(size.width, 0), [-uSize.width, 0], null);
|
path.add(tl.add(size.width, 0), [-uSize.width, 0], null);
|
||||||
|
|
||||||
var tr = rect.getTopRight();
|
|
||||||
path.add(tr.subtract(size.width, 0), null, [uSize.width, 0]);
|
path.add(tr.subtract(size.width, 0), null, [uSize.width, 0]);
|
||||||
path.add(tr.add(0, size.height), [0, -uSize.height], null);
|
path.add(tr.add(0, size.height), [0, -uSize.height], null);
|
||||||
|
|
||||||
var br = rect.getBottomRight();
|
|
||||||
path.add(br.subtract(0, size.height), null, [0, uSize.height]);
|
path.add(br.subtract(0, size.height), null, [0, uSize.height]);
|
||||||
path.add(br.subtract(size.width, 0), [uSize.width, 0], null);
|
path.add(br.subtract(size.width, 0), [uSize.width, 0], null);
|
||||||
|
|
||||||
|
@ -68,10 +68,10 @@ Path.inject({ statics: new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
Oval: function() {
|
Oval: function() {
|
||||||
var path = new Path();
|
var path = new Path(),
|
||||||
var rect = Rectangle.read(arguments);
|
rect = Rectangle.read(arguments),
|
||||||
var topLeft = rect.getTopLeft();
|
topLeft = rect.getTopLeft(),
|
||||||
var size = new Size(rect.width, rect.height);
|
size = new Size(rect.width, rect.height);
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
var segment = ovalSegments[i];
|
var segment = ovalSegments[i];
|
||||||
path._add(new Segment(
|
path._add(new Segment(
|
||||||
|
@ -106,10 +106,10 @@ Path.inject({ statics: new function() {
|
||||||
|
|
||||||
RegularPolygon: function(center, numSides, radius) {
|
RegularPolygon: function(center, numSides, radius) {
|
||||||
center = new Point(center);
|
center = new Point(center);
|
||||||
var path = new Path();
|
var path = new Path(),
|
||||||
var three = !(numSides % 3);
|
three = !(numSides % 3),
|
||||||
var vector = new Point(0, three ? -radius : radius);
|
vector = new Point(0, three ? -radius : radius),
|
||||||
var offset = three ? -1 : 0.5;
|
offset = three ? -1 : 0.5;
|
||||||
for (var i = 0; i < numSides; i++) {
|
for (var i = 0; i < numSides; i++) {
|
||||||
var angle = (360 / numSides) * (i + offset);
|
var angle = (360 / numSides) * (i + offset);
|
||||||
path.add(center.add(vector.rotate(angle)));
|
path.add(center.add(vector.rotate(angle)));
|
||||||
|
|
Loading…
Reference in a new issue