Take Color#alpha default into account in Color#equals()

Relates to #1084
This commit is contained in:
Jürg Lehni 2016-07-25 21:09:53 +02:00
parent e2e024f8a5
commit 29768c8228
2 changed files with 20 additions and 10 deletions

View file

@ -769,7 +769,7 @@ var Color = Base.extend(new function() {
: color;
return col === this || col && this._class === col._class
&& this._type === col._type
&& this._alpha === col._alpha
&& this.getAlpha() === col.getAlpha()
&& Base.equals(this._components, col._components)
|| false;
},

View file

@ -109,7 +109,7 @@ test('Get hue from RGB Color', function() {
equals(color.saturation, 1);
});
test('Gray Color', function() {
test('Get gray after conversion', function() {
var color = new Color(1);
equals(color.gray, 1, 'color.gray');
equals(color.red, 1, 'color.red');
@ -156,12 +156,12 @@ test('Setting Color#gray', function() {
equals(color, new Color(0.5));
});
test('Color.read(channels)', function() {
test('Color.read()', function() {
var color = Color.read([0, 0, 1]);
equals(color, new Color(0, 0, 1));
});
test('Cloning colors', function() {
test('Color#clone()', function() {
var color = new Color(0, 0, 0);
equals(function() {
return color.clone() != color;
@ -172,7 +172,7 @@ test('Cloning colors', function() {
}, true);
});
test('Color#convert', function() {
test('Color#convert()', function() {
var color = new Color(0, 0, 0);
var converted = color.convert('rgb');
equals(function() {
@ -183,13 +183,13 @@ test('Color#convert', function() {
}, true);
});
test('Saturation from black rgb', function() {
test('Getting saturation from black RGB Color', function() {
equals(function() {
return new Color(0, 0, 0).saturation === 0;
}, true);
});
test('Color#add', function() {
test('Color#add()', function() {
var color = new Color(0, 1, 1);
equals(color.add([1, 0, 0]), new Color([1, 1, 1]));
equals(color.add([1, 0.5, 0]), new Color([1, 1.5, 1]));
@ -197,7 +197,7 @@ test('Color#add', function() {
equals(color.add(0.5), new Color([0.5, 1, 0.5]));
});
test('Color#subtract', function() {
test('Color#subtract()', function() {
var color = new Color(0, 1, 1);
equals(color.subtract([0, 1, 1]), new Color([0, 0, 0]));
equals(color.subtract([0, 0.5, 1]), new Color([0, 0.5, 0]));
@ -205,7 +205,7 @@ test('Color#subtract', function() {
equals(color.subtract(0.5), new Color([0.5, 0.5, 0.5]));
});
test('Color#multiply', function() {
test('Color#multiply()', function() {
var color = new Color(1, 0.5, 0.25);
equals(color.multiply([0.25, 0.5, 1]), new Color([0.25, 0.25, 0.25]));
var color = new Color(1, 1, 1);
@ -214,7 +214,7 @@ test('Color#multiply', function() {
equals(color.multiply(2), new Color([1, 1, 1]));
});
test('Color#divide', function() {
test('Color#divide()', function() {
var color = new Color(1, 1, 1);
equals(color.divide([1, 2, 4]), new Color([1, 0.5, 0.25]));
var color = new Color(1, 0.5, 0.25);
@ -223,6 +223,16 @@ test('Color#divide', function() {
equals(color.divide(4), new Color([0.25, 0.25, 0.25]));
});
test('Color#equals()', function() {
var red = new Color('red');
equals(function() {
return new Color(1, 0, 0).equals(red);
}, true);
equals(function() {
return new Color(1, 0, 0, 1).equals(red);
}, true);
});
test('Gradient', function() {
var stop1 = new GradientStop({ offset: 0.5 });
var stop2 = new GradientStop('red', 0.75);