From 22e33519c8c54e6ab8e7c68bb35f4471cc4247d2 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 4 Dec 2014 09:07:21 +0100 Subject: [PATCH 1/2] Explain that return of ol.color.asArray should not be modified --- src/ol/color/color.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ol/color/color.js b/src/ol/color/color.js index 6f7f44fff4..712323f370 100644 --- a/src/ol/color/color.js +++ b/src/ol/color/color.js @@ -94,6 +94,8 @@ ol.color.blend = function(dst, src, opt_color) { /** + * Return the color as an array. This function maintains a cache of calculated + * arrays which means the result should not be modified. * @param {ol.Color|string} color Color. * @return {ol.Color} Color. * @api @@ -109,6 +111,7 @@ ol.color.asArray = function(color) { /** + * Return the color as an rgba string. * @param {ol.Color|string} color Color. * @return {string} Rgba string. * @api From ccc7c1b9b7041f484fe71cec24c36e6484ad588f Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Thu, 4 Dec 2014 09:24:18 +0100 Subject: [PATCH 2/2] Remove code that suggests that color arrays may be modified --- src/ol/color/color.js | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/src/ol/color/color.js b/src/ol/color/color.js index 712323f370..a857308d57 100644 --- a/src/ol/color/color.js +++ b/src/ol/color/color.js @@ -140,12 +140,11 @@ ol.color.equals = function(color1, color2) { /** * @param {string} s String. - * @param {ol.Color=} opt_color Color. * @return {ol.Color} Color. */ ol.color.fromString = ( /** - * @return {function(string, ol.Color=): ol.Color} + * @return {function(string): ol.Color} */ function() { @@ -172,10 +171,9 @@ ol.color.fromString = ( return ( /** * @param {string} s String. - * @param {ol.Color=} opt_color Color. * @return {ol.Color} Color. */ - function(s, opt_color) { + function(s) { var color; if (cache.hasOwnProperty(s)) { color = cache[s]; @@ -194,7 +192,7 @@ ol.color.fromString = ( cache[s] = color; ++cacheSize; } - return ol.color.returnOrUpdate(color, opt_color); + return color; }); })(); @@ -278,24 +276,6 @@ ol.color.normalize = function(color, opt_color) { }; -/** - * @param {ol.Color} color Color. - * @param {ol.Color=} opt_color Color. - * @return {ol.Color} Color. - */ -ol.color.returnOrUpdate = function(color, opt_color) { - if (goog.isDef(opt_color)) { - opt_color[0] = color[0]; - opt_color[1] = color[1]; - opt_color[2] = color[2]; - opt_color[3] = color[3]; - return opt_color; - } else { - return color; - } -}; - - /** * @param {ol.Color} color Color. * @return {string} String.