mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Merge remote branch 'origin/master'
This commit is contained in:
commit
f806c68dc0
6 changed files with 97 additions and 64 deletions
|
@ -161,8 +161,8 @@ var Color = this.Color = Base.extend(new function() {
|
||||||
* @return {@true if the GrayColor is the same}
|
* @return {@true if the GrayColor is the same}
|
||||||
*/
|
*/
|
||||||
equals: function(color) {
|
equals: function(color) {
|
||||||
if (color && color._colorType == this._colorType) {
|
if (color && color._colorType === this._colorType) {
|
||||||
for (var i = 0, l = this._components; i < l; i++) {
|
for (var i = 0, l = this._components.length; i < l; i++) {
|
||||||
var component = '_' + this._components[i];
|
var component = '_' + this._components[i];
|
||||||
if (this[component] !== color[component])
|
if (this[component] !== color[component])
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -85,6 +85,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() {
|
||||||
} else if (style != childStyle) {
|
} else if (style != childStyle) {
|
||||||
// If there is another item with a different style,
|
// If there is another item with a different style,
|
||||||
// the style is not defined:
|
// the style is not defined:
|
||||||
|
// TODO: Port back to Sg (currently returns null)
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,12 +182,40 @@ var Path = this.Path = PathItem.extend({
|
||||||
|
|
||||||
// TODO: Port back support for adding multiple segments at once to Sg
|
// TODO: Port back support for adding multiple segments at once to Sg
|
||||||
add: function(segment1 /*, segment2, ... */) {
|
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
|
// TODO: Port back support for adding multiple segments at once to Sg
|
||||||
insert: function(index, segment1 /*, segment2, ... */) {
|
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
|
// TODO: Port back to Sg
|
||||||
|
|
|
@ -7,17 +7,21 @@ function compareNumbers(number1, number2, message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function comparePoints(point1, point2, message) {
|
function comparePoints(point1, point2, message) {
|
||||||
compareNumbers(point1.x, point2.x, message ? message + ' x' : undefined);
|
compareNumbers(point1.x, point2.x,
|
||||||
compareNumbers(point1.y, point2.y, message ? message + ' y' : undefined);
|
(message || '') + ' x');
|
||||||
|
compareNumbers(point1.y, point2.y,
|
||||||
|
(message || '') + ' y');
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareRectangles(rect1, rect2, message) {
|
function compareRectangles(rect1, rect2, message) {
|
||||||
compareNumbers(rect1.x, rect2.x, message ? message + ' x' : undefined);
|
compareNumbers(rect1.x, rect2.x,
|
||||||
compareNumbers(rect1.y, rect2.y, message ? message + ' y' : undefined);
|
(message || '') + ' x');
|
||||||
|
compareNumbers(rect1.y, rect2.y,
|
||||||
|
(message || '') + ' y');
|
||||||
compareNumbers(rect1.width, rect2.width,
|
compareNumbers(rect1.width, rect2.width,
|
||||||
message ? message + ' width' : undefined);
|
(message || '') + ' width');
|
||||||
compareNumbers(rect1.height, rect2.height,
|
compareNumbers(rect1.height, rect2.height,
|
||||||
message ? message + ' height' : undefined);
|
(message || '') + ' height');
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareRGBColors(color1, color2, message) {
|
function compareRGBColors(color1, color2, message) {
|
||||||
|
@ -25,13 +29,13 @@ function compareRGBColors(color1, color2, message) {
|
||||||
color2 = new RGBColor(color2);
|
color2 = new RGBColor(color2);
|
||||||
|
|
||||||
compareNumbers(color1.red, color2.red,
|
compareNumbers(color1.red, color2.red,
|
||||||
message ? message + ' red' : undefined);
|
(message || '') + ' red');
|
||||||
compareNumbers(color1.green, color2.green,
|
compareNumbers(color1.green, color2.green,
|
||||||
message ? message + ' green' : undefined);
|
(message || '') + ' green');
|
||||||
compareNumbers(color1.blue, color2.blue,
|
compareNumbers(color1.blue, color2.blue,
|
||||||
message ? message + ' blue' : undefined);
|
(message || '') + ' blue');
|
||||||
compareNumbers(color1.alpha, color2.alpha,
|
compareNumbers(color1.alpha, color2.alpha,
|
||||||
message ? message + ' alpha' : undefined);
|
(message || '') + ' alpha');
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareHSBColors(color1, color2, message) {
|
function compareHSBColors(color1, color2, message) {
|
||||||
|
@ -39,13 +43,13 @@ function compareHSBColors(color1, color2, message) {
|
||||||
color2 = new HSBColor(color2);
|
color2 = new HSBColor(color2);
|
||||||
|
|
||||||
compareNumbers(color1.hue, color2.hue,
|
compareNumbers(color1.hue, color2.hue,
|
||||||
message ? message + ' hue' : undefined);
|
(message || '') + ' hue');
|
||||||
compareNumbers(color1.saturation, color2.saturation,
|
compareNumbers(color1.saturation, color2.saturation,
|
||||||
message ? message + ' saturation' : undefined);
|
(message || '') + ' saturation');
|
||||||
compareNumbers(color1.brightness, color2.brightness,
|
compareNumbers(color1.brightness, color2.brightness,
|
||||||
message ? message + ' brightness' : undefined);
|
(message || '') + ' brightness');
|
||||||
compareNumbers(color1.alpha, color2.alpha,
|
compareNumbers(color1.alpha, color2.alpha,
|
||||||
message ? message + ' alpha' : undefined);
|
(message || '') + ' alpha');
|
||||||
}
|
}
|
||||||
|
|
||||||
function compareGrayColors(color1, color2, message) {
|
function compareGrayColors(color1, color2, message) {
|
||||||
|
@ -53,5 +57,5 @@ function compareGrayColors(color1, color2, message) {
|
||||||
color2 = new GrayColor(color2);
|
color2 = new GrayColor(color2);
|
||||||
|
|
||||||
compareNumbers(color1.gray, color2.gray,
|
compareNumbers(color1.gray, color2.gray,
|
||||||
message ? message + ' gray' : undefined);
|
(message || '') + ' gray');
|
||||||
}
|
}
|
|
@ -3,46 +3,46 @@ module('Path');
|
||||||
test('path.join(path)', function() {
|
test('path.join(path)', function() {
|
||||||
var doc = new Document();
|
var doc = new Document();
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
path.add([0, 0]);
|
path.add(0, 0);
|
||||||
path.add([10, 0]);
|
path.add(10, 0);
|
||||||
|
|
||||||
var path2 = new Path();
|
var path2 = new Path();
|
||||||
path2.add([10, 0]);
|
path2.add(10, 0);
|
||||||
path2.add([20, 10]);
|
path2.add(20, 10);
|
||||||
|
|
||||||
path.join(path2);
|
path.join(path2);
|
||||||
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }');
|
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);
|
equals(doc.activeLayer.children.length, 1);
|
||||||
|
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
path.add([0, 0]);
|
path.add(0, 0);
|
||||||
path.add([10, 0]);
|
path.add(10, 0);
|
||||||
|
|
||||||
var path2 = new Path();
|
var path2 = new Path();
|
||||||
path2.add([20, 10]);
|
path2.add(20, 10);
|
||||||
path2.add([10, 0]);
|
path2.add(10, 0);
|
||||||
path.join(path2);
|
path.join(path2);
|
||||||
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }');
|
equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }');
|
||||||
|
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
path.add([0, 0]);
|
path.add(0, 0);
|
||||||
path.add([10, 0]);
|
path.add(10, 0);
|
||||||
|
|
||||||
var path2 = new Path();
|
var path2 = new Path();
|
||||||
path2.add([30, 10]);
|
path2.add(30, 10);
|
||||||
path2.add([40, 0]);
|
path2.add(40, 0);
|
||||||
path.join(path2);
|
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 } }');
|
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();
|
var path = new Path();
|
||||||
path.add([0, 0]);
|
path.add(0, 0);
|
||||||
path.add([10, 0]);
|
path.add(10, 0);
|
||||||
path.add([20, 10]);
|
path.add(20, 10);
|
||||||
|
|
||||||
var path2 = new Path();
|
var path2 = new Path();
|
||||||
path2.add([0, 0]);
|
path2.add(0, 0);
|
||||||
path2.add([10, 5]);
|
path2.add(10, 5);
|
||||||
path2.add([20, 10]);
|
path2.add(20, 10);
|
||||||
|
|
||||||
path.join(path2);
|
path.join(path2);
|
||||||
|
|
||||||
|
@ -53,10 +53,10 @@ test('path.join(path)', function() {
|
||||||
test('path.remove()', function() {
|
test('path.remove()', function() {
|
||||||
var doc = new Document();
|
var doc = new Document();
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
path.add([0, 0]);
|
path.add(0, 0);
|
||||||
path.add([10, 0]);
|
path.add(10, 0);
|
||||||
path.add([20, 0]);
|
path.add(20, 0);
|
||||||
path.add([30, 0]);
|
path.add(30, 0);
|
||||||
|
|
||||||
path.removeSegment(0);
|
path.removeSegment(0);
|
||||||
equals(path.segments.length, 3);
|
equals(path.segments.length, 3);
|
||||||
|
|
|
@ -4,12 +4,12 @@ test('currentStyle', function() {
|
||||||
var doc = new Document();
|
var doc = new Document();
|
||||||
doc.currentStyle.fillColor = 'black';
|
doc.currentStyle.fillColor = 'black';
|
||||||
var path = new Path();
|
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
|
// When changing the current style of the document, the style of
|
||||||
// paths created using document.currentStyle should not change.
|
// paths created using document.currentStyle should not change.
|
||||||
doc.currentStyle.fillColor = 'red';
|
doc.currentStyle.fillColor = 'red';
|
||||||
compareRGBColors(path.fillColor, 'black');
|
compareRGBColors(path.fillColor, 'black', 'path.fillColor');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('setting currentStyle to an object', function() {
|
test('setting currentStyle to an object', function() {
|
||||||
|
@ -19,8 +19,8 @@ test('setting currentStyle to an object', function() {
|
||||||
strokeColor: 'green'
|
strokeColor: 'green'
|
||||||
};
|
};
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
compareRGBColors(path.fillColor, 'red');
|
compareRGBColors(path.fillColor, 'red', 'path.fillColor');
|
||||||
compareRGBColors(path.strokeColor, 'green');
|
compareRGBColors(path.strokeColor, 'green', 'path.strokeColor');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('setting path styles to an object', function() {
|
test('setting path styles to an object', function() {
|
||||||
|
@ -30,8 +30,8 @@ test('setting path styles to an object', function() {
|
||||||
fillColor: 'red',
|
fillColor: 'red',
|
||||||
strokeColor: 'green'
|
strokeColor: 'green'
|
||||||
};
|
};
|
||||||
compareRGBColors(path.fillColor, 'red');
|
compareRGBColors(path.fillColor, 'red', 'path.fillColor');
|
||||||
compareRGBColors(path.strokeColor, 'green');
|
compareRGBColors(path.strokeColor, 'green', 'path.strokeColor');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('setting group styles to an object', function() {
|
test('setting group styles to an object', function() {
|
||||||
|
@ -43,8 +43,8 @@ test('setting group styles to an object', function() {
|
||||||
fillColor: 'red',
|
fillColor: 'red',
|
||||||
strokeColor: 'green'
|
strokeColor: 'green'
|
||||||
};
|
};
|
||||||
compareRGBColors(path.fillColor, 'red');
|
compareRGBColors(path.fillColor, 'red', 'path.fillColor');
|
||||||
compareRGBColors(path.strokeColor, 'green');
|
compareRGBColors(path.strokeColor, 'green', 'path.strokeColor');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getting group styles', function() {
|
test('getting group styles', function() {
|
||||||
|
@ -54,7 +54,7 @@ test('getting group styles', function() {
|
||||||
path.fillColor = 'red';
|
path.fillColor = 'red';
|
||||||
group.appendTop(path);
|
group.appendTop(path);
|
||||||
|
|
||||||
compareRGBColors(group.fillColor, 'red');
|
compareRGBColors(group.fillColor, 'red', 'group.fillColor');
|
||||||
|
|
||||||
var secondPath = new Path();
|
var secondPath = new Path();
|
||||||
secondPath.fillColor = 'black';
|
secondPath.fillColor = 'black';
|
||||||
|
@ -62,11 +62,11 @@ test('getting group styles', function() {
|
||||||
|
|
||||||
// the group now contains two paths with different fillColors and therefore
|
// the group now contains two paths with different fillColors and therefore
|
||||||
// should return null:
|
// should return null:
|
||||||
equals(group.fillColor, null);
|
equals(group.fillColor, null, 'group.fillColor');
|
||||||
|
|
||||||
//If we remove the first path, it should now return 'black':
|
//If we remove the first path, it should now return 'black':
|
||||||
group.children[0].remove();
|
group.children[0].remove();
|
||||||
compareRGBColors(group.fillColor, 'black');
|
compareRGBColors(group.fillColor, 'black', 'group.fillColor');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('setting group styles', function() {
|
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
|
// the paths contained in the group should now both have their fillColor
|
||||||
// set to black:
|
// set to black:
|
||||||
compareRGBColors(path.fillColor, 'black');
|
compareRGBColors(path.fillColor, 'black', 'path.fillColor');
|
||||||
compareRGBColors(secondPath.fillColor, 'black');
|
compareRGBColors(secondPath.fillColor, 'black', 'secondPath.fillColor');
|
||||||
|
|
||||||
// The second path still has its strokeColor set to red:
|
// 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() {
|
test('setting group styles 2', function() {
|
||||||
|
@ -100,31 +100,31 @@ test('setting group styles 2', function() {
|
||||||
path.fillColor = 'red';
|
path.fillColor = 'red';
|
||||||
group.appendTop(path);
|
group.appendTop(path);
|
||||||
|
|
||||||
compareRGBColors(group.fillColor, 'red');
|
compareRGBColors(group.fillColor, 'red', 'group.fillColor');
|
||||||
|
|
||||||
var secondPath = new Path();
|
var secondPath = new Path();
|
||||||
secondPath.fillColor = 'blue';
|
secondPath.fillColor = 'blue';
|
||||||
secondPath.strokeColor = 'red';
|
secondPath.strokeColor = 'red';
|
||||||
group.appendTop(secondPath);
|
group.appendTop(secondPath);
|
||||||
|
|
||||||
compareRGBColors(secondPath.fillColor, 'blue');
|
compareRGBColors(secondPath.fillColor, 'blue', 'secondPath.fillColor');
|
||||||
compareRGBColors(secondPath.strokeColor, 'red');
|
compareRGBColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
||||||
|
|
||||||
// By appending a path with a different fillcolor,
|
// By appending a path with a different fillcolor,
|
||||||
// the group's fillColor should return null:
|
// the group's fillColor should return undefined:
|
||||||
equals(group.fillColor, null);
|
equals(group.fillColor, undefined, 'group.fillColor');
|
||||||
|
|
||||||
// But, both paths have a red strokeColor, so:
|
// 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:
|
// Change the fill color of the group's style:
|
||||||
group.style.fillColor = 'black';
|
group.style.fillColor = 'black';
|
||||||
|
|
||||||
// the paths contained in the group should now both have their fillColor
|
// the paths contained in the group should now both have their fillColor
|
||||||
// set to black:
|
// set to black:
|
||||||
compareRGBColors(path.fillColor, 'black');
|
compareRGBColors(path.fillColor, 'black', 'path.fillColor');
|
||||||
compareRGBColors(secondPath.fillColor, 'black');
|
compareRGBColors(secondPath.fillColor, 'black', 'secondPath.fillColor');
|
||||||
|
|
||||||
// The second path still has its strokeColor set to red:
|
// The second path still has its strokeColor set to red:
|
||||||
compareRGBColors(secondPath.strokeColor, 'red');
|
compareRGBColors(secondPath.strokeColor, 'red', 'secondPath.strokeColor');
|
||||||
});
|
});
|
Loading…
Reference in a new issue