Reformating code to follow Scriptotgrapher coding conventions.

This commit is contained in:
Jürg Lehni 2011-02-13 16:26:24 +00:00
parent 50b2e12372
commit 08d4826441
26 changed files with 146 additions and 146 deletions

View file

@ -29,14 +29,14 @@
count++; count++;
doc.activeLayer.children = []; doc.activeLayer.children = [];
var point = new Point(1024, 768).divide(2); 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 vector = new Point(20 + 10 * i, 0).rotate(i * (360 / 35 * 2) * Math.sin(count / 150));
var l = vector.length; var l = vector.length;
var path = new Path(); var path = new Path();
// path.strokeColor = '#000000'; // path.strokeColor = '#000000';
path.fillColor = i % 2 ? 'red' : 'black'; path.fillColor = i % 2 ? 'red' : 'black';
path.closed = true; path.closed = true;
for(var j = 0; j < 32; j++) { for (var j = 0; j < 32; j++) {
vector = vector.rotate(45 / 4); vector = vector.rotate(45 / 4);
var newPoint = point.add(vector).add(vector.rotate(-180).normalize(l * (j % 2 ? 0.1 : -0.1))); var newPoint = point.add(vector).add(vector.rotate(-180).normalize(l * (j % 2 ? 0.1 : -0.1)));
path.add(newPoint); path.add(newPoint);

View file

@ -22,15 +22,15 @@
var doc = new Doc(canvas); var doc = new Doc(canvas);
var point = new Point(1024, 768).divide(2); 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 vector = new Point(10 + 20 * i, 0).rotate(i);
var l = vector.length; var l = vector.length;
var path = new Path(); var path = new Path();
path.fillColor = i % 2 ? 'red' : 'black'; path.fillColor = i % 2 ? 'red' : 'black';
path.closed = true; path.closed = true;
for(var j = 0; j < 17; j++) { for (var j = 0; j < 17; j++) {
vector = vector.rotate(45 / 2); vector = vector.rotate(45 / 2);
if(j == 0) { if (j == 0) {
path.add(point.add(vector)); path.add(point.add(vector));
} else { } else {
path.arcTo(point.add(vector), true); path.arcTo(point.add(vector), true);

View file

@ -23,7 +23,7 @@
var canvas = document.getElementById('canvas'); var canvas = document.getElementById('canvas');
doc = new Doc(canvas); doc = new Doc(canvas);
var center = doc.size.divide(2); 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); var path = new Path.Circle(center, i * 5);
path.strokeColor = 'black'; path.strokeColor = 'black';
} }

View file

@ -30,7 +30,7 @@
doc.activeLayer.children = []; doc.activeLayer.children = [];
var point = new Point(1024, 768).divide(2); var point = new Point(1024, 768).divide(2);
var vector = new Point(100, 0); 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)))); 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'; path.strokeColor = i % 4 ? 'black' : 'red';
} }

View file

@ -22,14 +22,14 @@
var doc = new Doc(canvas); var doc = new Doc(canvas);
var point = new Point(1024, 768).divide(2); 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 vector = new Point(1 + 10 * i, 0).rotate(i);
var l = vector.length; var l = vector.length;
var path = new Path(); var path = new Path();
// path.strokeColor = '#000000'; // path.strokeColor = '#000000';
path.fillColor = i % 2 ? 'red' : 'black'; path.fillColor = i % 2 ? 'red' : 'black';
path.closed = true; path.closed = true;
for(var j = 0; j < 32; j++) { for (var j = 0; j < 32; j++) {
vector = vector.rotate(45 / 4); vector = vector.rotate(45 / 4);
var newPoint = point.add(vector).add(vector.rotate(-180).normalize(l * (j % 2 ? 0.1 : -0.1))); var newPoint = point.add(vector).add(vector.rotate(-180).normalize(l * (j % 2 ? 0.1 : -0.1)));
path.add(newPoint); path.add(newPoint);

View file

@ -26,7 +26,7 @@
var path; var path;
var tool = new Tool({ var tool = new Tool({
onMouseDrag: function(event) { onMouseDrag: function(event) {
if(path) path.remove(); if (path) path.remove();
var distance = event.downPoint.subtract(event.point).length; var distance = event.downPoint.subtract(event.point).length;
path = new Path.Circle(event.downPoint, distance); path = new Path.Circle(event.downPoint, distance);
path.strokeColor = 'black'; path.strokeColor = 'black';

View file

@ -81,7 +81,7 @@
var strokePoints = strokeEnds * 2 + 1; var strokePoints = strokeEnds * 2 + 1;
point = point.subtract(step.divide(2)); point = point.subtract(step.divide(2));
step = step.divide(strokePoints - 1); 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 strokePoint = point.add(step.multiply(i));
var offset = delta.multiply(Math.random() * 0.3 + 0.1); var offset = delta.multiply(Math.random() * 0.3 + 0.1);
if (i % 2) { if (i % 2) {

View file

@ -2451,7 +2451,7 @@ DomDocument = DomElement.extend({
_type: 'document', _type: 'document',
initialize: function() { initialize: function() {
if(Browser.TRIDENT && Browser.VERSION < 7) if (Browser.TRIDENT && Browser.VERSION < 7)
try { try {
// Fix background flickering on IE. // Fix background flickering on IE.
this.$.execCommand('BackgroundImageCache', false, true); this.$.execCommand('BackgroundImageCache', false, true);
@ -4165,7 +4165,7 @@ HtmlFormElement.inject({
setSelection: function(start, end) { setSelection: function(start, end) {
var sel = end == undefined ? start : { start: start, end: end }; var sel = end == undefined ? start : { start: start, end: end };
this.focus(); this.focus();
if(this.$.setSelectionRange) { if (this.$.setSelectionRange) {
this.$.setSelectionRange(sel.start, sel.end); this.$.setSelectionRange(sel.start, sel.end);
} else { } else {
var value = this.getValue(); var value = this.getValue();
@ -4213,7 +4213,7 @@ HtmlFormElement.inject({
// Fix Firefox scroll bug, see http://userscripts.org/scripts/review/9452, #insertAtCaret() // Fix Firefox scroll bug, see http://userscripts.org/scripts/review/9452, #insertAtCaret()
var top = this.$.scrollTop, height = this.$.scrollHeight; var top = this.$.scrollTop, height = this.$.scrollHeight;
this.setValue(current.substring(0, range.start) + value + current.substring(range.end, current.length)); 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; this.$.scrollTop = top + this.$.scrollHeight - height;
return select || select == undefined return select || select == undefined
? this.setSelection(range.start, range.start + value.length) ? this.setSelection(range.start, range.start + value.length)

View file

@ -3,7 +3,7 @@ Paper = Base.extend({
documents: [], documents: [],
activateDocument: function(doc) { activateDocument: function(doc) {
var index = this.documents.indexOf(doc); var index = this.documents.indexOf(doc);
if(index != -1) if (index != -1)
this.document = this.documents[index]; this.document = this.documents[index];
} }
} }

View file

@ -1,23 +1,23 @@
var Point = Base.extend({ var Point = Base.extend({
beans: true, beans: true,
initialize: function() { initialize: function() {
if(arguments.length == 2) { if (arguments.length == 2) {
this.x = arguments[0]; this.x = arguments[0];
this.y = arguments[1]; this.y = arguments[1];
} else if(arguments.length == 1) { } else if (arguments.length == 1) {
var first = arguments[0]; var first = arguments[0];
if(first == null) { if (first == null) {
this.x = this.y = 0; this.x = this.y = 0;
} else if(first.x !== undefined) { } else if (first.x !== undefined) {
this.x = first.x; this.x = first.x;
this.y = first.y; this.y = first.y;
} else if(first.width !== undefined) { } else if (first.width !== undefined) {
this.x = first.width; this.x = first.width;
this.y = first.height; this.y = first.height;
} else if(first.length !== undefined) { } else if (first.length !== undefined) {
this.x = first[0]; this.x = first[0];
this.y = first.length > 1 ? first[1] : 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; this.x = this.y = first;
} else { } else {
this.x = this.y = 0; this.x = this.y = 0;
@ -145,7 +145,7 @@ var Point = Base.extend({
setAngle: function(angle) { setAngle: function(angle) {
angle = this._angle = angle * Math.PI / 180; angle = this._angle = angle * Math.PI / 180;
if(!this.isZero()) { if (!this.isZero()) {
var length = this.length; var length = this.length;
this.x = Math.cos(angle) * length; this.x = Math.cos(angle) * length;
this.y = Math.sin(angle) * length; this.y = Math.sin(angle) * length;
@ -154,10 +154,10 @@ var Point = Base.extend({
getAngle: function() { getAngle: function() {
var angle; var angle;
if(arguments.length) { if (arguments.length) {
var point = Point.read(arguments); var point = Point.read(arguments);
var div = this.length * point.length; var div = this.length * point.length;
if(div == 0) { if (div == 0) {
return NaN; return NaN;
} else { } else {
angle = Math.acos(this.dot(point) / div); angle = Math.acos(this.dot(point) / div);
@ -174,7 +174,7 @@ var Point = Base.extend({
var point = Point.read(arguments); var point = Point.read(arguments);
var angle = this.angle - point.angle; var angle = this.angle - point.angle;
var bounds = 180; var bounds = 180;
if(angle < - bounds) { if (angle < - bounds) {
return angle + bounds * 2; return angle + bounds * 2;
} else if (angle > bounds) { } else if (angle > bounds) {
return angle - bounds * 2; return angle - bounds * 2;
@ -255,7 +255,7 @@ var Point = Base.extend({
project: function() { project: function() {
var point = Point.read(arguments); var point = Point.read(arguments);
if(point.isZero()) { if (point.isZero()) {
return new Point(0, 0); return new Point(0, 0);
} else { } else {
var scale = this.dot(point) / point.dot(point); var scale = this.dot(point) / point.dot(point);

View file

@ -1,14 +1,14 @@
Rectangle = Base.extend({ Rectangle = Base.extend({
beans: true, beans: true,
initialize: function() { initialize: function() {
if(arguments.length == 1) { if (arguments.length == 1) {
var rect = arguments[0]; var rect = arguments[0];
this.x = rect.x; this.x = rect.x;
this.y = rect.y; this.y = rect.y;
this.width = rect.width; this.width = rect.width;
this.height = rect.height; this.height = rect.height;
} else if(arguments.length == 2) { } else if (arguments.length == 2) {
if(arguments[1].x !== undefined) { if (arguments[1].x !== undefined) {
// new Rectangle(point1, point2) // new Rectangle(point1, point2)
var point1 = new Point(arguments[0]); var point1 = new Point(arguments[0]);
var point2 = new Point(arguments[1]); var point2 = new Point(arguments[1]);
@ -16,11 +16,11 @@ Rectangle = Base.extend({
this.y = point1.y; this.y = point1.y;
this.width = point2.x - point1.x; this.width = point2.x - point1.x;
this.height = point2.y - point1.y; this.height = point2.y - point1.y;
if(this.width < 0) { if (this.width < 0) {
this.x = point2.x; this.x = point2.x;
this.width = -this.width; this.width = -this.width;
} }
if(this.height < 0) { if (this.height < 0) {
this.y = point2.y; this.y = point2.y;
this.height = -this.height; this.height = -this.height;
} }
@ -33,7 +33,7 @@ Rectangle = Base.extend({
this.width = size.width; this.width = size.width;
this.height = size.height; this.height = size.height;
} }
} else if(arguments.length == 4) { } else if (arguments.length == 4) {
// new Rectangle(x, y, width, height) // new Rectangle(x, y, width, height)
this.x = arguments[0]; this.x = arguments[0];
this.y = arguments[1]; this.y = arguments[1];
@ -221,7 +221,7 @@ Rectangle = Base.extend({
}, },
contains: function(rect) { contains: function(rect) {
if(rect.width !== undefined) { if (rect.width !== undefined) {
return rect.x >= this.x && rect.y >= this.y return rect.x >= this.x && rect.y >= this.y
&& rect.x + rect.width <= this.x + this.width && rect.x + rect.width <= this.x + this.width
&& rect.y + rect.height <= this.y + this.height; && rect.y + rect.height <= this.y + this.height;
@ -287,4 +287,4 @@ Rectangle = Base.extend({
} }
} }
} }
}); });

View file

@ -1,20 +1,20 @@
var Size = Base.extend({ var Size = Base.extend({
initialize: function() { initialize: function() {
if(arguments.length == 2) { if (arguments.length == 2) {
this.width = arguments[0]; this.width = arguments[0];
this.height = arguments[1]; this.height = arguments[1];
} else if(arguments.length == 1) { } else if (arguments.length == 1) {
var first = arguments[0]; 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.width = first.width ? first.width : 0;
this.height = first.height ? first.height : 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.width = first.x ? first.x : 0;
this.height = first.y ? first.y : 0; this.height = first.y ? first.y : 0;
} else if(first.length !== undefined) { } else if (first.length !== undefined) {
this.width = first[0]; this.width = first[0];
this.height = first.length > 1 ? first[1] : 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; this.width = this.height = first;
} else { } else {
this.width = this.height = 0; this.width = this.height = 0;
@ -113,4 +113,4 @@ var Size = Base.extend({
return new Size(Math.random(), Math.random()); return new Size(Math.random(), Math.random());
} }
} }
}); });

View file

@ -1,6 +1,6 @@
Doc = Base.extend({ Doc = Base.extend({
initialize: function(canvas) { initialize: function(canvas) {
if(canvas) { if (canvas) {
this.canvas = canvas; this.canvas = canvas;
this.ctx = this.canvas.getContext('2d'); this.ctx = this.canvas.getContext('2d');
this.size = new Size(canvas.offsetWidth, canvas.offsetHeight); this.size = new Size(canvas.offsetWidth, canvas.offsetHeight);
@ -16,11 +16,11 @@ Doc = Base.extend({
}, },
redraw: function() { redraw: function() {
if(this.canvas) { if (this.canvas) {
this.ctx.clearRect(0, 0, this.size.width, this.size.height); 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); this.layers[i].draw(this.ctx);
} }
} }
} }
}); });

View file

@ -2,8 +2,8 @@ Group = Item.extend({
initialize: function(items) { initialize: function(items) {
this.base(); this.base();
this.children = []; this.children = [];
if(items) { if (items) {
for(var i = 0, l = items.length; i < l; i++) { for (var i = 0, l = items.length; i < l; i++) {
this.appendTop(items[i]); this.appendTop(items[i]);
} }
} }
@ -11,7 +11,7 @@ Group = Item.extend({
}, },
draw: function(ctx) { 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); this.children[i].draw(ctx);
} }
}, },
@ -36,7 +36,7 @@ Group = Item.extend({
setClipped: function(clipped) { setClipped: function(clipped) {
this.clipped = clipped; this.clipped = clipped;
var child = this.firstChild; var child = this.firstChild;
if(child) if (child)
child.setClipMask(clipped); child.setClipMask(clipped);
} }
}); });

View file

@ -16,7 +16,7 @@ Item = Base.extend({
copyTo: function(itemOrDocument) { copyTo: function(itemOrDocument) {
var copy = Base.clone(this); var copy = Base.clone(this);
if(itemOrDocument.layers) { if (itemOrDocument.layers) {
copy.parent = itemOrDocument.activeLayer; copy.parent = itemOrDocument.activeLayer;
itemOrDocument.activeLayer.appendTop(copy); itemOrDocument.activeLayer.appendTop(copy);
} else { } else {
@ -127,7 +127,7 @@ Item = Base.extend({
setClipMask: function(clipMask) { setClipMask: function(clipMask) {
this.clipMask = clipMask; this.clipMask = clipMask;
if(this.clipMask) { if (this.clipMask) {
this.fillColor = null; this.fillColor = null;
this.strokeColor = null; this.strokeColor = null;
} }
@ -137,7 +137,7 @@ Item = Base.extend({
* The first item contained within this item. * The first item contained within this item.
*/ */
getFirstChild: function() { getFirstChild: function() {
if(this.children.length > 0) if (this.children.length > 0)
return this.children[0]; return this.children[0];
}, },
@ -145,7 +145,7 @@ Item = Base.extend({
* The last item contained within this item. * The last item contained within this item.
*/ */
getLastChild: function() { getLastChild: function() {
if(this.children.length > 0) if (this.children.length > 0)
return this.children[this.children.length - 1]; return this.children[this.children.length - 1];
}, },
@ -153,9 +153,9 @@ Item = Base.extend({
* The next item on the same level as this item. * The next item on the same level as this item.
*/ */
getNextSibling: function() { getNextSibling: function() {
if(this.parent) { if (this.parent) {
var index = this.index + 1; var index = this.index + 1;
if(index < this.parent.children.length) if (index < this.parent.children.length)
return this.parent.children[index]; return this.parent.children[index];
} }
}, },
@ -164,9 +164,9 @@ Item = Base.extend({
* The previous item on the same level as this item. * The previous item on the same level as this item.
*/ */
getPreviousSibling: function() { getPreviousSibling: function() {
if(this.parent) { if (this.parent) {
var index = this.index - 1; var index = this.index - 1;
if(index <= 0) if (index <= 0)
return this.parent.children[index]; return this.parent.children[index];
} }
}, },
@ -182,7 +182,7 @@ Item = Base.extend({
* Removes the item from its parent's children list. * Removes the item from its parent's children list.
*/ */
removeFromParent: function() { removeFromParent: function() {
if(this.parent) if (this.parent)
this.parent.children.splice(this.index, 1); this.parent.children.splice(this.index, 1);
this.parent = null; this.parent = null;
}, },
@ -214,7 +214,7 @@ Item = Base.extend({
isEditable: function() { isEditable: function() {
var parent = this; var parent = this;
while(parent) { while(parent) {
if(parent.hidden || parent.locked) if (parent.hidden || parent.locked)
return false; return false;
parent = parent.parent; parent = parent.parent;
} }
@ -350,7 +350,7 @@ Item = Base.extend({
isDescendant: function(item) { isDescendant: function(item) {
var parent = this; var parent = this;
while(parent) { while(parent) {
if(parent == item) if (parent == item)
return true; return true;
parent = parent.parent; parent = parent.parent;
} }
@ -375,10 +375,10 @@ Item = Base.extend({
isAncestor: function(item) { isAncestor: function(item) {
var parent = item; var parent = item;
while(parent) { while(parent) {
if(parent == this) if (parent == this)
return true; return true;
parent = parent.parent; parent = parent.parent;
} }
return false; return false;
} }
}); });

View file

@ -11,8 +11,8 @@ Layer = Item.extend({
}, },
draw: function(ctx) { 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); this.children[i].draw(ctx);
} }
} }
}); });

View file

@ -7,10 +7,10 @@ Path = PathItem.extend({
Line: Base.extend({ Line: Base.extend({
initialize: function() { initialize: function() {
var path = new Path(); var path = new Path();
if(arguments.length == 2) { if (arguments.length == 2) {
path.addSegment(new Segment(arguments[0])); path.addSegment(new Segment(arguments[0]));
path.addSegment(new Segment(arguments[1])); 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[0], arguments[1]));
path.addSegment(Segment.read(arguments[2], arguments[3])); path.addSegment(Segment.read(arguments[2], arguments[3]));
} }
@ -24,7 +24,7 @@ Path = PathItem.extend({
path.closed = true; path.closed = true;
var rectangle = Rectangle.read(arguments); var rectangle = Rectangle.read(arguments);
var corners = ['bottomLeft', 'topLeft', 'topRight', 'bottomRight']; 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]]); path.add(rectangle[corners[i]]);
} }
return path; return path;
@ -37,7 +37,7 @@ Path = PathItem.extend({
initialize: function() { initialize: function() {
var path = new Path(); var path = new Path();
var rect, size; var rect, size;
if(arguments.length == 2) { if (arguments.length == 2) {
rect = new Rectangle(arguments[0]); rect = new Rectangle(arguments[0]);
size = new Size(arguments[1]); size = new Size(arguments[1]);
} else { } else {
@ -84,7 +84,7 @@ Path = PathItem.extend({
var rect = Rectangle.read(arguments); var rect = Rectangle.read(arguments);
var topLeft = rect.topLeft; var topLeft = rect.topLeft;
var size = new Size(rect.width, rect.height); 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]]); var segment = Segment.read([segments[i]]);
segment.handleIn = segment.handleIn.multiply(size); segment.handleIn = segment.handleIn.multiply(size);
segment.handleOut = segment.handleOut.multiply(size); segment.handleOut = segment.handleOut.multiply(size);
@ -101,7 +101,7 @@ Path = PathItem.extend({
initialize: function() { initialize: function() {
var path = new Path(); var path = new Path();
var center, radius; var center, radius;
if(arguments.length == 3) { if (arguments.length == 3) {
center = new Point(arguments[0], arguments[1]); center = new Point(arguments[0], arguments[1]);
radius = arguments[2]; radius = arguments[2];
} else { } else {
@ -128,4 +128,4 @@ Path = PathItem.extend({
} }
}) })
} }
}); });

View file

@ -51,7 +51,7 @@ PathItem = Item.extend(new function() {
if (!segments || segments.length === undefined if (!segments || segments.length === undefined
|| typeof segments[0] != 'object') || typeof segments[0] != 'object')
segments = arguments; 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])); this.addSegment(new Segment(segments[i]));
}, },
@ -156,7 +156,7 @@ PathItem = Item.extend(new function() {
add: function() { add: function() {
var segment = Segment.read(arguments); var segment = Segment.read(arguments);
if(segment) if (segment)
this.addSegment(segment); this.addSegment(segment);
}, },
@ -180,13 +180,13 @@ PathItem = Item.extend(new function() {
moveTo: function() { moveTo: function() {
var segment = Segment.read(arguments); var segment = Segment.read(arguments);
if(segment && !this._segments.length) if (segment && !this._segments.length)
this.addSegment(segment); this.addSegment(segment);
}, },
lineTo: function() { lineTo: function() {
var segment = Segment.read(arguments); var segment = Segment.read(arguments);
if(segment && this._segments.length) if (segment && this._segments.length)
this.addSegment(segment); this.addSegment(segment);
}, },
@ -230,7 +230,7 @@ PathItem = Item.extend(new function() {
curveTo: function(through, to, parameter) { curveTo: function(through, to, parameter) {
through = new Point(through); through = new Point(through);
to = new Point(to); to = new Point(to);
if(parameter == null) if (parameter == null)
parameter = 0.5; parameter = 0.5;
var current = this.currentSegment.point; var current = this.currentSegment.point;
// handle = (through - (1 - t)^2 * current - t^2 * to) / (2 * (1 - t) * t) // 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; var through, to;
// Get the start point: // Get the start point:
var current = this.currentSegment; var current = this.currentSegment;
if(arguments[1] && typeof arguments[1] != 'boolean') { if (arguments[1] && typeof arguments[1] != 'boolean') {
through = new Point(arguments[0]); through = new Point(arguments[0]);
to = new Point(arguments[1]); to = new Point(arguments[1]);
} else { } else {
if(clockwise === null) if (clockwise === null)
clockwise = true; clockwise = true;
var middle = current.point.add(to).divide(2); var middle = current.point.add(to).divide(2);
var step = middle.subtract(current.point); var step = middle.subtract(current.point);
@ -337,7 +337,7 @@ PathItem = Item.extend(new function() {
lineBy: function() { lineBy: function() {
var vector = Point.read(arguments); var vector = Point.read(arguments);
if(vector) { if (vector) {
var current = this.currentSegment; var current = this.currentSegment;
this.lineTo(current.point.add(vector)); this.lineTo(current.point.add(vector));
} }
@ -457,23 +457,23 @@ PathItem = Item.extend(new function() {
}, },
setCtxStyles: function(ctx) { setCtxStyles: function(ctx) {
for(var i in styleNames) { for (var i in styleNames) {
var style; var style;
if(style = this[i]) if (style = this[i])
ctx[styleNames[i]] = style; ctx[styleNames[i]] = style;
} }
}, },
draw: function(ctx) { draw: function(ctx) {
if(!this.visible) return; if (!this.visible) return;
ctx.beginPath(); ctx.beginPath();
var cp1; 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 segment = this._segments[i];
var point = segment.point; var point = segment.point;
var handleIn = segment.handleIn ? segment.handleIn.add(point) : point; var handleIn = segment.handleIn ? segment.handleIn.add(point) : point;
var handleOut = segment.handleOut ? segment.handleOut.add(point) : point; var handleOut = segment.handleOut ? segment.handleOut.add(point) : point;
if(i == 0) { if (i == 0) {
ctx.moveTo(point.x, point.y); ctx.moveTo(point.x, point.y);
} else { } else {
ctx.bezierCurveTo(cp1.x, cp1.y, handleIn.x, handleIn.y, ctx.bezierCurveTo(cp1.x, cp1.y, handleIn.x, handleIn.y,
@ -481,7 +481,7 @@ PathItem = Item.extend(new function() {
} }
cp1 = handleOut; cp1 = handleOut;
} }
if(this.closed && this._segments.length > 1) { if (this.closed && this._segments.length > 1) {
var segment = this._segments[0]; var segment = this._segments[0];
var point = segment.point; var point = segment.point;
var handleIn = segment.handleIn ? segment.handleIn.add(point) : point; var handleIn = segment.handleIn ? segment.handleIn.add(point) : point;
@ -490,8 +490,8 @@ PathItem = Item.extend(new function() {
ctx.closePath(); ctx.closePath();
} }
this.setCtxStyles(ctx); this.setCtxStyles(ctx);
if(this.fillColor) ctx.fill(); if (this.fillColor) ctx.fill();
if(this.strokeColor) ctx.stroke(); if (this.strokeColor) ctx.stroke();
} }
}; };
}); });

View file

@ -1,29 +1,29 @@
Segment = Base.extend({ Segment = Base.extend({
initialize: function() { initialize: function() {
if(arguments.length == 0) { if (arguments.length == 0) {
this.point = new Point(); this.point = new Point();
} else if(arguments.length == 1) { } else if (arguments.length == 1) {
if(arguments[0].point) { if (arguments[0].point) {
var segment = arguments[0]; var segment = arguments[0];
this.point = new Point(segment.point); this.point = new Point(segment.point);
if(segment.handleIn) if (segment.handleIn)
this.handleIn = new Point(segment.handleIn); this.handleIn = new Point(segment.handleIn);
if(segment.handleOut) if (segment.handleOut)
this.handleOut = new Point(segment.handleOut); this.handleOut = new Point(segment.handleOut);
} else { } else {
this.point = new Point(arguments[0]); this.point = new Point(arguments[0]);
} }
} else if(arguments.length < 6) { } else if (arguments.length < 6) {
if(arguments.length == 2 && !arguments[1].x) { if (arguments.length == 2 && !arguments[1].x) {
this.point = new Point(arguments[0], arguments[1]); this.point = new Point(arguments[0], arguments[1]);
} else { } else {
this.point = new Point(arguments[0]); this.point = new Point(arguments[0]);
if(arguments[1]) if (arguments[1])
this.handleIn = new Point(arguments[1]); this.handleIn = new Point(arguments[1]);
if(arguments[2]) if (arguments[2])
this.handleOut = new Point(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.point = new Point(arguments[0], arguments[1]);
this.handleIn = new Point(arguments[2], arguments[3]); this.handleIn = new Point(arguments[2], arguments[3]);
this.handleOut = new Point(arguments[4], arguments[5]); this.handleOut = new Point(arguments[4], arguments[5]);
@ -36,7 +36,7 @@ Segment = Base.extend({
// TODO: // TODO:
// insert: function() { // insert: function() {
// if(this._segments && this._segments.path) { // if (this._segments && this._segments.path) {
// var path = this._segments.path; // var path = this._segments.path;
// path.checkValid(); // path.checkValid();
// //
@ -74,8 +74,8 @@ Segment = Base.extend({
getIndex: function() { getIndex: function() {
// TODO: Cache and update indices instead of searching? // TODO: Cache and update indices instead of searching?
var segments = this.path._segments; var segments = this.path._segments;
for(var i = 0, l = segments.length; i < l; i++) { for (var i = 0, l = segments.length; i < l; i++) {
if(segments[i] == this) if (segments[i] == this)
return i; return i;
} }
}, },
@ -86,7 +86,7 @@ Segment = Base.extend({
// todo // todo
// getCurve: function() { // getCurve: function() {
// if(this._segments && this._segments.path) { // if (this._segments && this._segments.path) {
// var curves = this._segments.path.getCurves(); // var curves = this._segments.path.getCurves();
// // The curves list handles closing curves, so the curves.size // // The curves list handles closing curves, so the curves.size
// // is adjusted accordingly. just check to be in the boundaries here: // // is adjusted accordingly. just check to be in the boundaries here:
@ -121,7 +121,7 @@ Segment = Base.extend({
}, },
remove: function() { remove: function() {
if(this.path && this.path._segments) if (this.path && this.path._segments)
return this.path._segments.splice(this.index, 1); return this.path._segments.splice(this.index, 1);
return false; return false;
}, },
@ -144,4 +144,4 @@ Segment = Base.extend({
} }
} }
} }
}) });

View file

@ -43,4 +43,4 @@ Tool = ToolHandler.extend({
getDocument: function() { getDocument: function() {
return this._document; return this._document;
} }
}); });

View file

@ -7,7 +7,7 @@ ToolHandler = Base.extend({
this.firstMove = true; this.firstMove = true;
this.count = 0; this.count = 0;
this.downCount = 0; this.downCount = 0;
for(var i in handlers) { for (var i in handlers) {
this[i] = handlers[i]; this[i] = handlers[i];
} }
}, },
@ -105,7 +105,7 @@ ToolHandler = Base.extend({
switch (type) { switch (type) {
case 'MOUSE_DOWN': case 'MOUSE_DOWN':
this.updateEvent(type, pt, null, null, true, false, false); this.updateEvent(type, pt, null, null, true, false, false);
if(this.onMouseDown) if (this.onMouseDown)
this.onMouseDown(new ToolEvent(this, type, modifiers)); this.onMouseDown(new ToolEvent(this, type, modifiers));
break; break;
case 'MOUSE_DRAG': case 'MOUSE_DRAG':
@ -121,7 +121,7 @@ ToolHandler = Base.extend({
this.matchMaxDistance = false; this.matchMaxDistance = false;
while (this.updateEvent(type, pt, this.minDistance, while (this.updateEvent(type, pt, this.minDistance,
this.maxDistance, false, this.needsChange, this.matchMaxDistance)) { this.maxDistance, false, this.needsChange, this.matchMaxDistance)) {
if(this.onMouseDrag) if (this.onMouseDrag)
this.onMouseDrag(new ToolEvent(this, type, modifiers)); this.onMouseDrag(new ToolEvent(this, type, modifiers));
this.needsChange = true; this.needsChange = true;
this.matchMaxDistance = true; this.matchMaxDistance = true;
@ -132,12 +132,12 @@ ToolHandler = Base.extend({
// mouse drag first, then mouse up. // mouse drag first, then mouse up.
if ((this.point.x != pt.x || this.point.y != pt.y) && this.updateEvent( if ((this.point.x != pt.x || this.point.y != pt.y) && this.updateEvent(
'MOUSE_DRAG', pt, this.minDistance, this.maxDistance, false, false, false)) { 'MOUSE_DRAG', pt, this.minDistance, this.maxDistance, false, false, false)) {
if(this.onMouseDrag) if (this.onMouseDrag)
this.onMouseDrag(new ToolEvent(this, type, modifiers)); this.onMouseDrag(new ToolEvent(this, type, modifiers));
} }
this.updateEvent(type, pt, null, this.maxDistance, false, this.updateEvent(type, pt, null, this.maxDistance, false,
false, false); false, false);
if(this.onMouseUp) if (this.onMouseUp)
this.onMouseUp(new ToolEvent(this, type, modifiers)); this.onMouseUp(new ToolEvent(this, type, modifiers));
// Start with new values for TRACK_CURSOR // Start with new values for TRACK_CURSOR
this.updateEvent(type, pt, null, null, true, false, false); this.updateEvent(type, pt, null, null, true, false, false);
@ -146,11 +146,11 @@ ToolHandler = Base.extend({
case 'MOUSE_MOVE': case 'MOUSE_MOVE':
while (this.updateEvent(type, pt, this.minDistance, while (this.updateEvent(type, pt, this.minDistance,
this.maxDistance, this.firstMove, true, false)) { this.maxDistance, this.firstMove, true, false)) {
if(this.onMouseMove) if (this.onMouseMove)
this.onMouseMove(new ToolEvent(this, type, modifiers)); this.onMouseMove(new ToolEvent(this, type, modifiers));
this.firstMove = false; this.firstMove = false;
} }
break; break;
} }
} }
}); });

View file

@ -1004,8 +1004,8 @@ QUnit.equiv = function () {
parents.push(a); parents.push(a);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
loop = false; loop = false;
for(j=0;j<parents.length;j++){ for (j=0;j<parents.length;j++){
if(parents[j] === a[i]){ if (parents[j] === a[i]){
loop = true;//dont rewalk array 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 for (i in a) { // be strict: don't ensures hasOwnProperty and go deep
loop = false; loop = false;
for(j=0;j<parents.length;j++){ for (j=0;j<parents.length;j++){
if(parents[j] === a[i]) if (parents[j] === a[i])
loop = true; //don't go down the same path twice loop = true; //don't go down the same path twice
} }
aProperties.push(i); // collect a's properties aProperties.push(i); // collect a's properties

View file

@ -1,7 +1,7 @@
function compareSegmentLists(list1, list2) { function compareSegmentLists(list1, list2) {
equals(list1.length, list2.length, 'segment count'); equals(list1.length, list2.length, 'segment count');
if(list1.length == list2.length) { if (list1.length == list2.length) {
for(var i = 0, l = list1.length; i < l; i++) { for (var i = 0, l = list1.length; i < l; i++) {
compareSegments(list1[i], list2[i]); compareSegments(list1[i], list2[i]);
} }
} }
@ -12,9 +12,9 @@ function compareSegments(segment1, segment2) {
// all handles all the time. // all handles all the time.
segment2 = Segment.read([segment2]); segment2 = Segment.read([segment2]);
var points = ['point', 'handleIn', 'handleOut']; 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]); 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]); comparePoints(segment1[points[i]], segment2[points[i]], points[i]);
} }
} }

View file

@ -1,29 +1,29 @@
module('Point'); module('Point');
test('new Point(10, 20)', function(){ test('new Point(10, 20)', function() {
var point = new Point(10, 20); var point = new Point(10, 20);
equals(point.x, 10); equals(point.x, 10);
equals(point.y, 20); equals(point.y, 20);
}); });
test('new Point([10, 20])', function(){ test('new Point([10, 20])', function() {
var point = new Point([10, 20]); var point = new Point([10, 20]);
equals(point.x, 10); equals(point.x, 10);
equals(point.y, 20); 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}); var point = new Point({x: 10, y: 20});
equals(point.x, 10); equals(point.x, 10);
equals(point.y, 20); 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)); var point = new Point(new Size(10, 20));
equals(point.x, 10); equals(point.x, 10);
equals(point.y, 20); 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}); var point = new Point({width: 10, height: 20});
equals(point.x, 10); equals(point.x, 10);
equals(point.y, 20); equals(point.y, 20);
@ -31,36 +31,36 @@ test('new Point({ width: 10, height: 20})', function(){
module('Point vector operations'); module('Point vector operations');
test('normalize(length)', function(){ test('normalize(length)', function() {
var point = new Point(0, 10).normalize(20) var point = new Point(0, 10).normalize(20)
equals(point.x, 0); equals(point.x, 0);
equals(point.y, 20); equals(point.y, 20);
}); });
test('set length', function(){ test('set length', function() {
var point = new Point(0, 10); var point = new Point(0, 10);
point.length = 20; point.length = 20;
equals(point.x, 0); equals(point.x, 0);
equals(point.y, 20); equals(point.y, 20);
}); });
test('get angle', function(){ test('get angle', function() {
var angle = new Point(0, 10).angle; var angle = new Point(0, 10).angle;
equals(angle, 90); equals(angle, 90);
}); });
test('getAngle(point)', function(){ test('getAngle(point)', function() {
var angle = new Point(0, 10).getAngle([10, 10]); var angle = new Point(0, 10).getAngle([10, 10]);
equals(Math.round(angle), 45); equals(Math.round(angle), 45);
}); });
test('rotate(degrees)', function(){ test('rotate(degrees)', function() {
var point = new Point(100, 50).rotate(90); var point = new Point(100, 50).rotate(90);
equals(Math.round(point.x), -50); equals(Math.round(point.x), -50);
equals(Math.round(point.y), 100); equals(Math.round(point.y), 100);
}); });
test('set angle', function(){ test('set angle', function() {
var point = new Point(10, 20); var point = new Point(10, 20);
point.angle = 92; point.angle = 92;
equals(point.angle, 92); equals(point.angle, 92);

View file

@ -1,49 +1,49 @@
module('Segment'); module('Segment');
test('new Segment(point)', function(){ test('new Segment(point)', function() {
var segment = new Segment(new Point(10, 10)); var segment = new Segment(new Point(10, 10));
var expected = { point: { x: 10, y: 10 } }; var expected = { point: { x: 10, y: 10 } };
compareSegments(segment, expected); compareSegments(segment, expected);
}); });
test('new Segment(x, y)', function(){ test('new Segment(x, y)', function() {
var segment = new Segment(10, 10); var segment = new Segment(10, 10);
var expected = { point: { x: 10, y: 10 } }; var expected = { point: { x: 10, y: 10 } };
compareSegments(segment, expected); 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 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 } }; var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } };
compareSegments(segment, expected); 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 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 } }; var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } };
compareSegments(segment, expected); 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 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 } }; var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } };
compareSegments(segment, expected); 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)); var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
segment = segment.reverse(); segment = segment.reverse();
var expected = { point: { x: 10, y: 10 }, handleIn: { x: 15, y: 15 }, handleOut: { x: 5, y: 5 } }; var expected = { point: { x: 10, y: 10 }, handleIn: { x: 15, y: 15 }, handleOut: { x: 5, y: 5 } };
compareSegments(segment, expected); 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 segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
var clone = segment.clone(); var clone = segment.clone();
equals(segment == clone, false); equals(segment == clone, false);
compareSegments(segment, clone); compareSegments(segment, clone);
}); });
test('segment.remove()', function(){ test('segment.remove()', function() {
var doc = new Doc(); var doc = new Doc();
var path = new Path([10, 10], [5, 5], [10, 10]); var path = new Path([10, 10], [5, 5], [10, 10]);
path.segments[1].remove(); path.segments[1].remove();

View file

@ -1,29 +1,29 @@
module('Size'); module('Size');
test('new Size(10, 20)', function(){ test('new Size(10, 20)', function() {
var size = new Size(10, 20); var size = new Size(10, 20);
equals(size.width, 10); equals(size.width, 10);
equals(size.height, 20); equals(size.height, 20);
}); });
test('new Size([10, 20])', function(){ test('new Size([10, 20])', function() {
var size = new Size([10, 20]); var size = new Size([10, 20]);
equals(size.width, 10); equals(size.width, 10);
equals(size.height, 20); 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}); var size = new Size({width: 10, height: 20});
equals(size.width, 10); equals(size.width, 10);
equals(size.height, 20); 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)); var size = new Size(new Point(10, 20));
equals(size.width, 10); equals(size.width, 10);
equals(size.height, 20); 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}); var size = new Size({x: 10, y: 20});
equals(size.width, 10); equals(size.width, 10);
equals(size.height, 20); equals(size.height, 20);