Merge pull request #4995 from tschaub/uncolored
Remove unused ol.color functions.
This commit is contained in:
@@ -9,7 +9,6 @@ goog.provide('ol.color');
|
|||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.color');
|
goog.require('goog.color');
|
||||||
goog.require('goog.color.names');
|
goog.require('goog.color.names');
|
||||||
goog.require('goog.vec.Mat4');
|
|
||||||
goog.require('ol');
|
goog.require('ol');
|
||||||
goog.require('ol.math');
|
goog.require('ol.math');
|
||||||
|
|
||||||
@@ -54,48 +53,6 @@ ol.color.rgbaColorRe_ =
|
|||||||
/^(?:rgba)?\((0|[1-9]\d{0,2}),\s?(0|[1-9]\d{0,2}),\s?(0|[1-9]\d{0,2}),\s?(0|1|0\.\d{0,10})\)$/i;
|
/^(?:rgba)?\((0|[1-9]\d{0,2}),\s?(0|[1-9]\d{0,2}),\s?(0|[1-9]\d{0,2}),\s?(0|1|0\.\d{0,10})\)$/i;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.Color} dst Destination.
|
|
||||||
* @param {ol.Color} src Source.
|
|
||||||
* @param {ol.Color=} opt_color Color.
|
|
||||||
* @return {ol.Color} Color.
|
|
||||||
*/
|
|
||||||
ol.color.blend = function(dst, src, opt_color) {
|
|
||||||
// http://en.wikipedia.org/wiki/Alpha_compositing
|
|
||||||
// FIXME do we need to scale by 255?
|
|
||||||
var out = opt_color ? opt_color : [];
|
|
||||||
var dstA = dst[3];
|
|
||||||
var srcA = src[3];
|
|
||||||
if (dstA == 1) {
|
|
||||||
out[0] = (src[0] * srcA + dst[0] * (1 - srcA) + 0.5) | 0;
|
|
||||||
out[1] = (src[1] * srcA + dst[1] * (1 - srcA) + 0.5) | 0;
|
|
||||||
out[2] = (src[2] * srcA + dst[2] * (1 - srcA) + 0.5) | 0;
|
|
||||||
out[3] = 1;
|
|
||||||
} else if (srcA === 0) {
|
|
||||||
out[0] = dst[0];
|
|
||||||
out[1] = dst[1];
|
|
||||||
out[2] = dst[2];
|
|
||||||
out[3] = dstA;
|
|
||||||
} else {
|
|
||||||
var outA = srcA + dstA * (1 - srcA);
|
|
||||||
if (outA === 0) {
|
|
||||||
out[0] = 0;
|
|
||||||
out[1] = 0;
|
|
||||||
out[2] = 0;
|
|
||||||
out[3] = 0;
|
|
||||||
} else {
|
|
||||||
out[0] = ((src[0] * srcA + dst[0] * dstA * (1 - srcA)) / outA + 0.5) | 0;
|
|
||||||
out[1] = ((src[1] * srcA + dst[1] * dstA * (1 - srcA)) / outA + 0.5) | 0;
|
|
||||||
out[2] = ((src[2] * srcA + dst[2] * dstA * (1 - srcA)) / outA + 0.5) | 0;
|
|
||||||
out[3] = outA;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
goog.asserts.assert(ol.color.isValid(out),
|
|
||||||
'Output color of blend should be a valid color');
|
|
||||||
return out;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the color as an array. This function maintains a cache of calculated
|
* Return the color as an array. This function maintains a cache of calculated
|
||||||
* arrays which means the result should not be modified.
|
* arrays which means the result should not be modified.
|
||||||
@@ -129,18 +86,6 @@ ol.color.asString = function(color) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.Color} color1 Color1.
|
|
||||||
* @param {ol.Color} color2 Color2.
|
|
||||||
* @return {boolean} Equals.
|
|
||||||
*/
|
|
||||||
ol.color.equals = function(color1, color2) {
|
|
||||||
return color1 === color2 || (
|
|
||||||
color1[0] == color2[0] && color1[1] == color2[1] &&
|
|
||||||
color1[2] == color2[2] && color1[3] == color2[3]);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} s String.
|
* @param {string} s String.
|
||||||
* @return {ol.Color} Color.
|
* @return {ol.Color} Color.
|
||||||
@@ -297,37 +242,3 @@ ol.color.toString = function(color) {
|
|||||||
var a = color[3] === undefined ? 1 : color[3];
|
var a = color[3] === undefined ? 1 : color[3];
|
||||||
return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
|
return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {!ol.Color} color Color.
|
|
||||||
* @param {goog.vec.Mat4.Number} transform Transform.
|
|
||||||
* @param {!ol.Color=} opt_color Color.
|
|
||||||
* @return {ol.Color} Transformed color.
|
|
||||||
*/
|
|
||||||
ol.color.transform = function(color, transform, opt_color) {
|
|
||||||
var result = opt_color ? opt_color : [];
|
|
||||||
result = goog.vec.Mat4.multVec3(transform, color, result);
|
|
||||||
goog.asserts.assert(goog.isArray(result), 'result should be an array');
|
|
||||||
result[3] = color[3];
|
|
||||||
return ol.color.normalize(result, result);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.Color|string} color1 Color2.
|
|
||||||
* @param {ol.Color|string} color2 Color2.
|
|
||||||
* @return {boolean} Equals.
|
|
||||||
*/
|
|
||||||
ol.color.stringOrColorEquals = function(color1, color2) {
|
|
||||||
if (color1 === color2 || color1 == color2) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (typeof color1 === 'string') {
|
|
||||||
color1 = ol.color.fromString(color1);
|
|
||||||
}
|
|
||||||
if (typeof color2 === 'string') {
|
|
||||||
color2 = ol.color.fromString(color2);
|
|
||||||
}
|
|
||||||
return ol.color.equals(color1, color2);
|
|
||||||
};
|
|
||||||
|
|||||||
+39
-21
@@ -3,31 +3,49 @@ goog.provide('ol.test.color');
|
|||||||
|
|
||||||
describe('ol.color', function() {
|
describe('ol.color', function() {
|
||||||
|
|
||||||
describe('ol.color.blend', function() {
|
describe('ol.color.asArray()', function() {
|
||||||
it('blends red (a=1) and blue (a=1) to blue (a=1)', function() {
|
|
||||||
var red = [255, 0, 0, 1];
|
it('returns the same for an array', function() {
|
||||||
var blue = [0, 0, 255, 1];
|
var color = [1, 2, 3, 0.4];
|
||||||
var blended = ol.color.blend(red, blue);
|
var got = ol.color.asArray(color);
|
||||||
expect(blended).to.eql([0, 0, 255, 1]);
|
expect(got).to.be(color);
|
||||||
});
|
});
|
||||||
it('blends red (a=1) and blue (a=0) to red (a=1)', function() {
|
|
||||||
var red = [255, 0, 0, 1];
|
it('returns an array given an rgba string', function() {
|
||||||
var blue = [0, 0, 255, 0];
|
var color = ol.color.asArray('rgba(1,2,3,0.4)');
|
||||||
var blended = ol.color.blend(red, blue);
|
expect(color).to.eql([1, 2, 3, 0.4]);
|
||||||
expect(blended).to.eql([255, 0, 0, 1]);
|
|
||||||
});
|
});
|
||||||
it('blends red (a=0.5) and blue (a=0.5) to purple (a=0.75)', function() {
|
|
||||||
var red = [255, 0, 0, 0.5];
|
it('returns an array given an rgb string', function() {
|
||||||
var blue = [0, 0, 255, 0.5];
|
var color = ol.color.asArray('rgb(1,2,3)');
|
||||||
var blended = ol.color.blend(red, blue);
|
expect(color).to.eql([1, 2, 3, 1]);
|
||||||
expect(blended).to.eql([85, 0, 170, 0.75]);
|
|
||||||
});
|
});
|
||||||
it('blends red (a=0.5) and blue (a=0) to red (a=0.5)', function() {
|
|
||||||
var red = [255, 0, 0, 0.5];
|
it('returns an array given a hex string', function() {
|
||||||
var blue = [0, 0, 255, 0];
|
var color = ol.color.asArray('#00ccff');
|
||||||
var blended = ol.color.blend(red, blue);
|
expect(color).to.eql([0, 204, 255, 1]);
|
||||||
expect(blended).to.eql([255, 0, 0, 0.5]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ol.color.asString()', function() {
|
||||||
|
|
||||||
|
it('returns the same for a string', function() {
|
||||||
|
var color = 'rgba(0,1,2,0.3)';
|
||||||
|
var got = ol.color.asString(color);
|
||||||
|
expect(got).to.be(color);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns a string given an rgba array', function() {
|
||||||
|
var color = ol.color.asString([1, 2, 3, 0.4]);
|
||||||
|
expect(color).to.eql('rgba(1,2,3,0.4)');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns a string given an rgb array', function() {
|
||||||
|
var color = ol.color.asString([1, 2, 3]);
|
||||||
|
expect(color).to.eql('rgba(1,2,3,1)');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ol.color.fromString', function() {
|
describe('ol.color.fromString', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user