mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Reformating code to follow Scriptotgrapher coding conventions.
This commit is contained in:
parent
50b2e12372
commit
08d4826441
26 changed files with 146 additions and 146 deletions
|
@ -29,14 +29,14 @@
|
|||
count++;
|
||||
doc.activeLayer.children = [];
|
||||
var point = new Point(1024, 768).divide(2);
|
||||
for(var i = 0; i < 35; i++) {
|
||||
for (var i = 0; i < 35; i++) {
|
||||
var vector = new Point(20 + 10 * i, 0).rotate(i * (360 / 35 * 2) * Math.sin(count / 150));
|
||||
var l = vector.length;
|
||||
var path = new Path();
|
||||
// path.strokeColor = '#000000';
|
||||
path.fillColor = i % 2 ? 'red' : 'black';
|
||||
path.closed = true;
|
||||
for(var j = 0; j < 32; j++) {
|
||||
for (var j = 0; j < 32; j++) {
|
||||
vector = vector.rotate(45 / 4);
|
||||
var newPoint = point.add(vector).add(vector.rotate(-180).normalize(l * (j % 2 ? 0.1 : -0.1)));
|
||||
path.add(newPoint);
|
||||
|
|
|
@ -22,15 +22,15 @@
|
|||
var doc = new Doc(canvas);
|
||||
|
||||
var point = new Point(1024, 768).divide(2);
|
||||
for(var i = 0; i < 30; i++) {
|
||||
for (var i = 0; i < 30; i++) {
|
||||
var vector = new Point(10 + 20 * i, 0).rotate(i);
|
||||
var l = vector.length;
|
||||
var path = new Path();
|
||||
path.fillColor = i % 2 ? 'red' : 'black';
|
||||
path.closed = true;
|
||||
for(var j = 0; j < 17; j++) {
|
||||
for (var j = 0; j < 17; j++) {
|
||||
vector = vector.rotate(45 / 2);
|
||||
if(j == 0) {
|
||||
if (j == 0) {
|
||||
path.add(point.add(vector));
|
||||
} else {
|
||||
path.arcTo(point.add(vector), true);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
var canvas = document.getElementById('canvas');
|
||||
doc = new Doc(canvas);
|
||||
var center = doc.size.divide(2);
|
||||
for(var i = 0; i < 70; i++) {
|
||||
for (var i = 0; i < 70; i++) {
|
||||
var path = new Path.Circle(center, i * 5);
|
||||
path.strokeColor = 'black';
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
doc.activeLayer.children = [];
|
||||
var point = new Point(1024, 768).divide(2);
|
||||
var vector = new Point(100, 0);
|
||||
for(var i = 0; i < 180; i++) {
|
||||
for (var i = 0; i < 180; i++) {
|
||||
var path = new Path.Line(point.add(vector.rotate(i * 2).normalize(30)), point.add(vector.rotate(i * 2).normalize(30 + Math.abs(Math.sin((i + count / 20)) * 300))));
|
||||
path.strokeColor = i % 4 ? 'black' : 'red';
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
var doc = new Doc(canvas);
|
||||
|
||||
var point = new Point(1024, 768).divide(2);
|
||||
for(var i = 0; i < 30; i++) {
|
||||
for (var i = 0; i < 30; i++) {
|
||||
var vector = new Point(1 + 10 * i, 0).rotate(i);
|
||||
var l = vector.length;
|
||||
var path = new Path();
|
||||
// path.strokeColor = '#000000';
|
||||
path.fillColor = i % 2 ? 'red' : 'black';
|
||||
path.closed = true;
|
||||
for(var j = 0; j < 32; j++) {
|
||||
for (var j = 0; j < 32; j++) {
|
||||
vector = vector.rotate(45 / 4);
|
||||
var newPoint = point.add(vector).add(vector.rotate(-180).normalize(l * (j % 2 ? 0.1 : -0.1)));
|
||||
path.add(newPoint);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
var path;
|
||||
var tool = new Tool({
|
||||
onMouseDrag: function(event) {
|
||||
if(path) path.remove();
|
||||
if (path) path.remove();
|
||||
var distance = event.downPoint.subtract(event.point).length;
|
||||
path = new Path.Circle(event.downPoint, distance);
|
||||
path.strokeColor = 'black';
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
var strokePoints = strokeEnds * 2 + 1;
|
||||
point = point.subtract(step.divide(2));
|
||||
step = step.divide(strokePoints - 1);
|
||||
for(var i = 0; i < strokePoints; i++) {
|
||||
for (var i = 0; i < strokePoints; i++) {
|
||||
var strokePoint = point.add(step.multiply(i));
|
||||
var offset = delta.multiply(Math.random() * 0.3 + 0.1);
|
||||
if (i % 2) {
|
||||
|
|
|
@ -2451,7 +2451,7 @@ DomDocument = DomElement.extend({
|
|||
_type: 'document',
|
||||
|
||||
initialize: function() {
|
||||
if(Browser.TRIDENT && Browser.VERSION < 7)
|
||||
if (Browser.TRIDENT && Browser.VERSION < 7)
|
||||
try {
|
||||
// Fix background flickering on IE.
|
||||
this.$.execCommand('BackgroundImageCache', false, true);
|
||||
|
@ -4165,7 +4165,7 @@ HtmlFormElement.inject({
|
|||
setSelection: function(start, end) {
|
||||
var sel = end == undefined ? start : { start: start, end: end };
|
||||
this.focus();
|
||||
if(this.$.setSelectionRange) {
|
||||
if (this.$.setSelectionRange) {
|
||||
this.$.setSelectionRange(sel.start, sel.end);
|
||||
} else {
|
||||
var value = this.getValue();
|
||||
|
@ -4213,7 +4213,7 @@ HtmlFormElement.inject({
|
|||
// Fix Firefox scroll bug, see http://userscripts.org/scripts/review/9452, #insertAtCaret()
|
||||
var top = this.$.scrollTop, height = this.$.scrollHeight;
|
||||
this.setValue(current.substring(0, range.start) + value + current.substring(range.end, current.length));
|
||||
if(top != null)
|
||||
if (top != null)
|
||||
this.$.scrollTop = top + this.$.scrollHeight - height;
|
||||
return select || select == undefined
|
||||
? this.setSelection(range.start, range.start + value.length)
|
||||
|
|
|
@ -3,7 +3,7 @@ Paper = Base.extend({
|
|||
documents: [],
|
||||
activateDocument: function(doc) {
|
||||
var index = this.documents.indexOf(doc);
|
||||
if(index != -1)
|
||||
if (index != -1)
|
||||
this.document = this.documents[index];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
var Point = Base.extend({
|
||||
beans: true,
|
||||
initialize: function() {
|
||||
if(arguments.length == 2) {
|
||||
if (arguments.length == 2) {
|
||||
this.x = arguments[0];
|
||||
this.y = arguments[1];
|
||||
} else if(arguments.length == 1) {
|
||||
} else if (arguments.length == 1) {
|
||||
var first = arguments[0];
|
||||
if(first == null) {
|
||||
if (first == null) {
|
||||
this.x = this.y = 0;
|
||||
} else if(first.x !== undefined) {
|
||||
} else if (first.x !== undefined) {
|
||||
this.x = first.x;
|
||||
this.y = first.y;
|
||||
} else if(first.width !== undefined) {
|
||||
} else if (first.width !== undefined) {
|
||||
this.x = first.width;
|
||||
this.y = first.height;
|
||||
} else if(first.length !== undefined) {
|
||||
} else if (first.length !== undefined) {
|
||||
this.x = first[0];
|
||||
this.y = first.length > 1 ? first[1] : first[0];
|
||||
} else if(typeof first === 'number') {
|
||||
} else if (typeof first === 'number') {
|
||||
this.x = this.y = first;
|
||||
} else {
|
||||
this.x = this.y = 0;
|
||||
|
@ -145,7 +145,7 @@ var Point = Base.extend({
|
|||
|
||||
setAngle: function(angle) {
|
||||
angle = this._angle = angle * Math.PI / 180;
|
||||
if(!this.isZero()) {
|
||||
if (!this.isZero()) {
|
||||
var length = this.length;
|
||||
this.x = Math.cos(angle) * length;
|
||||
this.y = Math.sin(angle) * length;
|
||||
|
@ -154,10 +154,10 @@ var Point = Base.extend({
|
|||
|
||||
getAngle: function() {
|
||||
var angle;
|
||||
if(arguments.length) {
|
||||
if (arguments.length) {
|
||||
var point = Point.read(arguments);
|
||||
var div = this.length * point.length;
|
||||
if(div == 0) {
|
||||
if (div == 0) {
|
||||
return NaN;
|
||||
} else {
|
||||
angle = Math.acos(this.dot(point) / div);
|
||||
|
@ -174,7 +174,7 @@ var Point = Base.extend({
|
|||
var point = Point.read(arguments);
|
||||
var angle = this.angle - point.angle;
|
||||
var bounds = 180;
|
||||
if(angle < - bounds) {
|
||||
if (angle < - bounds) {
|
||||
return angle + bounds * 2;
|
||||
} else if (angle > bounds) {
|
||||
return angle - bounds * 2;
|
||||
|
@ -255,7 +255,7 @@ var Point = Base.extend({
|
|||
|
||||
project: function() {
|
||||
var point = Point.read(arguments);
|
||||
if(point.isZero()) {
|
||||
if (point.isZero()) {
|
||||
return new Point(0, 0);
|
||||
} else {
|
||||
var scale = this.dot(point) / point.dot(point);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
Rectangle = Base.extend({
|
||||
beans: true,
|
||||
initialize: function() {
|
||||
if(arguments.length == 1) {
|
||||
if (arguments.length == 1) {
|
||||
var rect = arguments[0];
|
||||
this.x = rect.x;
|
||||
this.y = rect.y;
|
||||
this.width = rect.width;
|
||||
this.height = rect.height;
|
||||
} else if(arguments.length == 2) {
|
||||
if(arguments[1].x !== undefined) {
|
||||
} else if (arguments.length == 2) {
|
||||
if (arguments[1].x !== undefined) {
|
||||
// new Rectangle(point1, point2)
|
||||
var point1 = new Point(arguments[0]);
|
||||
var point2 = new Point(arguments[1]);
|
||||
|
@ -16,11 +16,11 @@ Rectangle = Base.extend({
|
|||
this.y = point1.y;
|
||||
this.width = point2.x - point1.x;
|
||||
this.height = point2.y - point1.y;
|
||||
if(this.width < 0) {
|
||||
if (this.width < 0) {
|
||||
this.x = point2.x;
|
||||
this.width = -this.width;
|
||||
}
|
||||
if(this.height < 0) {
|
||||
if (this.height < 0) {
|
||||
this.y = point2.y;
|
||||
this.height = -this.height;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ Rectangle = Base.extend({
|
|||
this.width = size.width;
|
||||
this.height = size.height;
|
||||
}
|
||||
} else if(arguments.length == 4) {
|
||||
} else if (arguments.length == 4) {
|
||||
// new Rectangle(x, y, width, height)
|
||||
this.x = arguments[0];
|
||||
this.y = arguments[1];
|
||||
|
@ -221,7 +221,7 @@ Rectangle = Base.extend({
|
|||
},
|
||||
|
||||
contains: function(rect) {
|
||||
if(rect.width !== undefined) {
|
||||
if (rect.width !== undefined) {
|
||||
return rect.x >= this.x && rect.y >= this.y
|
||||
&& rect.x + rect.width <= this.x + this.width
|
||||
&& rect.y + rect.height <= this.y + this.height;
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
var Size = Base.extend({
|
||||
initialize: function() {
|
||||
if(arguments.length == 2) {
|
||||
if (arguments.length == 2) {
|
||||
this.width = arguments[0];
|
||||
this.height = arguments[1];
|
||||
} else if(arguments.length == 1) {
|
||||
} else if (arguments.length == 1) {
|
||||
var first = arguments[0];
|
||||
if(first.width !== undefined || first.height !== undefined) {
|
||||
if (first.width !== undefined || first.height !== undefined) {
|
||||
this.width = first.width ? first.width : 0;
|
||||
this.height = first.height ? first.height : 0;
|
||||
} else if(first.x !== undefined || first.y !== undefined) {
|
||||
} else if (first.x !== undefined || first.y !== undefined) {
|
||||
this.width = first.x ? first.x : 0;
|
||||
this.height = first.y ? first.y : 0;
|
||||
} else if(first.length !== undefined) {
|
||||
} else if (first.length !== undefined) {
|
||||
this.width = first[0];
|
||||
this.height = first.length > 1 ? first[1] : first[0];
|
||||
} else if(typeof first === 'number') {
|
||||
} else if (typeof first === 'number') {
|
||||
this.width = this.height = first;
|
||||
} else {
|
||||
this.width = this.height = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Doc = Base.extend({
|
||||
initialize: function(canvas) {
|
||||
if(canvas) {
|
||||
if (canvas) {
|
||||
this.canvas = canvas;
|
||||
this.ctx = this.canvas.getContext('2d');
|
||||
this.size = new Size(canvas.offsetWidth, canvas.offsetHeight);
|
||||
|
@ -16,9 +16,9 @@ Doc = Base.extend({
|
|||
},
|
||||
|
||||
redraw: function() {
|
||||
if(this.canvas) {
|
||||
if (this.canvas) {
|
||||
this.ctx.clearRect(0, 0, this.size.width, this.size.height);
|
||||
for(var i = 0, l = this.layers.length; i < l; i++) {
|
||||
for (var i = 0, l = this.layers.length; i < l; i++) {
|
||||
this.layers[i].draw(this.ctx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ Group = Item.extend({
|
|||
initialize: function(items) {
|
||||
this.base();
|
||||
this.children = [];
|
||||
if(items) {
|
||||
for(var i = 0, l = items.length; i < l; i++) {
|
||||
if (items) {
|
||||
for (var i = 0, l = items.length; i < l; i++) {
|
||||
this.appendTop(items[i]);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ Group = Item.extend({
|
|||
},
|
||||
|
||||
draw: function(ctx) {
|
||||
for(var i = 0, l = this.children.length; i < l; i++) {
|
||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||
this.children[i].draw(ctx);
|
||||
}
|
||||
},
|
||||
|
@ -36,7 +36,7 @@ Group = Item.extend({
|
|||
setClipped: function(clipped) {
|
||||
this.clipped = clipped;
|
||||
var child = this.firstChild;
|
||||
if(child)
|
||||
if (child)
|
||||
child.setClipMask(clipped);
|
||||
}
|
||||
});
|
|
@ -16,7 +16,7 @@ Item = Base.extend({
|
|||
|
||||
copyTo: function(itemOrDocument) {
|
||||
var copy = Base.clone(this);
|
||||
if(itemOrDocument.layers) {
|
||||
if (itemOrDocument.layers) {
|
||||
copy.parent = itemOrDocument.activeLayer;
|
||||
itemOrDocument.activeLayer.appendTop(copy);
|
||||
} else {
|
||||
|
@ -127,7 +127,7 @@ Item = Base.extend({
|
|||
|
||||
setClipMask: function(clipMask) {
|
||||
this.clipMask = clipMask;
|
||||
if(this.clipMask) {
|
||||
if (this.clipMask) {
|
||||
this.fillColor = null;
|
||||
this.strokeColor = null;
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ Item = Base.extend({
|
|||
* The first item contained within this item.
|
||||
*/
|
||||
getFirstChild: function() {
|
||||
if(this.children.length > 0)
|
||||
if (this.children.length > 0)
|
||||
return this.children[0];
|
||||
},
|
||||
|
||||
|
@ -145,7 +145,7 @@ Item = Base.extend({
|
|||
* The last item contained within this item.
|
||||
*/
|
||||
getLastChild: function() {
|
||||
if(this.children.length > 0)
|
||||
if (this.children.length > 0)
|
||||
return this.children[this.children.length - 1];
|
||||
},
|
||||
|
||||
|
@ -153,9 +153,9 @@ Item = Base.extend({
|
|||
* The next item on the same level as this item.
|
||||
*/
|
||||
getNextSibling: function() {
|
||||
if(this.parent) {
|
||||
if (this.parent) {
|
||||
var index = this.index + 1;
|
||||
if(index < this.parent.children.length)
|
||||
if (index < this.parent.children.length)
|
||||
return this.parent.children[index];
|
||||
}
|
||||
},
|
||||
|
@ -164,9 +164,9 @@ Item = Base.extend({
|
|||
* The previous item on the same level as this item.
|
||||
*/
|
||||
getPreviousSibling: function() {
|
||||
if(this.parent) {
|
||||
if (this.parent) {
|
||||
var index = this.index - 1;
|
||||
if(index <= 0)
|
||||
if (index <= 0)
|
||||
return this.parent.children[index];
|
||||
}
|
||||
},
|
||||
|
@ -182,7 +182,7 @@ Item = Base.extend({
|
|||
* Removes the item from its parent's children list.
|
||||
*/
|
||||
removeFromParent: function() {
|
||||
if(this.parent)
|
||||
if (this.parent)
|
||||
this.parent.children.splice(this.index, 1);
|
||||
this.parent = null;
|
||||
},
|
||||
|
@ -214,7 +214,7 @@ Item = Base.extend({
|
|||
isEditable: function() {
|
||||
var parent = this;
|
||||
while(parent) {
|
||||
if(parent.hidden || parent.locked)
|
||||
if (parent.hidden || parent.locked)
|
||||
return false;
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ Item = Base.extend({
|
|||
isDescendant: function(item) {
|
||||
var parent = this;
|
||||
while(parent) {
|
||||
if(parent == item)
|
||||
if (parent == item)
|
||||
return true;
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ Item = Base.extend({
|
|||
isAncestor: function(item) {
|
||||
var parent = item;
|
||||
while(parent) {
|
||||
if(parent == this)
|
||||
if (parent == this)
|
||||
return true;
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ Layer = Item.extend({
|
|||
},
|
||||
|
||||
draw: function(ctx) {
|
||||
for(var i = 0, l = this.children.length; i < l; i++) {
|
||||
for (var i = 0, l = this.children.length; i < l; i++) {
|
||||
this.children[i].draw(ctx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ Path = PathItem.extend({
|
|||
Line: Base.extend({
|
||||
initialize: function() {
|
||||
var path = new Path();
|
||||
if(arguments.length == 2) {
|
||||
if (arguments.length == 2) {
|
||||
path.addSegment(new Segment(arguments[0]));
|
||||
path.addSegment(new Segment(arguments[1]));
|
||||
} else if(arguments.length == 4) {
|
||||
} else if (arguments.length == 4) {
|
||||
path.addSegment(Segment.read(arguments[0], arguments[1]));
|
||||
path.addSegment(Segment.read(arguments[2], arguments[3]));
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ Path = PathItem.extend({
|
|||
path.closed = true;
|
||||
var rectangle = Rectangle.read(arguments);
|
||||
var corners = ['bottomLeft', 'topLeft', 'topRight', 'bottomRight'];
|
||||
for(var i = 0; i < 4; i++) {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
path.add(rectangle[corners[i]]);
|
||||
}
|
||||
return path;
|
||||
|
@ -37,7 +37,7 @@ Path = PathItem.extend({
|
|||
initialize: function() {
|
||||
var path = new Path();
|
||||
var rect, size;
|
||||
if(arguments.length == 2) {
|
||||
if (arguments.length == 2) {
|
||||
rect = new Rectangle(arguments[0]);
|
||||
size = new Size(arguments[1]);
|
||||
} else {
|
||||
|
@ -84,7 +84,7 @@ Path = PathItem.extend({
|
|||
var rect = Rectangle.read(arguments);
|
||||
var topLeft = rect.topLeft;
|
||||
var size = new Size(rect.width, rect.height);
|
||||
for(var i = 0; i < 4; i++) {
|
||||
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);
|
||||
|
@ -101,7 +101,7 @@ Path = PathItem.extend({
|
|||
initialize: function() {
|
||||
var path = new Path();
|
||||
var center, radius;
|
||||
if(arguments.length == 3) {
|
||||
if (arguments.length == 3) {
|
||||
center = new Point(arguments[0], arguments[1]);
|
||||
radius = arguments[2];
|
||||
} else {
|
||||
|
|
|
@ -51,7 +51,7 @@ PathItem = Item.extend(new function() {
|
|||
if (!segments || segments.length === undefined
|
||||
|| typeof segments[0] != 'object')
|
||||
segments = arguments;
|
||||
for(var i = 0, l = segments.length; i < l; i++)
|
||||
for (var i = 0, l = segments.length; i < l; i++)
|
||||
this.addSegment(new Segment(segments[i]));
|
||||
},
|
||||
|
||||
|
@ -156,7 +156,7 @@ PathItem = Item.extend(new function() {
|
|||
|
||||
add: function() {
|
||||
var segment = Segment.read(arguments);
|
||||
if(segment)
|
||||
if (segment)
|
||||
this.addSegment(segment);
|
||||
},
|
||||
|
||||
|
@ -180,13 +180,13 @@ PathItem = Item.extend(new function() {
|
|||
|
||||
moveTo: function() {
|
||||
var segment = Segment.read(arguments);
|
||||
if(segment && !this._segments.length)
|
||||
if (segment && !this._segments.length)
|
||||
this.addSegment(segment);
|
||||
},
|
||||
|
||||
lineTo: function() {
|
||||
var segment = Segment.read(arguments);
|
||||
if(segment && this._segments.length)
|
||||
if (segment && this._segments.length)
|
||||
this.addSegment(segment);
|
||||
},
|
||||
|
||||
|
@ -230,7 +230,7 @@ PathItem = Item.extend(new function() {
|
|||
curveTo: function(through, to, parameter) {
|
||||
through = new Point(through);
|
||||
to = new Point(to);
|
||||
if(parameter == null)
|
||||
if (parameter == null)
|
||||
parameter = 0.5;
|
||||
var current = this.currentSegment.point;
|
||||
// handle = (through - (1 - t)^2 * current - t^2 * to) / (2 * (1 - t) * t)
|
||||
|
@ -250,11 +250,11 @@ PathItem = Item.extend(new function() {
|
|||
var through, to;
|
||||
// Get the start point:
|
||||
var current = this.currentSegment;
|
||||
if(arguments[1] && typeof arguments[1] != 'boolean') {
|
||||
if (arguments[1] && typeof arguments[1] != 'boolean') {
|
||||
through = new Point(arguments[0]);
|
||||
to = new Point(arguments[1]);
|
||||
} else {
|
||||
if(clockwise === null)
|
||||
if (clockwise === null)
|
||||
clockwise = true;
|
||||
var middle = current.point.add(to).divide(2);
|
||||
var step = middle.subtract(current.point);
|
||||
|
@ -337,7 +337,7 @@ PathItem = Item.extend(new function() {
|
|||
|
||||
lineBy: function() {
|
||||
var vector = Point.read(arguments);
|
||||
if(vector) {
|
||||
if (vector) {
|
||||
var current = this.currentSegment;
|
||||
this.lineTo(current.point.add(vector));
|
||||
}
|
||||
|
@ -457,23 +457,23 @@ PathItem = Item.extend(new function() {
|
|||
},
|
||||
|
||||
setCtxStyles: function(ctx) {
|
||||
for(var i in styleNames) {
|
||||
for (var i in styleNames) {
|
||||
var style;
|
||||
if(style = this[i])
|
||||
if (style = this[i])
|
||||
ctx[styleNames[i]] = style;
|
||||
}
|
||||
},
|
||||
|
||||
draw: function(ctx) {
|
||||
if(!this.visible) return;
|
||||
if (!this.visible) return;
|
||||
ctx.beginPath();
|
||||
var cp1;
|
||||
for(var i = 0, l = this._segments.length; i < l; i++) {
|
||||
for (var i = 0, l = this._segments.length; i < l; i++) {
|
||||
var segment = this._segments[i];
|
||||
var point = segment.point;
|
||||
var handleIn = segment.handleIn ? segment.handleIn.add(point) : point;
|
||||
var handleOut = segment.handleOut ? segment.handleOut.add(point) : point;
|
||||
if(i == 0) {
|
||||
if (i == 0) {
|
||||
ctx.moveTo(point.x, point.y);
|
||||
} else {
|
||||
ctx.bezierCurveTo(cp1.x, cp1.y, handleIn.x, handleIn.y,
|
||||
|
@ -481,7 +481,7 @@ PathItem = Item.extend(new function() {
|
|||
}
|
||||
cp1 = handleOut;
|
||||
}
|
||||
if(this.closed && this._segments.length > 1) {
|
||||
if (this.closed && this._segments.length > 1) {
|
||||
var segment = this._segments[0];
|
||||
var point = segment.point;
|
||||
var handleIn = segment.handleIn ? segment.handleIn.add(point) : point;
|
||||
|
@ -490,8 +490,8 @@ PathItem = Item.extend(new function() {
|
|||
ctx.closePath();
|
||||
}
|
||||
this.setCtxStyles(ctx);
|
||||
if(this.fillColor) ctx.fill();
|
||||
if(this.strokeColor) ctx.stroke();
|
||||
if (this.fillColor) ctx.fill();
|
||||
if (this.strokeColor) ctx.stroke();
|
||||
}
|
||||
};
|
||||
});
|
|
@ -1,29 +1,29 @@
|
|||
Segment = Base.extend({
|
||||
initialize: function() {
|
||||
if(arguments.length == 0) {
|
||||
if (arguments.length == 0) {
|
||||
this.point = new Point();
|
||||
} else if(arguments.length == 1) {
|
||||
if(arguments[0].point) {
|
||||
} else if (arguments.length == 1) {
|
||||
if (arguments[0].point) {
|
||||
var segment = arguments[0];
|
||||
this.point = new Point(segment.point);
|
||||
if(segment.handleIn)
|
||||
if (segment.handleIn)
|
||||
this.handleIn = new Point(segment.handleIn);
|
||||
if(segment.handleOut)
|
||||
if (segment.handleOut)
|
||||
this.handleOut = new Point(segment.handleOut);
|
||||
} else {
|
||||
this.point = new Point(arguments[0]);
|
||||
}
|
||||
} else if(arguments.length < 6) {
|
||||
if(arguments.length == 2 && !arguments[1].x) {
|
||||
} else if (arguments.length < 6) {
|
||||
if (arguments.length == 2 && !arguments[1].x) {
|
||||
this.point = new Point(arguments[0], arguments[1]);
|
||||
} else {
|
||||
this.point = new Point(arguments[0]);
|
||||
if(arguments[1])
|
||||
if (arguments[1])
|
||||
this.handleIn = new Point(arguments[1]);
|
||||
if(arguments[2])
|
||||
if (arguments[2])
|
||||
this.handleOut = new Point(arguments[2]);
|
||||
}
|
||||
} else if(arguments.length == 6) {
|
||||
} else if (arguments.length == 6) {
|
||||
this.point = new Point(arguments[0], arguments[1]);
|
||||
this.handleIn = new Point(arguments[2], arguments[3]);
|
||||
this.handleOut = new Point(arguments[4], arguments[5]);
|
||||
|
@ -36,7 +36,7 @@ Segment = Base.extend({
|
|||
|
||||
// TODO:
|
||||
// insert: function() {
|
||||
// if(this._segments && this._segments.path) {
|
||||
// if (this._segments && this._segments.path) {
|
||||
// var path = this._segments.path;
|
||||
// path.checkValid();
|
||||
//
|
||||
|
@ -74,8 +74,8 @@ Segment = Base.extend({
|
|||
getIndex: function() {
|
||||
// TODO: Cache and update indices instead of searching?
|
||||
var segments = this.path._segments;
|
||||
for(var i = 0, l = segments.length; i < l; i++) {
|
||||
if(segments[i] == this)
|
||||
for (var i = 0, l = segments.length; i < l; i++) {
|
||||
if (segments[i] == this)
|
||||
return i;
|
||||
}
|
||||
},
|
||||
|
@ -86,7 +86,7 @@ Segment = Base.extend({
|
|||
|
||||
// todo
|
||||
// getCurve: function() {
|
||||
// if(this._segments && this._segments.path) {
|
||||
// if (this._segments && this._segments.path) {
|
||||
// var curves = this._segments.path.getCurves();
|
||||
// // The curves list handles closing curves, so the curves.size
|
||||
// // is adjusted accordingly. just check to be in the boundaries here:
|
||||
|
@ -121,7 +121,7 @@ Segment = Base.extend({
|
|||
},
|
||||
|
||||
remove: function() {
|
||||
if(this.path && this.path._segments)
|
||||
if (this.path && this.path._segments)
|
||||
return this.path._segments.splice(this.index, 1);
|
||||
return false;
|
||||
},
|
||||
|
@ -144,4 +144,4 @@ Segment = Base.extend({
|
|||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ ToolHandler = Base.extend({
|
|||
this.firstMove = true;
|
||||
this.count = 0;
|
||||
this.downCount = 0;
|
||||
for(var i in handlers) {
|
||||
for (var i in handlers) {
|
||||
this[i] = handlers[i];
|
||||
}
|
||||
},
|
||||
|
@ -105,7 +105,7 @@ ToolHandler = Base.extend({
|
|||
switch (type) {
|
||||
case 'MOUSE_DOWN':
|
||||
this.updateEvent(type, pt, null, null, true, false, false);
|
||||
if(this.onMouseDown)
|
||||
if (this.onMouseDown)
|
||||
this.onMouseDown(new ToolEvent(this, type, modifiers));
|
||||
break;
|
||||
case 'MOUSE_DRAG':
|
||||
|
@ -121,7 +121,7 @@ ToolHandler = Base.extend({
|
|||
this.matchMaxDistance = false;
|
||||
while (this.updateEvent(type, pt, this.minDistance,
|
||||
this.maxDistance, false, this.needsChange, this.matchMaxDistance)) {
|
||||
if(this.onMouseDrag)
|
||||
if (this.onMouseDrag)
|
||||
this.onMouseDrag(new ToolEvent(this, type, modifiers));
|
||||
this.needsChange = true;
|
||||
this.matchMaxDistance = true;
|
||||
|
@ -132,12 +132,12 @@ ToolHandler = Base.extend({
|
|||
// mouse drag first, then mouse up.
|
||||
if ((this.point.x != pt.x || this.point.y != pt.y) && this.updateEvent(
|
||||
'MOUSE_DRAG', pt, this.minDistance, this.maxDistance, false, false, false)) {
|
||||
if(this.onMouseDrag)
|
||||
if (this.onMouseDrag)
|
||||
this.onMouseDrag(new ToolEvent(this, type, modifiers));
|
||||
}
|
||||
this.updateEvent(type, pt, null, this.maxDistance, false,
|
||||
false, false);
|
||||
if(this.onMouseUp)
|
||||
if (this.onMouseUp)
|
||||
this.onMouseUp(new ToolEvent(this, type, modifiers));
|
||||
// Start with new values for TRACK_CURSOR
|
||||
this.updateEvent(type, pt, null, null, true, false, false);
|
||||
|
@ -146,7 +146,7 @@ ToolHandler = Base.extend({
|
|||
case 'MOUSE_MOVE':
|
||||
while (this.updateEvent(type, pt, this.minDistance,
|
||||
this.maxDistance, this.firstMove, true, false)) {
|
||||
if(this.onMouseMove)
|
||||
if (this.onMouseMove)
|
||||
this.onMouseMove(new ToolEvent(this, type, modifiers));
|
||||
this.firstMove = false;
|
||||
}
|
||||
|
|
|
@ -1004,8 +1004,8 @@ QUnit.equiv = function () {
|
|||
parents.push(a);
|
||||
for (i = 0; i < len; i++) {
|
||||
loop = false;
|
||||
for(j=0;j<parents.length;j++){
|
||||
if(parents[j] === a[i]){
|
||||
for (j=0;j<parents.length;j++){
|
||||
if (parents[j] === a[i]){
|
||||
loop = true;//dont rewalk array
|
||||
}
|
||||
}
|
||||
|
@ -1035,8 +1035,8 @@ QUnit.equiv = function () {
|
|||
|
||||
for (i in a) { // be strict: don't ensures hasOwnProperty and go deep
|
||||
loop = false;
|
||||
for(j=0;j<parents.length;j++){
|
||||
if(parents[j] === a[i])
|
||||
for (j=0;j<parents.length;j++){
|
||||
if (parents[j] === a[i])
|
||||
loop = true; //don't go down the same path twice
|
||||
}
|
||||
aProperties.push(i); // collect a's properties
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
function compareSegmentLists(list1, list2) {
|
||||
equals(list1.length, list2.length, 'segment count');
|
||||
if(list1.length == list2.length) {
|
||||
for(var i = 0, l = list1.length; i < l; i++) {
|
||||
if (list1.length == list2.length) {
|
||||
for (var i = 0, l = list1.length; i < l; i++) {
|
||||
compareSegments(list1[i], list2[i]);
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ function compareSegments(segment1, segment2) {
|
|||
// all handles all the time.
|
||||
segment2 = Segment.read([segment2]);
|
||||
var points = ['point', 'handleIn', 'handleOut'];
|
||||
for(var i = 0; i < 3; i++) {
|
||||
for (var i = 0; i < 3; i++) {
|
||||
equals(!!segment1[points[i]], !!segment2[points[i]], 'have ' + points[i]);
|
||||
if(segment1[points[i]] && segment2[points[i]])
|
||||
if (segment1[points[i]] && segment2[points[i]])
|
||||
comparePoints(segment1[points[i]], segment2[points[i]], points[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
module('Point');
|
||||
test('new Point(10, 20)', function(){
|
||||
test('new Point(10, 20)', function() {
|
||||
var point = new Point(10, 20);
|
||||
equals(point.x, 10);
|
||||
equals(point.y, 20);
|
||||
});
|
||||
|
||||
test('new Point([10, 20])', function(){
|
||||
test('new Point([10, 20])', function() {
|
||||
var point = new Point([10, 20]);
|
||||
equals(point.x, 10);
|
||||
equals(point.y, 20);
|
||||
});
|
||||
|
||||
test('new Point({x: 10, y: 20})', function(){
|
||||
test('new Point({x: 10, y: 20})', function() {
|
||||
var point = new Point({x: 10, y: 20});
|
||||
equals(point.x, 10);
|
||||
equals(point.y, 20);
|
||||
});
|
||||
|
||||
test('new Point(new Size(10, 20))', function(){
|
||||
test('new Point(new Size(10, 20))', function() {
|
||||
var point = new Point(new Size(10, 20));
|
||||
equals(point.x, 10);
|
||||
equals(point.y, 20);
|
||||
});
|
||||
|
||||
test('new Point({ width: 10, height: 20})', function(){
|
||||
test('new Point({ width: 10, height: 20})', function() {
|
||||
var point = new Point({width: 10, height: 20});
|
||||
equals(point.x, 10);
|
||||
equals(point.y, 20);
|
||||
|
@ -31,36 +31,36 @@ test('new Point({ width: 10, height: 20})', function(){
|
|||
|
||||
module('Point vector operations');
|
||||
|
||||
test('normalize(length)', function(){
|
||||
test('normalize(length)', function() {
|
||||
var point = new Point(0, 10).normalize(20)
|
||||
equals(point.x, 0);
|
||||
equals(point.y, 20);
|
||||
});
|
||||
|
||||
test('set length', function(){
|
||||
test('set length', function() {
|
||||
var point = new Point(0, 10);
|
||||
point.length = 20;
|
||||
equals(point.x, 0);
|
||||
equals(point.y, 20);
|
||||
});
|
||||
|
||||
test('get angle', function(){
|
||||
test('get angle', function() {
|
||||
var angle = new Point(0, 10).angle;
|
||||
equals(angle, 90);
|
||||
});
|
||||
|
||||
test('getAngle(point)', function(){
|
||||
test('getAngle(point)', function() {
|
||||
var angle = new Point(0, 10).getAngle([10, 10]);
|
||||
equals(Math.round(angle), 45);
|
||||
});
|
||||
|
||||
test('rotate(degrees)', function(){
|
||||
test('rotate(degrees)', function() {
|
||||
var point = new Point(100, 50).rotate(90);
|
||||
equals(Math.round(point.x), -50);
|
||||
equals(Math.round(point.y), 100);
|
||||
});
|
||||
|
||||
test('set angle', function(){
|
||||
test('set angle', function() {
|
||||
var point = new Point(10, 20);
|
||||
point.angle = 92;
|
||||
equals(point.angle, 92);
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
module('Segment');
|
||||
test('new Segment(point)', function(){
|
||||
test('new Segment(point)', function() {
|
||||
var segment = new Segment(new Point(10, 10));
|
||||
var expected = { point: { x: 10, y: 10 } };
|
||||
compareSegments(segment, expected);
|
||||
});
|
||||
|
||||
test('new Segment(x, y)', function(){
|
||||
test('new Segment(x, y)', function() {
|
||||
var segment = new Segment(10, 10);
|
||||
var expected = { point: { x: 10, y: 10 } };
|
||||
compareSegments(segment, expected);
|
||||
});
|
||||
|
||||
test('new Segment(object)', function(){
|
||||
test('new Segment(object)', function() {
|
||||
var segment = new Segment({ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } });
|
||||
var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } };
|
||||
compareSegments(segment, expected);
|
||||
});
|
||||
|
||||
test('new Segment(point, handleIn, handleOut)', function(){
|
||||
test('new Segment(point, handleIn, handleOut)', function() {
|
||||
var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
|
||||
var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } };
|
||||
compareSegments(segment, expected);
|
||||
});
|
||||
|
||||
test('new Segment(x, y, inX, inY, outX, outY)', function(){
|
||||
test('new Segment(x, y, inX, inY, outX, outY)', function() {
|
||||
var segment = new Segment(10, 10, 5, 5, 15, 15);
|
||||
var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } };
|
||||
compareSegments(segment, expected);
|
||||
});
|
||||
|
||||
test('segment.reverse()', function(){
|
||||
test('segment.reverse()', function() {
|
||||
var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
|
||||
segment = segment.reverse();
|
||||
var expected = { point: { x: 10, y: 10 }, handleIn: { x: 15, y: 15 }, handleOut: { x: 5, y: 5 } };
|
||||
compareSegments(segment, expected);
|
||||
});
|
||||
|
||||
test('segment.clone()', function(){
|
||||
test('segment.clone()', function() {
|
||||
var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
|
||||
var clone = segment.clone();
|
||||
equals(segment == clone, false);
|
||||
compareSegments(segment, clone);
|
||||
});
|
||||
|
||||
test('segment.remove()', function(){
|
||||
test('segment.remove()', function() {
|
||||
var doc = new Doc();
|
||||
var path = new Path([10, 10], [5, 5], [10, 10]);
|
||||
path.segments[1].remove();
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
module('Size');
|
||||
test('new Size(10, 20)', function(){
|
||||
test('new Size(10, 20)', function() {
|
||||
var size = new Size(10, 20);
|
||||
equals(size.width, 10);
|
||||
equals(size.height, 20);
|
||||
});
|
||||
|
||||
test('new Size([10, 20])', function(){
|
||||
test('new Size([10, 20])', function() {
|
||||
var size = new Size([10, 20]);
|
||||
equals(size.width, 10);
|
||||
equals(size.height, 20);
|
||||
});
|
||||
|
||||
test('new Size({width: 10, height: 20})', function(){
|
||||
test('new Size({width: 10, height: 20})', function() {
|
||||
var size = new Size({width: 10, height: 20});
|
||||
equals(size.width, 10);
|
||||
equals(size.height, 20);
|
||||
});
|
||||
|
||||
test('new Size(new Point(10, 20))', function(){
|
||||
test('new Size(new Point(10, 20))', function() {
|
||||
var size = new Size(new Point(10, 20));
|
||||
equals(size.width, 10);
|
||||
equals(size.height, 20);
|
||||
});
|
||||
|
||||
test('new Size({ x: 10, y: 20})', function(){
|
||||
test('new Size({ x: 10, y: 20})', function() {
|
||||
var size = new Size({x: 10, y: 20});
|
||||
equals(size.width, 10);
|
||||
equals(size.height, 20);
|
||||
|
|
Loading…
Reference in a new issue