2011-02-07 13:28:09 -05:00
|
|
|
Path = PathItem.extend({
|
|
|
|
initialize: function() {
|
|
|
|
this.base.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
statics: {
|
2011-02-11 05:49:24 -05:00
|
|
|
Line: Base.extend({
|
2011-02-07 13:28:09 -05:00
|
|
|
initialize: function() {
|
2011-02-11 05:49:24 -05:00
|
|
|
var path = new Path();
|
2011-02-07 13:28:09 -05:00
|
|
|
if(arguments.length == 2) {
|
2011-02-11 05:49:24 -05:00
|
|
|
path.addSegment(new Segment(arguments[0]));
|
|
|
|
path.addSegment(new Segment(arguments[1]));
|
2011-02-07 13:28:09 -05:00
|
|
|
} else if(arguments.length == 4) {
|
2011-02-11 05:49:24 -05:00
|
|
|
path.addSegment(Segment.read(arguments[0], arguments[1]));
|
|
|
|
path.addSegment(Segment.read(arguments[2], arguments[3]));
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
2011-02-11 05:49:24 -05:00
|
|
|
return path;
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2011-02-11 05:49:24 -05:00
|
|
|
Rectangle: Base.extend({
|
2011-02-07 13:28:09 -05:00
|
|
|
initialize: function() {
|
2011-02-11 05:49:24 -05:00
|
|
|
var path = new Path();
|
|
|
|
path.closed = true;
|
2011-02-07 13:28:09 -05:00
|
|
|
var rectangle = Rectangle.read(arguments);
|
2011-02-11 08:41:32 -05:00
|
|
|
var corners = ['bottomLeft', 'topLeft', 'topRight', 'bottomRight'];
|
2011-02-07 13:28:09 -05:00
|
|
|
for(var i = 0; i < 4; i++) {
|
2011-02-11 08:41:32 -05:00
|
|
|
path.add(rectangle[corners[i]]);
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
2011-02-11 05:49:24 -05:00
|
|
|
return path;
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2011-02-11 05:49:24 -05:00
|
|
|
RoundRectangle: Base.extend(new function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var u = 4 / 3 * (Math.sqrt(2) - 1);
|
|
|
|
return {
|
|
|
|
initialize: function() {
|
2011-02-11 05:49:24 -05:00
|
|
|
var path = new Path();
|
2011-02-07 13:28:09 -05:00
|
|
|
var rect, size;
|
|
|
|
if(arguments.length == 2) {
|
|
|
|
rect = new Rectangle(arguments[0]);
|
|
|
|
size = new Size(arguments[1]);
|
|
|
|
} else {
|
|
|
|
rect = new Rectangle(arguments[0], arguments[1],
|
|
|
|
arguments[2], arguments[3]);
|
|
|
|
size = new Size(arguments[4], arguments[5]);
|
|
|
|
}
|
2011-02-11 08:41:32 -05:00
|
|
|
size = Size.min(size, rect.size.divide(2));
|
2011-02-07 13:28:09 -05:00
|
|
|
uSize = size.multiply(u);
|
|
|
|
|
2011-02-11 08:41:32 -05:00
|
|
|
var bl = rect.bottomLeft;
|
2011-02-11 05:49:24 -05:00
|
|
|
path.add(bl.add(size.width, 0), null, [-uSize.width, 0]);
|
|
|
|
path.add(bl.subtract(0, size.height), [0, uSize.height], null);
|
2011-02-07 13:28:09 -05:00
|
|
|
|
2011-02-11 08:41:32 -05:00
|
|
|
var tl = rect.topLeft;
|
2011-02-11 05:49:24 -05:00
|
|
|
path.add(tl.add(0, size.height), null, [0, -uSize.height]);
|
|
|
|
path.add(tl.add(size.width, 0), [-uSize.width, 0], null);
|
2011-02-07 13:28:09 -05:00
|
|
|
|
2011-02-11 08:41:32 -05:00
|
|
|
var tr = rect.topRight;
|
2011-02-11 05:49:24 -05:00
|
|
|
path.add(tr.subtract(size.width, 0), null, [uSize.width, 0]);
|
|
|
|
path.add(tr.add(0, size.height), [0, -uSize.height], null);
|
2011-02-07 13:28:09 -05:00
|
|
|
|
2011-02-11 08:41:32 -05:00
|
|
|
var br = rect.bottomRight;
|
2011-02-11 05:49:24 -05:00
|
|
|
path.add(br.subtract(0, size.height), null, [0, uSize.height]);
|
|
|
|
path.add(br.subtract(size.width, 0), [uSize.width, 0], null);
|
2011-02-07 13:28:09 -05:00
|
|
|
|
2011-02-11 05:49:24 -05:00
|
|
|
path.closed = true;
|
|
|
|
return path;
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2011-02-11 05:49:24 -05:00
|
|
|
Oval: Base.extend(new function() {
|
2011-02-07 13:28:09 -05:00
|
|
|
var u = 2 / 3 * (Math.sqrt(2) - 1);
|
|
|
|
var segments = [
|
|
|
|
{ handleOut: [0, -u], handleIn: [0, u], point: [ 0, 0.5] },
|
|
|
|
{ handleOut: [u, 0], handleIn: [-u, 0], point: [ 0.5, 0] },
|
|
|
|
{ handleOut: [0, u], handleIn: [0, -u], point: [ 1, 0.5] },
|
|
|
|
{ handleOut: [-u, 0], handleIn: [u, 0], point: [0.5, 1] }
|
|
|
|
];
|
|
|
|
return {
|
|
|
|
initialize: function() {
|
2011-02-11 05:49:24 -05:00
|
|
|
var path = new Path();
|
2011-02-07 13:28:09 -05:00
|
|
|
var rect = Rectangle.read(arguments);
|
2011-02-11 08:41:32 -05:00
|
|
|
var topLeft = rect.topLeft;
|
2011-02-07 13:28:09 -05:00
|
|
|
var size = new Size(rect.width, rect.height);
|
|
|
|
for(var i = 0; i < 4; i++) {
|
|
|
|
var segment = Segment.read([segments[i]]);
|
|
|
|
segment.handleIn = segment.handleIn.multiply(size);
|
|
|
|
segment.handleOut = segment.handleOut.multiply(size);
|
|
|
|
segment.point = segment.point.multiply(size).add(topLeft);
|
2011-02-13 08:52:51 -05:00
|
|
|
path._segments.push(segment);
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
2011-02-11 05:49:24 -05:00
|
|
|
path.closed = true;
|
|
|
|
return path;
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2011-02-11 05:49:24 -05:00
|
|
|
Circle: Base.extend({
|
2011-02-07 13:28:09 -05:00
|
|
|
initialize: function() {
|
2011-02-11 05:49:24 -05:00
|
|
|
var path = new Path();
|
2011-02-07 13:28:09 -05:00
|
|
|
var center, radius;
|
|
|
|
if(arguments.length == 3) {
|
|
|
|
center = new Point(arguments[0], arguments[1]);
|
|
|
|
radius = arguments[2];
|
|
|
|
} else {
|
|
|
|
center = new Point(arguments[0]);
|
|
|
|
radius = arguments[1];
|
|
|
|
}
|
|
|
|
var left = center.subtract(radius, 0);
|
2011-02-11 05:49:24 -05:00
|
|
|
path.moveTo(left);
|
|
|
|
path.arcTo(center.add(radius, 0), true);
|
|
|
|
path.arcTo(left, true);
|
2011-02-13 08:52:51 -05:00
|
|
|
var last = path._segments.pop();
|
|
|
|
path._segments[0].handleIn = last.handleIn;
|
2011-02-11 05:49:24 -05:00
|
|
|
path.closed = true;
|
|
|
|
return path;
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
Arc: PathItem.extend({
|
|
|
|
initialize: function(from, through, to) {
|
2011-02-11 05:49:24 -05:00
|
|
|
var path = new Path();
|
|
|
|
path.moveTo(from);
|
|
|
|
path.arcTo(through, to);
|
|
|
|
return path;
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|