diff --git a/src/color/Color.js b/src/color/Color.js index 155e926a..187ed759 100644 --- a/src/color/Color.js +++ b/src/color/Color.js @@ -161,8 +161,8 @@ var Color = this.Color = Base.extend(new function() { * @return {@true if the GrayColor is the same} */ equals: function(color) { - if (color && color._colorType == this._colorType) { - for (var i = 0, l = this._components; i < l; i++) { + if (color && color._colorType === this._colorType) { + for (var i = 0, l = this._components.length; i < l; i++) { var component = '_' + this._components[i]; if (this[component] !== color[component]) return false; diff --git a/src/item/PathStyle.js b/src/item/PathStyle.js index 07d93ecb..51867351 100644 --- a/src/item/PathStyle.js +++ b/src/item/PathStyle.js @@ -85,6 +85,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() { } else if (style != childStyle) { // If there is another item with a different style, // the style is not defined: + // TODO: Port back to Sg (currently returns null) return undefined; } } diff --git a/src/path/Path.js b/src/path/Path.js index ce7a7456..eeaa74a2 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -182,12 +182,40 @@ var Path = this.Path = PathItem.extend({ // TODO: Port back support for adding multiple segments at once to Sg add: function(segment1 /*, segment2, ... */) { - return this._add(Segment.readAll(arguments), true); + return arguments.length > 1 && typeof segment1 != 'number' + // addSegments + ? this._add(Segment.readAll(arguments), true) + // addSegment + : this._add([ Segment.read(arguments) ], true)[0]; }, // TODO: Port back support for adding multiple segments at once to Sg insert: function(index, segment1 /*, segment2, ... */) { - return this._add(Segment.readAll(arguments, 1), true, index); + return arguments.length > 2 && typeof segment1 != 'number' + // insertSegments + ? this._add(Segment.readAll(arguments, 1), true, index) + // insertSegment + : this._add([ Segment.read(arguments, 1) ], true, index)[0]; + }, + + // TODO: Port back to Sg + addSegment: function(segment) { + return this._add([ Segment.read(arguments) ], true)[0]; + }, + + // TODO: Port back to Sg + insertSegment: function(index, segment) { + return this._add([ Segment.read(arguments, 1) ], true, index)[0]; + }, + + // TODO: Port back to Sg + addSegments: function(segments) { + return this._add(Segment.readAll(segments), true); + }, + + // TODO: Port back to Sg + insertSegments: function(index, segments) { + return this._add(Segment.readAll(segments), true, index); }, // TODO: Port back to Sg diff --git a/test/lib/helpers.js b/test/lib/helpers.js index ca204c62..1e5b288a 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -7,17 +7,21 @@ function compareNumbers(number1, number2, message) { } function comparePoints(point1, point2, message) { - compareNumbers(point1.x, point2.x, message ? message + ' x' : undefined); - compareNumbers(point1.y, point2.y, message ? message + ' y' : undefined); + compareNumbers(point1.x, point2.x, + (message || '') + ' x'); + compareNumbers(point1.y, point2.y, + (message || '') + ' y'); } function compareRectangles(rect1, rect2, message) { - compareNumbers(rect1.x, rect2.x, message ? message + ' x' : undefined); - compareNumbers(rect1.y, rect2.y, message ? message + ' y' : undefined); + compareNumbers(rect1.x, rect2.x, + (message || '') + ' x'); + compareNumbers(rect1.y, rect2.y, + (message || '') + ' y'); compareNumbers(rect1.width, rect2.width, - message ? message + ' width' : undefined); + (message || '') + ' width'); compareNumbers(rect1.height, rect2.height, - message ? message + ' height' : undefined); + (message || '') + ' height'); } function compareRGBColors(color1, color2, message) { @@ -25,13 +29,13 @@ function compareRGBColors(color1, color2, message) { color2 = new RGBColor(color2); compareNumbers(color1.red, color2.red, - message ? message + ' red' : undefined); + (message || '') + ' red'); compareNumbers(color1.green, color2.green, - message ? message + ' green' : undefined); + (message || '') + ' green'); compareNumbers(color1.blue, color2.blue, - message ? message + ' blue' : undefined); + (message || '') + ' blue'); compareNumbers(color1.alpha, color2.alpha, - message ? message + ' alpha' : undefined); + (message || '') + ' alpha'); } function compareHSBColors(color1, color2, message) { @@ -39,13 +43,13 @@ function compareHSBColors(color1, color2, message) { color2 = new HSBColor(color2); compareNumbers(color1.hue, color2.hue, - message ? message + ' hue' : undefined); + (message || '') + ' hue'); compareNumbers(color1.saturation, color2.saturation, - message ? message + ' saturation' : undefined); + (message || '') + ' saturation'); compareNumbers(color1.brightness, color2.brightness, - message ? message + ' brightness' : undefined); + (message || '') + ' brightness'); compareNumbers(color1.alpha, color2.alpha, - message ? message + ' alpha' : undefined); + (message || '') + ' alpha'); } function compareGrayColors(color1, color2, message) { @@ -53,5 +57,5 @@ function compareGrayColors(color1, color2, message) { color2 = new GrayColor(color2); compareNumbers(color1.gray, color2.gray, - message ? message + ' gray' : undefined); + (message || '') + ' gray'); } \ No newline at end of file diff --git a/test/tests/Path.js b/test/tests/Path.js index 6a621506..f7306540 100644 --- a/test/tests/Path.js +++ b/test/tests/Path.js @@ -3,46 +3,46 @@ module('Path'); test('path.join(path)', function() { var doc = new Document(); var path = new Path(); - path.add([0, 0]); - path.add([10, 0]); + path.add(0, 0); + path.add(10, 0); var path2 = new Path(); - path2.add([10, 0]); - path2.add([20, 10]); + path2.add(10, 0); + path2.add(20, 10); path.join(path2); equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }'); equals(doc.activeLayer.children.length, 1); var path = new Path(); - path.add([0, 0]); - path.add([10, 0]); + path.add(0, 0); + path.add(10, 0); var path2 = new Path(); - path2.add([20, 10]); - path2.add([10, 0]); + path2.add(20, 10); + path2.add(10, 0); path.join(path2); equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }'); var path = new Path(); - path.add([0, 0]); - path.add([10, 0]); + path.add(0, 0); + path.add(10, 0); var path2 = new Path(); - path2.add([30, 10]); - path2.add([40, 0]); + path2.add(30, 10); + path2.add(40, 0); path.join(path2); equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 30, y: 10 } },{ point: { x: 40, y: 0 } }'); var path = new Path(); - path.add([0, 0]); - path.add([10, 0]); - path.add([20, 10]); + path.add(0, 0); + path.add(10, 0); + path.add(20, 10); var path2 = new Path(); - path2.add([0, 0]); - path2.add([10, 5]); - path2.add([20, 10]); + path2.add(0, 0); + path2.add(10, 5); + path2.add(20, 10); path.join(path2); @@ -53,10 +53,10 @@ test('path.join(path)', function() { test('path.remove()', function() { var doc = new Document(); var path = new Path(); - path.add([0, 0]); - path.add([10, 0]); - path.add([20, 0]); - path.add([30, 0]); + path.add(0, 0); + path.add(10, 0); + path.add(20, 0); + path.add(30, 0); path.removeSegment(0); equals(path.segments.length, 3); diff --git a/test/tests/PathStyle.js b/test/tests/PathStyle.js index 5c1e6c7b..5b7ba8f9 100644 --- a/test/tests/PathStyle.js +++ b/test/tests/PathStyle.js @@ -4,12 +4,12 @@ test('currentStyle', function() { var doc = new Document(); doc.currentStyle.fillColor = 'black'; var path = new Path(); - compareRGBColors(path.fillColor, 'black'); + compareRGBColors(path.fillColor, 'black', 'path.fillColor'); // When changing the current style of the document, the style of // paths created using document.currentStyle should not change. doc.currentStyle.fillColor = 'red'; - compareRGBColors(path.fillColor, 'black'); + compareRGBColors(path.fillColor, 'black', 'path.fillColor'); }); test('setting currentStyle to an object', function() { @@ -19,8 +19,8 @@ test('setting currentStyle to an object', function() { strokeColor: 'green' }; var path = new Path(); - compareRGBColors(path.fillColor, 'red'); - compareRGBColors(path.strokeColor, 'green'); + compareRGBColors(path.fillColor, 'red', 'path.fillColor'); + compareRGBColors(path.strokeColor, 'green', 'path.strokeColor'); }); test('setting path styles to an object', function() { @@ -30,8 +30,8 @@ test('setting path styles to an object', function() { fillColor: 'red', strokeColor: 'green' }; - compareRGBColors(path.fillColor, 'red'); - compareRGBColors(path.strokeColor, 'green'); + compareRGBColors(path.fillColor, 'red', 'path.fillColor'); + compareRGBColors(path.strokeColor, 'green', 'path.strokeColor'); }); test('setting group styles to an object', function() { @@ -43,8 +43,8 @@ test('setting group styles to an object', function() { fillColor: 'red', strokeColor: 'green' }; - compareRGBColors(path.fillColor, 'red'); - compareRGBColors(path.strokeColor, 'green'); + compareRGBColors(path.fillColor, 'red', 'path.fillColor'); + compareRGBColors(path.strokeColor, 'green', 'path.strokeColor'); }); test('getting group styles', function() { @@ -54,7 +54,7 @@ test('getting group styles', function() { path.fillColor = 'red'; group.appendTop(path); - compareRGBColors(group.fillColor, 'red'); + compareRGBColors(group.fillColor, 'red', 'group.fillColor'); var secondPath = new Path(); secondPath.fillColor = 'black'; @@ -62,11 +62,11 @@ test('getting group styles', function() { // the group now contains two paths with different fillColors and therefore // should return null: - equals(group.fillColor, null); + equals(group.fillColor, null, 'group.fillColor'); //If we remove the first path, it should now return 'black': group.children[0].remove(); - compareRGBColors(group.fillColor, 'black'); + compareRGBColors(group.fillColor, 'black', 'group.fillColor'); }); test('setting group styles', function() { @@ -86,11 +86,11 @@ test('setting group styles', function() { // the paths contained in the group should now both have their fillColor // set to black: - compareRGBColors(path.fillColor, 'black'); - compareRGBColors(secondPath.fillColor, 'black'); + compareRGBColors(path.fillColor, 'black', 'path.fillColor'); + compareRGBColors(secondPath.fillColor, 'black', 'secondPath.fillColor'); // The second path still has its strokeColor set to red: - compareRGBColors(secondPath.strokeColor, 'red'); + compareRGBColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor'); }); test('setting group styles 2', function() { @@ -100,31 +100,31 @@ test('setting group styles 2', function() { path.fillColor = 'red'; group.appendTop(path); - compareRGBColors(group.fillColor, 'red'); + compareRGBColors(group.fillColor, 'red', 'group.fillColor'); var secondPath = new Path(); secondPath.fillColor = 'blue'; secondPath.strokeColor = 'red'; group.appendTop(secondPath); - compareRGBColors(secondPath.fillColor, 'blue'); - compareRGBColors(secondPath.strokeColor, 'red'); + compareRGBColors(secondPath.fillColor, 'blue', 'secondPath.fillColor'); + compareRGBColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor'); // By appending a path with a different fillcolor, - // the group's fillColor should return null: - equals(group.fillColor, null); + // the group's fillColor should return undefined: + equals(group.fillColor, undefined, 'group.fillColor'); // But, both paths have a red strokeColor, so: - compareRGBColors(group.strokeColor, 'red'); + compareRGBColors(group.strokeColor, 'red', 'group.strokeColor'); // Change the fill color of the group's style: group.style.fillColor = 'black'; // the paths contained in the group should now both have their fillColor // set to black: - compareRGBColors(path.fillColor, 'black'); - compareRGBColors(secondPath.fillColor, 'black'); + compareRGBColors(path.fillColor, 'black', 'path.fillColor'); + compareRGBColors(secondPath.fillColor, 'black', 'secondPath.fillColor'); // The second path still has its strokeColor set to red: - compareRGBColors(secondPath.strokeColor, 'red'); + compareRGBColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor'); }); \ No newline at end of file