From f6efffca303ac432ab9cc55f0ef63c2c8c59afb5 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 10 Jan 2017 16:32:41 -0500 Subject: [PATCH 1/3] Treat color as vec4 --- Source/Scene/Expression.js | 124 ++++++++-------------- Specs/Scene/ExpressionSpec.js | 190 ++++++++++++++++------------------ 2 files changed, 133 insertions(+), 181 deletions(-) diff --git a/Source/Scene/Expression.js b/Source/Scene/Expression.js index 17ae36798635..3ab185a3cc60 100644 --- a/Source/Scene/Expression.js +++ b/Source/Scene/Expression.js @@ -36,8 +36,6 @@ define([ var scratchColor = new Color(); var ScratchStorage = { - scratchColorIndex : 0, - scratchColorArray : [new Color()], scratchArrayIndex : 0, scratchArrayArray : [[]], scratchCartesian2Index : 0, @@ -47,18 +45,11 @@ define([ scratchCartesian3Array : [new Cartesian3()], scratchCartesian4Array : [new Cartesian4()], reset : function() { - this.scratchColorIndex = 0; this.scratchArrayIndex = 0; this.scratchCartesian2Index = 0; this.scratchCartesian3Index = 0; this.scratchCartesian4Index = 0; }, - getColor : function() { - if (this.scratchColorIndex >= this.scratchColorArray.length) { - this.scratchColorArray.push(new Color()); - } - return this.scratchColorArray[this.scratchColorIndex++]; - }, getArray : function() { if (this.scratchArrayIndex >= this.scratchArrayArray.length) { this.scratchArrayArray.push([]); @@ -184,18 +175,17 @@ define([ * {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/Styling|3D Tiles Styling language} * is of type Boolean, Number, or String, the corresponding JavaScript * primitive type will be returned. If the result is a RegExp, a Javascript RegExp - * object will be returned. If the result is a Color, a {@link Color} object will be returned. - * If the result is a Cartesian2, Cartesian3, or Cartesian4, + * object will be returned. If the result is a Cartesian2, Cartesian3, or Cartesian4, * a {@link Cartesian2}, {@link Cartesian3}, or {@link Cartesian4} object will be returned. * * @param {FrameState} frameState The frame state. * @param {Cesium3DTileFeature} feature The feature who's properties may be used as variables in the expression. - * @returns {Boolean|Number|String|Color|Cartesian2|Cartesian3|Cartesian4|RegExp} The result of evaluating the expression. + * @returns {Boolean|Number|String|Cartesian2|Cartesian3|Cartesian4|RegExp} The result of evaluating the expression. */ Expression.prototype.evaluate = function(frameState, feature) { ScratchStorage.reset(); var result = this._runtimeAst.evaluate(frameState, feature); - if ((result instanceof Color) || (result instanceof Cartesian2) || (result instanceof Cartesian3) || (result instanceof Cartesian4)) { + if ((result instanceof Cartesian2) || (result instanceof Cartesian3) || (result instanceof Cartesian4)) { return result.clone(); } return result; @@ -212,7 +202,7 @@ define([ Expression.prototype.evaluateColor = function(frameState, feature, result) { ScratchStorage.reset(); var color = this._runtimeAst.evaluate(frameState, feature); - return Color.clone(color, result); + return Color.fromCartesian4(color, result); }; /** @@ -776,23 +766,23 @@ define([ }; Node.prototype._evaluateLiteralColor = function(frameState, feature) { - var result = ScratchStorage.getColor(); + var color = scratchColor; var args = this._left; if (this._value === 'color') { if (!defined(args)) { - return Color.fromBytes(255, 255, 255, 255, result); + Color.fromBytes(255, 255, 255, 255, color); } else if (args.length > 1) { - Color.fromCssColorString(args[0].evaluate(frameState, feature), result); - result.alpha = args[1].evaluate(frameState, feature); + Color.fromCssColorString(args[0].evaluate(frameState, feature), color); + color.alpha = args[1].evaluate(frameState, feature); } else { - Color.fromCssColorString(args[0].evaluate(frameState, feature), result); + Color.fromCssColorString(args[0].evaluate(frameState, feature), color); } } else if (this._value === 'rgb') { Color.fromBytes( args[0].evaluate(frameState, feature), args[1].evaluate(frameState, feature), args[2].evaluate(frameState, feature), - 255, result); + 255, color); } else if (this._value === 'rgba') { // convert between css alpha (0 to 1) and cesium alpha (0 to 255) var a = args[3].evaluate(frameState, feature) * 255; @@ -800,22 +790,22 @@ define([ args[0].evaluate(frameState, feature), args[1].evaluate(frameState, feature), args[2].evaluate(frameState, feature), - a, result); + a, color); } else if (this._value === 'hsl') { Color.fromHsl( args[0].evaluate(frameState, feature), args[1].evaluate(frameState, feature), args[2].evaluate(frameState, feature), - 1.0, result); + 1.0, color); } else if (this._value === 'hsla') { Color.fromHsl( args[0].evaluate(frameState, feature), args[1].evaluate(frameState, feature), args[2].evaluate(frameState, feature), args[3].evaluate(frameState, feature), - result); + color); } - return result; + return Cartesian4.fromColor(color, ScratchStorage.getCartesian4()); }; Node.prototype._evaluateLiteralVector = function(frameState, feature) { @@ -917,19 +907,18 @@ define([ } var member = this._right.evaluate(frameState, feature); - if (property instanceof Color) { - // Color components may be accessed with .x, .y, .z, .w and implicitly with .red, .green, .blue, .alpha - if (member === 'x') { - return property.red; - } else if (member === 'y') { - return property.green; - } else if (member === 'z') { - return property.blue; - } else if (member === 'w') { - return property.alpha; + if ((property instanceof Cartesian2) || (property instanceof Cartesian3) || (property instanceof Cartesian4)) { + // Vector components may be accessed with .red, .green, .blue, .alpha and implicitly with .x, .y, .z, .w + if (member === 'red') { + return property.x; + } else if (member === 'green') { + return property.y; + } else if (member === 'blue') { + return property.z; + } else if (member === 'alpha') { + return property.w; } } - return property[member]; }; @@ -943,27 +932,16 @@ define([ } var member = this._right.evaluate(frameState, feature); - if (property instanceof Color) { - // Color components may be accessed with [0][1][2][3], ['x']['y']['z']['w'], and implicitly with ['red']['green']['blue']['alpha'] - if (member === 0 || member === 'x') { - return property.red; - } else if (member === 1 || member === 'y') { - return property.green; - } else if (member === 2 || member === 'z') { - return property.blue; - } else if (member === 3 || member === 'w') { - return property.alpha; - } - } else if ((property instanceof Cartesian2) || (property instanceof Cartesian3) || (property instanceof Cartesian4)) { - // Vector components may be accessed with [0][1][2][3] and implicitly with ['x']['y']['z']['w'] + if ((property instanceof Cartesian2) || (property instanceof Cartesian3) || (property instanceof Cartesian4)) { + // Vector components may be accessed with [0][1][2][3], ['red']['green']['blue']['alpha'] and implicitly with ['x']['y']['z']['w'] // For Cartesian2 and Cartesian3 out-of-range components will just return undefined - if (member === 0) { + if (member === 0 || member === 'red') { return property.x; - } else if (member === 1) { + } else if (member === 1 || member === 'green') { return property.y; - } else if (member === 2) { + } else if (member === 2 || member === 'blue') { return property.z; - } else if (member === 3) { + } else if (member === 3 || member === 'alpha') { return property.w; } } @@ -999,7 +977,7 @@ define([ Node.prototype._evaluatePositive = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); - if ((left instanceof Color) || (left instanceof Cartesian2) || (left instanceof Cartesian3) || (left instanceof Cartesian4)) { + if ((left instanceof Cartesian2) || (left instanceof Cartesian3) || (left instanceof Cartesian4)) { return left; } return +left; @@ -1076,9 +1054,7 @@ define([ Node.prototype._evaluatePlus = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color)) { - return Color.add(left, right, ScratchStorage.getColor()); - } else if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { + if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { return Cartesian2.add(left, right, ScratchStorage.getCartesian2()); } else if ((right instanceof Cartesian3) && (left instanceof Cartesian3)) { return Cartesian3.add(left, right, ScratchStorage.getCartesian3()); @@ -1091,9 +1067,7 @@ define([ Node.prototype._evaluateMinus = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color)) { - return Color.subtract(left, right, ScratchStorage.getColor()); - } else if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { + if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { return Cartesian2.subtract(left, right, ScratchStorage.getCartesian2()); } else if ((right instanceof Cartesian3) && (left instanceof Cartesian3)) { return Cartesian3.subtract(left, right, ScratchStorage.getCartesian3()); @@ -1106,13 +1080,7 @@ define([ Node.prototype._evaluateTimes = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color)) { - return Color.multiply(left, right, ScratchStorage.getColor()); - } else if ((right instanceof Color) && (typeof(left) === 'number')) { - return Color.multiplyByScalar(right, left, ScratchStorage.getColor()); - } else if ((left instanceof Color) && (typeof(right) === 'number')) { - return Color.multiplyByScalar(left, right, ScratchStorage.getColor()); - } else if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { + if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { return Cartesian2.multiplyComponents(left, right, ScratchStorage.getCartesian2()); } else if ((right instanceof Cartesian2) && (typeof(left) === 'number')) { return Cartesian2.multiplyByScalar(right, left, ScratchStorage.getCartesian2()); @@ -1137,11 +1105,7 @@ define([ Node.prototype._evaluateDivide = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color)) { - return Color.divide(left, right, ScratchStorage.getColor()); - } else if ((left instanceof Color) && (typeof(right) === 'number')) { - return Color.divideByScalar(left, right, ScratchStorage.getColor()); - } else if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { + if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { return Cartesian2.divideComponents(left, right, ScratchStorage.getCartesian2()); } else if ((left instanceof Cartesian2) && (typeof(right) === 'number')) { return Cartesian2.divideByScalar(left, right, ScratchStorage.getCartesian2()); @@ -1160,9 +1124,7 @@ define([ Node.prototype._evaluateMod = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color)) { - return Color.mod(left, right, ScratchStorage.getColor()); - } else if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { + if ((right instanceof Cartesian2) && (left instanceof Cartesian2)) { return Cartesian2.fromElements(left.x % right.x, left.y % right.y, ScratchStorage.getCartesian2()); } else if ((right instanceof Cartesian3) && (left instanceof Cartesian3)) { return Cartesian3.fromElements(left.x % right.x, left.y % right.y, left.z % right.z, ScratchStorage.getCartesian3()); @@ -1175,8 +1137,7 @@ define([ Node.prototype._evaluateEqualsStrict = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color) || - (right instanceof Cartesian2) && (left instanceof Cartesian2) || + if ((right instanceof Cartesian2) && (left instanceof Cartesian2) || (right instanceof Cartesian3) && (left instanceof Cartesian3) || (right instanceof Cartesian4) && (left instanceof Cartesian4)) { return left.equals(right); @@ -1187,8 +1148,7 @@ define([ Node.prototype._evaluateEquals = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color) || - (right instanceof Cartesian2) && (left instanceof Cartesian2) || + if ((right instanceof Cartesian2) && (left instanceof Cartesian2) || (right instanceof Cartesian3) && (left instanceof Cartesian3) || (right instanceof Cartesian4) && (left instanceof Cartesian4)) { return left.equals(right); @@ -1202,8 +1162,7 @@ define([ Node.prototype._evaluateNotEqualsStrict = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color) || - (right instanceof Cartesian2) && (left instanceof Cartesian2) || + if ((right instanceof Cartesian2) && (left instanceof Cartesian2) || (right instanceof Cartesian3) && (left instanceof Cartesian3) || (right instanceof Cartesian4) && (left instanceof Cartesian4)) { return !left.equals(right); @@ -1214,8 +1173,7 @@ define([ Node.prototype._evaluateNotEquals = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); var right = this._right.evaluate(frameState, feature); - if ((right instanceof Color) && (left instanceof Color) || - (right instanceof Cartesian2) && (left instanceof Cartesian2) || + if ((right instanceof Cartesian2) && (left instanceof Cartesian2) || (right instanceof Cartesian3) && (left instanceof Cartesian3) || (right instanceof Cartesian4) && (left instanceof Cartesian4)) { return !left.equals(right); @@ -1321,7 +1279,7 @@ define([ Node.prototype._evaluateToString = function(frameState, feature) { var left = this._left.evaluate(frameState, feature); - if ((left instanceof RegExp) || (left instanceof Color) || (left instanceof Cartesian2) || (left instanceof Cartesian3) || (left instanceof Cartesian4)) { + if ((left instanceof RegExp) || (left instanceof Cartesian2) || (left instanceof Cartesian3) || (left instanceof Cartesian4)) { return String(left); } //>>includeStart('debug', pragmas.debug); diff --git a/Specs/Scene/ExpressionSpec.js b/Specs/Scene/ExpressionSpec.js index 078761b40a2e..404af431d4d7 100644 --- a/Specs/Scene/ExpressionSpec.js +++ b/Specs/Scene/ExpressionSpec.js @@ -69,7 +69,7 @@ defineSuite([ feature.addProperty('width', 5); feature.addProperty('string', 'hello'); feature.addProperty('boolean', true); - feature.addProperty('color', Color.RED); + feature.addProperty('vector', Cartesian3.UNIT_X); feature.addProperty('null', null); feature.addProperty('undefined', undefined); @@ -103,11 +103,11 @@ defineSuite([ expression = new Expression('\'${boolean}\''); expect(expression.evaluate(frameState, feature)).toEqual('true'); - expression = new Expression('${color}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.RED); + expression = new Expression('${vector}'); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian3.UNIT_X); - expression = new Expression('\'${color}\''); - expect(expression.evaluate(frameState, feature)).toEqual(Color.RED.toString()); + expression = new Expression('\'${vector}\''); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian3.UNIT_X.toString()); expression = new Expression('${null}'); expect(expression.evaluate(frameState, feature)).toEqual(null); @@ -294,52 +294,52 @@ defineSuite([ it('evaluates literal color', function() { var expression = new Expression('color(\'#ffffff\')'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('color(\'#00FFFF\')'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.CYAN); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.CYAN)); expression = new Expression('color(\'#fff\')'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('color(\'#0FF\')'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.CYAN); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.CYAN)); expression = new Expression('color(\'white\')'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('color(\'cyan\')'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.CYAN); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.CYAN)); expression = new Expression('color(\'white\', 0.5)'); - expect(expression.evaluate(frameState, undefined)).toEqual(new Color(1.0, 1.0, 1.0, 0.5)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.fromAlpha(Color.WHITE, 0.5))); expression = new Expression('rgb(255, 255, 255)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('rgb(100, 255, 190)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.fromBytes(100, 255, 190)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.fromBytes(100, 255, 190))); expression = new Expression('hsl(0, 0, 1)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('hsl(1.0, 0.6, 0.7)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.fromHsl(1.0, 0.6, 0.7)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.fromHsl(1.0, 0.6, 0.7))); expression = new Expression('rgba(255, 255, 255, 0.5)'); - expect(expression.evaluate(frameState, undefined)).toEqual(new Color(1.0, 1.0, 1.0, 0.5)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.fromAlpha(Color.WHITE, 0.5))); expression = new Expression('rgba(100, 255, 190, 0.25)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.fromBytes(100, 255, 190, 0.25 * 255)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.fromBytes(100, 255, 190, 0.25 * 255))); expression = new Expression('hsla(0, 0, 1, 0.5)'); - expect(expression.evaluate(frameState, undefined)).toEqual(new Color(1.0, 1.0, 1.0, 0.5)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(new Color(1.0, 1.0, 1.0, 0.5))); expression = new Expression('hsla(1.0, 0.6, 0.7, 0.75)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.fromHsl(1.0, 0.6, 0.7, 0.75)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.fromHsl(1.0, 0.6, 0.7, 0.75))); expression = new Expression('color()'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.WHITE)); }); it('evaluates literal color with result parameter', function() { @@ -390,19 +390,19 @@ defineSuite([ feature.addProperty('alpha', 0.2); var expression = new Expression('color(${hex6})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('color(${hex3})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('color(${keyword})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('color(${keyword}, ${alpha} + 0.6)'); - expect(expression.evaluate(frameState, feature).red).toEqual(1.0); - expect(expression.evaluate(frameState, feature).green).toEqual(1.0); - expect(expression.evaluate(frameState, feature).blue).toEqual(1.0); - expect(expression.evaluate(frameState, feature).alpha).toEqual(0.8); + expect(expression.evaluate(frameState, feature).x).toEqual(1.0); + expect(expression.evaluate(frameState, feature).y).toEqual(1.0); + expect(expression.evaluate(frameState, feature).z).toEqual(1.0); + expect(expression.evaluate(frameState, feature).w).toEqual(0.8); }); it('evaluates rgb with expressions as arguments', function() { @@ -412,10 +412,10 @@ defineSuite([ feature.addProperty('blue', 255); var expression = new Expression('rgb(${red}, ${green}, ${blue})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.fromBytes(100, 200, 255)); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.fromBytes(100, 200, 255))); expression = new Expression('rgb(${red}/2, ${green}/2, ${blue})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.fromBytes(50, 100, 255)); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.fromBytes(50, 100, 255))); }); it('evaluates hsl with expressions as arguments', function() { @@ -425,10 +425,10 @@ defineSuite([ feature.addProperty('l', 1.0); var expression = new Expression('hsl(${h}, ${s}, ${l})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('hsl(${h} + 0.2, ${s} + 1.0, ${l} - 0.5)'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.fromHsl(0.2, 1.0, 0.5)); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.fromHsl(0.2, 1.0, 0.5))); }); it('evaluates rgba with expressions as arguments', function() { @@ -439,10 +439,10 @@ defineSuite([ feature.addProperty('a', 0.3); var expression = new Expression('rgba(${red}, ${green}, ${blue}, ${a})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.fromBytes(100, 200, 255, 0.3*255)); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.fromBytes(100, 200, 255, 0.3*255))); expression = new Expression('rgba(${red}/2, ${green}/2, ${blue}, ${a} * 2)'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.fromBytes(50, 100, 255, 0.6*255)); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.fromBytes(50, 100, 255, 0.6*255))); }); it('evaluates hsla with expressions as arguments', function() { @@ -453,10 +453,10 @@ defineSuite([ feature.addProperty('a', 1.0); var expression = new Expression('hsla(${h}, ${s}, ${l}, ${a})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('hsla(${h} + 0.2, ${s} + 1.0, ${l} - 0.5, ${a} / 4)'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.fromHsl(0.2, 1.0, 0.5, 0.25)); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.fromHsl(0.2, 1.0, 0.5, 0.25))); }); it('evaluates rgba with expressions as arguments', function() { @@ -467,10 +467,10 @@ defineSuite([ feature.addProperty('alpha', 0.5); var expression = new Expression('rgba(${red}, ${green}, ${blue}, ${alpha})'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.fromBytes(100, 200, 255, 0.5 * 255)); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.fromBytes(100, 200, 255, 0.5 * 255))); expression = new Expression('rgba(${red}/2, ${green}/2, ${blue}, ${alpha} + 0.1)'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.fromBytes(50, 100, 255, 0.6 * 255)); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.fromColor(Color.fromBytes(50, 100, 255, 0.6 * 255))); }); it('color constructors throw with wrong number of arguments', function() { @@ -1003,31 +1003,31 @@ defineSuite([ it('evaluates color operations', function() { var expression = new Expression('+rgba(255, 0, 0, 1.0)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.RED); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.RED)); expression = new Expression('rgba(255, 0, 0, 0.5) + rgba(0, 0, 255, 0.5)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.MAGENTA); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.MAGENTA)); expression = new Expression('rgba(0, 255, 255, 1.0) - rgba(0, 255, 0, 0)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.BLUE); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.BLUE)); expression = new Expression('rgba(255, 255, 255, 1.0) * rgba(255, 0, 0, 1.0)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.RED); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.RED)); expression = new Expression('rgba(255, 255, 0, 1.0) * 1.0'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.YELLOW); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.YELLOW)); expression = new Expression('1 * rgba(255, 255, 0, 1.0)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.YELLOW); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.YELLOW)); expression = new Expression('rgba(255, 255, 255, 1.0) / rgba(255, 255, 255, 1.0)'); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(Color.WHITE)); expression = new Expression('rgba(255, 255, 255, 1.0) / 2'); - expect(expression.evaluate(frameState, undefined)).toEqual(new Color(0.5, 0.5, 0.5, 0.5)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(new Color(0.5, 0.5, 0.5, 0.5))); expression = new Expression('rgba(255, 255, 255, 1.0) % rgba(255, 255, 255, 1.0)'); - expect(expression.evaluate(frameState, undefined)).toEqual(new Color(0, 0, 0, 0)); + expect(expression.evaluate(frameState, undefined)).toEqual(Cartesian4.fromColor(new Color(0, 0, 0, 0))); expression = new Expression('color(\'green\') == color(\'green\')'); expect(expression.evaluate(frameState, undefined)).toEqual(true); @@ -1177,17 +1177,11 @@ defineSuite([ }); it('evaluates color toString function', function() { - var feature = new MockFeature(); - feature.addProperty('property', Color.BLUE); - var expression = new Expression('color("red").toString()'); expect(expression.evaluate(frameState, undefined)).toEqual('(1, 0, 0, 1)'); expression = new Expression('rgba(0, 0, 255, 0.5).toString()'); expect(expression.evaluate(frameState, undefined)).toEqual('(0, 0, 1, 0.5)'); - - expression = new Expression('${property}.toString()'); - expect(expression.evaluate(frameState, feature)).toEqual('(0, 0, 1, 1)'); }); it('evaluates vector toString function', function() { @@ -1613,11 +1607,11 @@ defineSuite([ feature.addProperty('width', 5); feature.addProperty('string', 'hello'); feature.addProperty('boolean', true); - feature.addProperty('color', Color.RED); - feature.addProperty('color.red', 'something else'); - feature.addProperty('feature.color', Color.GREEN); + feature.addProperty('vector', Cartesian4.UNIT_X); + feature.addProperty('vector.x', 'something else'); + feature.addProperty('feature.vector', Cartesian4.UNIT_Y); feature.addProperty('feature', { - color : Color.BLUE + vector : Cartesian4.UNIT_Z }); feature.addProperty('null', null); feature.addProperty('undefined', undefined); @@ -1626,30 +1620,30 @@ defineSuite([ "city" : "Example City" }); - var expression = new Expression('${color.red}'); + var expression = new Expression('${vector.x}'); expect(expression.evaluate(frameState, feature)).toEqual(1.0); - expression = new Expression('${color.blue}'); + expression = new Expression('${vector.z}'); expect(expression.evaluate(frameState, feature)).toEqual(0.0); - expression = new Expression('${height.blue}'); + expression = new Expression('${height.z}'); expect(expression.evaluate(frameState, feature)).toEqual(undefined); - expression = new Expression('${undefined.blue}'); + expression = new Expression('${undefined.z}'); expect(expression.evaluate(frameState, feature)).toEqual(undefined); expression = new Expression('${feature}'); expect(expression.evaluate(frameState, feature)).toEqual({ - color : Color.BLUE + vector : Cartesian4.UNIT_Z }); - expression = new Expression('${feature.color}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.RED); + expression = new Expression('${feature.vector}'); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.UNIT_X); - expression = new Expression('${feature.feature.color}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.BLUE); + expression = new Expression('${feature.feature.vector}'); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.UNIT_Z); - expression = new Expression('${feature.color.red}'); + expression = new Expression('${feature.vector.x}'); expect(expression.evaluate(frameState, feature)).toEqual(1.0); expression = new Expression('${address.street}'); @@ -1665,11 +1659,11 @@ defineSuite([ feature.addProperty('width', 5); feature.addProperty('string', 'hello'); feature.addProperty('boolean', true); - feature.addProperty('color', Color.RED); - feature.addProperty('color.red', 'something else'); - feature.addProperty('feature.color', Color.GREEN); + feature.addProperty('vector', Cartesian4.UNIT_X); + feature.addProperty('vector.x', 'something else'); + feature.addProperty('feature.vector', Cartesian4.UNIT_Y); feature.addProperty('feature', { - color : Color.BLUE + vector : Cartesian4.UNIT_Z }); feature.addProperty('null', null); feature.addProperty('undefined', undefined); @@ -1679,35 +1673,35 @@ defineSuite([ "city" : "Example City" }); - var expression = new Expression('${color["red"]}'); + var expression = new Expression('${vector["x"]}'); expect(expression.evaluate(frameState, feature)).toEqual(1.0); - expression = new Expression('${color["blue"]}'); + expression = new Expression('${vector["z"]}'); expect(expression.evaluate(frameState, feature)).toEqual(0.0); - expression = new Expression('${height["blue"]}'); + expression = new Expression('${height["z"]}'); expect(expression.evaluate(frameState, feature)).toEqual(undefined); - expression = new Expression('${undefined["blue"]}'); + expression = new Expression('${undefined["z"]}'); expect(expression.evaluate(frameState, feature)).toEqual(undefined); - expression = new Expression('${feature["color"]}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.RED); + expression = new Expression('${feature["vector"]}'); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.UNIT_X); - expression = new Expression('${feature.color["red"]}'); + expression = new Expression('${feature.vector["x"]}'); expect(expression.evaluate(frameState, feature)).toEqual(1.0); - expression = new Expression('${feature["color"].red}'); + expression = new Expression('${feature["vector"].x}'); expect(expression.evaluate(frameState, feature)).toEqual(1.0); - expression = new Expression('${feature["color.red"]}'); + expression = new Expression('${feature["vector.x"]}'); expect(expression.evaluate(frameState, feature)).toEqual('something else'); - expression = new Expression('${feature.feature["color"]}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.BLUE); + expression = new Expression('${feature.feature["vector"]}'); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.UNIT_Z); - expression = new Expression('${feature["feature.color"]}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.GREEN); + expression = new Expression('${feature["feature.vector"]}'); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.UNIT_Y); expression = new Expression('${address.street}'); expect(expression.evaluate(frameState, feature)).toEqual("Example Street"); @@ -1740,23 +1734,23 @@ defineSuite([ it('member expression throws with variable property', function() { var feature = new MockFeature(); - feature.addProperty('color', Color.RED); - feature.addProperty('colorName', 'red'); + feature.addProperty('vector', Cartesian4.UNIT_X); + feature.addProperty('vectorName', 'UNIT_X'); expect(function() { - return new Expression('${color[${colorName}]}'); + return new Expression('${vector[${vectorName}]}'); }).toThrowDeveloperError(); }); it('evaluates feature property', function() { var feature = new MockFeature(); feature.addProperty('feature', { - color : Color.BLUE + vector : Cartesian4.UNIT_X }); var expression = new Expression('${feature}'); expect(expression.evaluate(frameState, feature)).toEqual({ - color : Color.BLUE + vector : Cartesian4.UNIT_X }); expression = new Expression('${feature} == ${feature.feature}'); @@ -1969,13 +1963,13 @@ defineSuite([ it('evaluates array expression', function() { var feature = new MockFeature(); feature.addProperty('property', 'value'); - feature.addProperty('array', [Color.GREEN, Color.PURPLE, Color.YELLOW]); + feature.addProperty('array', [Cartesian4.UNIT_X, Cartesian4.UNIT_Y, Cartesian4.UNIT_Z]); feature.addProperty('complicatedArray', [{ - 'subproperty' : Color.ORANGE, - 'anotherproperty' : Color.RED + 'subproperty' : Cartesian4.UNIT_X, + 'anotherproperty' : Cartesian4.UNIT_Y }, { - 'subproperty' : Color.BLUE, - 'anotherproperty' : Color.WHITE + 'subproperty' : Cartesian4.UNIT_Z, + 'anotherproperty' : Cartesian4.UNIT_W }]); feature.addProperty('temperatures', { "scale" : "fahrenheit", @@ -1986,7 +1980,7 @@ defineSuite([ expect(expression.evaluate(frameState, undefined)).toEqual([1, 2, 3]); expression = new Expression('[1+2, "hello", 2 < 3, color("blue"), ${property}]'); - expect(expression.evaluate(frameState, feature)).toEqual([3, 'hello', true, Color.BLUE, 'value']); + expect(expression.evaluate(frameState, feature)).toEqual([3, 'hello', true, Cartesian4.fromColor(Color.BLUE), 'value']); expression = new Expression('[1, 2, 3] * 4'); expect(expression.evaluate(frameState, undefined)).toEqual(NaN); @@ -1995,13 +1989,13 @@ defineSuite([ expect(expression.evaluate(frameState, undefined)).toEqual(NaN); expression = new Expression('${array[1]}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.PURPLE); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.UNIT_Y); expression = new Expression('${complicatedArray[1].subproperty}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.BLUE); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.UNIT_Z); expression = new Expression('${complicatedArray[0]["anotherproperty"]}'); - expect(expression.evaluate(frameState, feature)).toEqual(Color.RED); + expect(expression.evaluate(frameState, feature)).toEqual(Cartesian4.UNIT_Y); expression = new Expression('${temperatures["scale"]}'); expect(expression.evaluate(frameState, feature)).toEqual('fahrenheit'); From 96439351be2baafae9642502c66a89eda0d40480 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Tue, 10 Jan 2017 23:39:47 -0500 Subject: [PATCH 2/3] Fix other tests --- Specs/Scene/Cesium3DTileStyleSpec.js | 28 ++++++++++++------------- Specs/Scene/ConditionsExpressionSpec.js | 20 +++++++++--------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Specs/Scene/Cesium3DTileStyleSpec.js b/Specs/Scene/Cesium3DTileStyleSpec.js index 273ec01c8dff..c4d4d4adc206 100644 --- a/Specs/Scene/Cesium3DTileStyleSpec.js +++ b/Specs/Scene/Cesium3DTileStyleSpec.js @@ -281,7 +281,7 @@ defineSuite([ volume : '${Height} * ${Width} * ${Depth}' } }); - expect(style.meta.featureColor.evaluate(frameState, feature1)).toEqual(Color.fromBytes(38, 255, 82)); + expect(style.meta.featureColor.evaluateColor(frameState, feature1)).toEqual(Color.fromBytes(38, 255, 82)); expect(style.meta.volume.evaluate(frameState, feature1)).toEqual(20 * 20 * 100); }); @@ -324,7 +324,7 @@ defineSuite([ }); expect(style.show.evaluate(frameState, undefined)).toEqual(true); - expect(style.color.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(style.color.evaluateColor(frameState, undefined)).toEqual(Color.WHITE); expect(style.pointSize.evaluate(frameState, undefined)).toEqual(1.0); }); @@ -335,7 +335,7 @@ defineSuite([ expect(style.show.evaluate(frameState, feature1)).toEqual(true); expect(style.show.evaluate(frameState, feature2)).toEqual(false); - expect(style.color.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(style.color.evaluateColor(frameState, undefined)).toEqual(Color.WHITE); }); it('applies show style with regexp and variables', function() { @@ -345,7 +345,7 @@ defineSuite([ expect(style.show.evaluate(frameState, feature1)).toEqual(true); expect(style.show.evaluate(frameState, feature2)).toEqual(false); - expect(style.color.evaluate(frameState, undefined)).toEqual(Color.WHITE); + expect(style.color.evaluateColor(frameState, undefined)).toEqual(Color.WHITE); }); it('applies show style with complex conditional', function() { @@ -388,8 +388,8 @@ defineSuite([ "color" : "(${Temperature} > 90) ? color('red') : color('white')" }); expect(style.show.evaluate(frameState, feature1)).toEqual(true); - expect(style.color.evaluate(frameState, feature1)).toEqual(Color.WHITE); - expect(style.color.evaluate(frameState, feature2)).toEqual(Color.RED); + expect(style.color.evaluateColor(frameState, feature1)).toEqual(Color.WHITE); + expect(style.color.evaluateColor(frameState, feature2)).toEqual(Color.RED); }); it('applies color style with new color', function() { @@ -397,8 +397,8 @@ defineSuite([ "color" : "rgba(${red}, ${green}, ${blue}, (${volume} > 100 ? 0.5 : 1.0))" }); expect(style.show.evaluate(frameState, feature1)).toEqual(true); - expect(style.color.evaluate(frameState, feature1)).toEqual(new Color(38/255, 255/255, 82/255, 0.5)); - expect(style.color.evaluate(frameState, feature2)).toEqual(new Color(255/255, 30/255, 30/255, 1.0)); + expect(style.color.evaluateColor(frameState, feature1)).toEqual(new Color(38/255, 255/255, 82/255, 0.5)); + expect(style.color.evaluateColor(frameState, feature2)).toEqual(new Color(255/255, 30/255, 30/255, 1.0)); }); it('applies color style that maps id to color', function() { @@ -413,8 +413,8 @@ defineSuite([ } }); expect(style.show.evaluate(frameState, feature1)).toEqual(true); - expect(style.color.evaluate(frameState, feature1)).toEqual(Color.RED); - expect(style.color.evaluate(frameState, feature2)).toEqual(Color.LIME); + expect(style.color.evaluateColor(frameState, feature1)).toEqual(Color.RED); + expect(style.color.evaluateColor(frameState, feature2)).toEqual(Color.LIME); }); it('applies color style with complex conditional', function() { @@ -432,8 +432,8 @@ defineSuite([ } }); expect(style.show.evaluate(frameState, feature1)).toEqual(true); - expect(style.color.evaluate(frameState, feature1)).toEqual(Color.BLUE); - expect(style.color.evaluate(frameState, feature2)).toEqual(Color.YELLOW); + expect(style.color.evaluateColor(frameState, feature1)).toEqual(Color.BLUE); + expect(style.color.evaluateColor(frameState, feature2)).toEqual(Color.YELLOW); }); it('applies color style with conditional', function() { @@ -450,8 +450,8 @@ defineSuite([ } }); expect(style.show.evaluate(frameState, feature1)).toEqual(true); - expect(style.color.evaluate(frameState, feature1)).toEqual(Color.BLUE); - expect(style.color.evaluate(frameState, feature2)).toEqual(Color.YELLOW); + expect(style.color.evaluateColor(frameState, feature1)).toEqual(Color.BLUE); + expect(style.color.evaluateColor(frameState, feature2)).toEqual(Color.YELLOW); }); it('applies pointSize style with variable', function() { diff --git a/Specs/Scene/ConditionsExpressionSpec.js b/Specs/Scene/ConditionsExpressionSpec.js index 0769f7071d63..4bc58500ff71 100644 --- a/Specs/Scene/ConditionsExpressionSpec.js +++ b/Specs/Scene/ConditionsExpressionSpec.js @@ -81,16 +81,16 @@ defineSuite([ it('evaluates conditional', function() { var expression = new ConditionsExpression(jsonExp); - expect(expression.evaluate(frameState, new MockFeature(101))).toEqual(Color.BLUE); - expect(expression.evaluate(frameState, new MockFeature(52))).toEqual(Color.RED); - expect(expression.evaluate(frameState, new MockFeature(3))).toEqual(Color.LIME); + expect(expression.evaluateColor(frameState, new MockFeature(101))).toEqual(Color.BLUE); + expect(expression.evaluateColor(frameState, new MockFeature(52))).toEqual(Color.RED); + expect(expression.evaluateColor(frameState, new MockFeature(3))).toEqual(Color.LIME); }); it('evaluates conditional with multiple expressions', function() { var expression = new ConditionsExpression(jsonExpWithMultipleExpression); - expect(expression.evaluate(frameState, new MockFeature(101))).toEqual(Color.BLUE); - expect(expression.evaluate(frameState, new MockFeature(52))).toEqual(Color.LIME); - expect(expression.evaluate(frameState, new MockFeature(3))).toEqual(Color.LIME); + expect(expression.evaluateColor(frameState, new MockFeature(101))).toEqual(Color.BLUE); + expect(expression.evaluateColor(frameState, new MockFeature(52))).toEqual(Color.LIME); + expect(expression.evaluateColor(frameState, new MockFeature(3))).toEqual(Color.LIME); }); it('constructs and evaluates empty conditional', function() { @@ -113,15 +113,15 @@ defineSuite([ it('evaluates conditional with expression', function() { var expression = new ConditionsExpression(jsonExpWithExpression); - expect(expression.evaluate(frameState, new MockFeature(101))).toEqual(Color.BLUE); - expect(expression.evaluate(frameState, new MockFeature(52))).toEqual(Color.RED); - expect(expression.evaluate(frameState, new MockFeature(3))).toEqual(Color.LIME); + expect(expression.evaluateColor(frameState, new MockFeature(101))).toEqual(Color.BLUE); + expect(expression.evaluateColor(frameState, new MockFeature(52))).toEqual(Color.RED); + expect(expression.evaluateColor(frameState, new MockFeature(3))).toEqual(Color.LIME); }); it('evaluates undefined conditional expression', function() { var expression = new ConditionsExpression(jsonExpWithUndefinedExpression); expect(expression._expression).toEqual(undefined); - expect(expression.evaluate(frameState, undefined)).toEqual(Color.BLUE); + expect(expression.evaluateColor(frameState, undefined)).toEqual(Color.BLUE); }); it('gets shader function', function() { From 328e01b07f3f0953eff2cfd709bf8077fc6b8ce5 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 12 Jan 2017 14:19:21 -0500 Subject: [PATCH 3/3] Change .red and others to .r --- Source/Scene/Expression.js | 33 +++++++++++++++------------------ Specs/Scene/ExpressionSpec.js | 28 ++++++++++++++-------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/Source/Scene/Expression.js b/Source/Scene/Expression.js index 3ab185a3cc60..de941f866e32 100644 --- a/Source/Scene/Expression.js +++ b/Source/Scene/Expression.js @@ -908,14 +908,14 @@ define([ var member = this._right.evaluate(frameState, feature); if ((property instanceof Cartesian2) || (property instanceof Cartesian3) || (property instanceof Cartesian4)) { - // Vector components may be accessed with .red, .green, .blue, .alpha and implicitly with .x, .y, .z, .w - if (member === 'red') { + // Vector components may be accessed with .r, .g, .b, .a and implicitly with .x, .y, .z, .w + if (member === 'r') { return property.x; - } else if (member === 'green') { + } else if (member === 'g') { return property.y; - } else if (member === 'blue') { + } else if (member === 'b') { return property.z; - } else if (member === 'alpha') { + } else if (member === 'a') { return property.w; } } @@ -933,15 +933,15 @@ define([ var member = this._right.evaluate(frameState, feature); if ((property instanceof Cartesian2) || (property instanceof Cartesian3) || (property instanceof Cartesian4)) { - // Vector components may be accessed with [0][1][2][3], ['red']['green']['blue']['alpha'] and implicitly with ['x']['y']['z']['w'] + // Vector components may be accessed with [0][1][2][3], ['r']['g']['b']['a'] and implicitly with ['x']['y']['z']['w'] // For Cartesian2 and Cartesian3 out-of-range components will just return undefined - if (member === 0 || member === 'red') { + if (member === 0 || member === 'r') { return property.x; - } else if (member === 1 || member === 'green') { + } else if (member === 1 || member === 'g') { return property.y; - } else if (member === 2 || member === 'blue') { + } else if (member === 2 || member === 'b') { return property.z; - } else if (member === 3 || member === 'alpha') { + } else if (member === 3 || member === 'a') { return property.w; } } @@ -1458,14 +1458,13 @@ define([ case ExpressionNodeType.MEMBER: // This is intended for accessing the components of vector properties. String members aren't supported. // Check for 0.0 rather than 0 because all numbers are previously converted to decimals. - // In this shader there is not much distinction between colors and vectors so allow .red to access the 0th component for both. - if (right === 'red' || right === 'x' || right === '0.0') { + if (right === 'r' || right === 'x' || right === '0.0') { return left + '[0]'; - } else if (right === 'green' || right === 'y' || right === '1.0') { + } else if (right === 'g' || right === 'y' || right === '1.0') { return left + '[1]'; - } else if (right === 'blue' || right === 'z' || right === '2.0') { + } else if (right === 'b' || right === 'z' || right === '2.0') { return left + '[2]'; - } else if (right === 'alpha' || right === 'w' || right === '3.0') { + } else if (right === 'a' || right === 'w' || right === '3.0') { return left + '[3]'; } return left + '[int(' + right + ')]'; @@ -1504,10 +1503,8 @@ define([ case ExpressionNodeType.LITERAL_NUMBER: return numberToString(value); case ExpressionNodeType.LITERAL_STRING: - // Check if parent is of type MEMBER. Otherwise it is not possible to know whether 'red', 'green', and 'blue' - // refer to CSS strings or component accessors. if (defined(parent) && (parent._type === ExpressionNodeType.MEMBER)) { - if (value === 'red' || value === 'green' || value === 'blue' || value === 'alpha' || + if (value === 'r' || value === 'g' || value === 'b' || value === 'a' || value === 'x' || value === 'y' || value === 'z' || value === 'w') { return value; } diff --git a/Specs/Scene/ExpressionSpec.js b/Specs/Scene/ExpressionSpec.js index 404af431d4d7..f81acea750f7 100644 --- a/Specs/Scene/ExpressionSpec.js +++ b/Specs/Scene/ExpressionSpec.js @@ -491,17 +491,17 @@ defineSuite([ }).toThrowDeveloperError(); }); - it('evaluates color properties (reg, green, blue, alpha)', function() { - var expression = new Expression('color(\'#ffffff\').red'); + it('evaluates color properties (r, g, b, a)', function() { + var expression = new Expression('color(\'#ffffff\').r'); expect(expression.evaluate(frameState, undefined)).toEqual(1); - expression = new Expression('rgb(255, 255, 0).green'); + expression = new Expression('rgb(255, 255, 0).g'); expect(expression.evaluate(frameState, undefined)).toEqual(1); - expression = new Expression('color("cyan").blue'); + expression = new Expression('color("cyan").b'); expect(expression.evaluate(frameState, undefined)).toEqual(1); - expression = new Expression('rgba(255, 255, 0, 0.5).alpha'); + expression = new Expression('rgba(255, 255, 0, 0.5).a'); expect(expression.evaluate(frameState, undefined)).toEqual(0.5); }); @@ -533,17 +533,17 @@ defineSuite([ expect(expression.evaluate(frameState, undefined)).toEqual(0.5); }); - it('evaluates color properties (["red"], ["green"], ["blue"], ["alpha"])', function() { - var expression = new Expression('color(\'#ffffff\')["red"]'); + it('evaluates color properties (["r"], ["g"], ["b"], ["a"])', function() { + var expression = new Expression('color(\'#ffffff\')["r"]'); expect(expression.evaluate(frameState, undefined)).toEqual(1); - expression = new Expression('rgb(255, 255, 0)["green"]'); + expression = new Expression('rgb(255, 255, 0)["g"]'); expect(expression.evaluate(frameState, undefined)).toEqual(1); - expression = new Expression('color("cyan")["blue"]'); + expression = new Expression('color("cyan")["b"]'); expect(expression.evaluate(frameState, undefined)).toEqual(1); - expression = new Expression('rgba(255, 255, 0, 0.5)["alpha"]'); + expression = new Expression('rgba(255, 255, 0, 0.5)["a"]'); expect(expression.evaluate(frameState, undefined)).toEqual(0.5); }); @@ -1724,11 +1724,11 @@ defineSuite([ it('member expressions throw without variable notation', function() { expect(function() { - return new Expression('color.red'); + return new Expression('color.r'); }).toThrowDeveloperError(); expect(function() { - return new Expression('color["red"]'); + return new Expression('color["r"]'); }).toThrowDeveloperError(); }); @@ -2347,8 +2347,8 @@ defineSuite([ }); it('gets shader expression for color components', function() { - // .red, .green, .blue, .alpha - var expression = new Expression('color().red + color().green + color().blue + color().alpha'); + // .r, .g, .b, .a + var expression = new Expression('color().r + color().g + color().b + color().a'); var shaderExpression = expression.getShaderExpression('', {}); var expected = '(((vec4(1.0)[0] + vec4(1.0)[1]) + vec4(1.0)[2]) + vec4(1.0)[3])'; expect(shaderExpression).toEqual(expected);