Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3D Tiles Styling - Type Mismatches #2 #4940

Merged
merged 7 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
});

addStyle('Show Subsections', {
show : "${id} == 1 || ${id} > 250 && ${id} < 300"
show : "${id} === 1 || ${id} > 250 && ${id} < 300"
});

addStyle('Mod', {
show : "${id} % 2 == 0"
show : "${id} % 2 === 0"
});

addStyle('Abs', {
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/3D Tiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@

var leftOperand = 0;
var rightOperand = 0;
var op = '==';
var op = '===';

// Left operand (properties and literals)

Expand All @@ -559,7 +559,7 @@

// Operator

var ops = ['<', '<=', '>', '>=', '==', '!='];
var ops = ['<', '<=', '>', '>=', '===', '!=='];
var operators = [{
text : 'Operator',
onselect : function() {
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ define([
}

// Store any information needed to access the binary data, including the typed array,
// componentCount (e.g. a MAT4 would be 16), and the type used to pack and unpack (e.g. Matrix4).
// componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
binaryProperties[name] = {
typedArray : typedArray,
componentCount : componentCount,
Expand Down
10 changes: 5 additions & 5 deletions Source/Scene/Cesium3DTileStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ define([
var pointSizeExpression = defaultValue(styleJson.pointSize, DEFAULT_JSON_NUMBER_EXPRESSION);

var color;
if (typeof(colorExpression) === 'string') {
if (typeof colorExpression === 'string') {
color = new Expression(colorExpression);
} else if (defined(colorExpression.conditions)) {
color = new ConditionsExpression(colorExpression);
Expand All @@ -118,9 +118,9 @@ define([
that._color = color;

var show;
if (typeof(showExpression) === 'boolean') {
if (typeof showExpression === 'boolean') {
show = new Expression(String(showExpression));
} else if (typeof(showExpression) === 'string') {
} else if (typeof showExpression === 'string') {
show = new Expression(showExpression);
} else if (defined(showExpression.conditions)) {
show = new ConditionsExpression(showExpression);
Expand All @@ -129,9 +129,9 @@ define([
that._show = show;

var pointSize;
if (typeof(pointSizeExpression) === 'number') {
if (typeof pointSizeExpression === 'number') {
pointSize = new Expression(String(pointSizeExpression));
} else if (typeof(pointSizeExpression) === 'string') {
} else if (typeof pointSizeExpression === 'string') {
pointSize = new Expression(pointSizeExpression);
} else if (defined(pointSizeExpression.conditions)) {
pointSize = new ConditionsExpression(pointSizeExpression);
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/ConditionsExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ define([
* var expression = new Cesium.Expression({
* expression : 'regExp("^1(\\d)").exec(${id})',
* conditions : [
* ['${expression} == "1"', 'color("#FF0000")'],
* ['${expression} == "2"', 'color("#00FF00")'],
* ['${expression} === "1"', 'color("#FF0000")'],
* ['${expression} === "2"', 'color("#00FF00")'],
* ['true', 'color("#FFFFFF")']
* ]
* });
Expand Down
151 changes: 78 additions & 73 deletions Source/Scene/Expression.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Source/Scene/PointCloud3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ define([

for (var name in styleableProperties) {
if (styleableProperties.hasOwnProperty(name)) {
// TODO : this will not handle matrix types currently
var property = styleableProperties[name];
var typedArray = property.typedArray;
var componentCount = property.componentCount;
Expand Down
8 changes: 4 additions & 4 deletions Specs/Scene/Cesium3DTileStyleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ defineSuite([

it('applies show style with variable', function() {
var style = new Cesium3DTileStyle({
"show" : "${ZipCode} == '19341'"
"show" : "${ZipCode} === '19341'"
});

expect(style.show.evaluate(frameState, feature1)).toEqual(true);
Expand Down Expand Up @@ -404,10 +404,10 @@ defineSuite([
it('applies color style that maps id to color', function() {
var style = new Cesium3DTileStyle({
"color" : {
"expression" : "regExp('^1(\\d)').exec(${id})",
"expression" : "regExp('^1(\\d)').exec(String(${id}))",
"conditions" : [
["${expression} == '1'", "color('#FF0000')"],
["${expression} == '2'", "color('#00FF00')"],
["${expression} === '1'", "color('#FF0000')"],
["${expression} === '2'", "color('#00FF00')"],
["true", "color('#FFFFFF')"]
]
}
Expand Down
2 changes: 1 addition & 1 deletion Specs/Scene/ConditionsExpressionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defineSuite([

var jsonExpWithUndefinedExpression = {
conditions : [
['${expression} == undefined', 'color("blue")'],
['${expression} === undefined', 'color("blue")'],
['true', 'color("lime")']
]
};
Expand Down
141 changes: 59 additions & 82 deletions Specs/Scene/ExpressionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,20 +1010,6 @@ defineSuite([
expect(expression.evaluate(frameState, undefined)).toEqual(false);
});

it('evaluates binary equals', function() {
var expression = new Expression('\'hello\' == \'hello\'');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('1 == 2');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('false == true == false');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('1 == "1"');
expect(expression.evaluate(frameState, undefined)).toEqual(true);
});

it('evaluates binary not equals strict', function() {
var expression = new Expression('\'hello\' !== \'hello\'');
expect(expression.evaluate(frameState, undefined)).toEqual(false);
Expand All @@ -1038,20 +1024,6 @@ defineSuite([
expect(expression.evaluate(frameState, undefined)).toEqual(true);
});

it('evaluates binary not equals', function() {
var expression = new Expression('\'hello\' != \'hello\'');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('1 != 2');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('false != true != false');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('1 != "1"');
expect(expression.evaluate(frameState, undefined)).toEqual(false);
});

it('evaluates binary less than', function() {
var expression = new Expression('2 < 3');
expect(expression.evaluate(frameState, undefined)).toEqual(true);
Expand Down Expand Up @@ -1278,15 +1250,9 @@ defineSuite([
expression = new Expression('rgba(255, 255, 255, 1.0) % rgba(255, 255, 255, 1.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);

expression = new Expression('color() == color()');
expression = new Expression('color(\'green\') === color(\'green\')');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('color(\'green\') != color(\'green\')');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('color(\'green\') !== color(\'green\')');
expect(expression.evaluate(frameState, undefined)).toEqual(false);
});
Expand Down Expand Up @@ -1382,15 +1348,6 @@ defineSuite([
expression = new Expression('vec4(2, 3, 4, 5) % vec4(3, 3, 3, 2)');
expect(expression.evaluate(frameState, undefined)).toEqual(new Cartesian4(2, 0, 1, 1));

expression = new Expression('vec2(1, 3) == vec2(1, 3)');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('vec3(1, 3, 4) == vec3(1, 3, 4)');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('vec4(1, 3, 4, 6) == vec4(1, 3, 4, 6)');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('vec2(1, 2) === vec2(1, 2)');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

Expand All @@ -1400,15 +1357,6 @@ defineSuite([
expression = new Expression('vec4(1, 2, 3, 4) === vec4(1, 2, 3, 4)');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('vec2(1, 2) != vec2(1, 2)');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('vec3(1, 2, 3) != vec3(1, 2, 3)');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('vec4(1, 2, 3, 4) != vec4(1, 2, 3, 4)');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('vec2(1, 2) !== vec2(1, 2)');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

Expand Down Expand Up @@ -2358,7 +2306,7 @@ defineSuite([
vector : Cartesian4.UNIT_X
});

expression = new Expression('${feature} == ${feature.feature}');
expression = new Expression('${feature} === ${feature.feature}');
expect(expression.evaluate(frameState, feature)).toEqual(true);
});

Expand Down Expand Up @@ -2443,6 +2391,18 @@ defineSuite([
expect(expression.evaluate(frameState, feature)).toEqual(true);
});

it('throws if regex test function has invalid arguments', function() {
var expression = new Expression('regExp("1").test(1)');
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();

expression = new Expression('regExp("a").test(regExp("b"))');
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();
});

it('evaluates regex exec function', function() {
var feature = new MockFeature();
feature.addProperty('property', 'abc');
Expand All @@ -2467,6 +2427,18 @@ defineSuite([
expect(expression.evaluate(frameState, feature)).toEqual('1');
});

it('throws if regex exec function has invalid arguments', function() {
var expression = new Expression('regExp("1").exec(1)');
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();

expression = new Expression('regExp("a").exec(regExp("b"))');
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();
});

it('evaluates regex match operator', function() {
var feature = new MockFeature();
feature.addProperty('property', 'abc');
Expand All @@ -2486,17 +2458,28 @@ defineSuite([
expression = new Expression('regExp("quick\\s(brown).+?(jumps)", "ig") =~ "The Quick Brown Fox Jumps Over The Lazy Dog"');
expect(expression.evaluate(frameState, undefined)).toEqual(true);

expression = new Expression('regExp("a") =~ 1');
expect(expression.evaluate(frameState, undefined)).toEqual(false);
expression = new Expression('regExp(${property}) =~ ${property}');
expect(expression.evaluate(frameState, feature)).toEqual(true);
});

it('throws if regex match operator has invalid arguments', function() {
var feature = new MockFeature();
feature.addProperty('property', 'abc');

var expression = new Expression('regExp("a") =~ 1');
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();

expression = new Expression('1 =~ regExp("a")');
expect(expression.evaluate(frameState, undefined)).toEqual(false);
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();

expression = new Expression('1 =~ 1');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('regExp(${property}) =~ ${property}');
expect(expression.evaluate(frameState, feature)).toEqual(true);
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();
});

it('evaluates regex not match operator', function() {
Expand All @@ -2518,17 +2501,25 @@ defineSuite([
expression = new Expression('regExp("quick\\s(brown).+?(jumps)", "ig") !~ "The Quick Brown Fox Jumps Over The Lazy Dog"');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('regExp("a") !~ 1');
expect(expression.evaluate(frameState, undefined)).toEqual(true);
expression = new Expression('regExp(${property}) !~ ${property}');
expect(expression.evaluate(frameState, feature)).toEqual(false);
});

it('throws if regex not match operator has invalid arguments', function() {
var expression = new Expression('regExp("a") !~ 1');
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();

expression = new Expression('1 !~ regExp("a")');
expect(expression.evaluate(frameState, undefined)).toEqual(true);
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();

expression = new Expression('1 !~ 1');
expect(expression.evaluate(frameState, undefined)).toEqual(false);

expression = new Expression('regExp(${property}) !~ ${property}');
expect(expression.evaluate(frameState, feature)).toEqual(false);
expect(function() {
expression.evaluate(frameState, undefined);
}).toThrowDeveloperError();
});

it('throws if test is not called with a RegExp', function() {
Expand Down Expand Up @@ -2708,27 +2699,13 @@ defineSuite([
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for binary equals', function() {
var expression = new Expression('1.0 == 2.0');
var shaderExpression = expression.getShaderExpression('', {});
var expected = '(1.0 == 2.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for binary not equals strict', function() {
var expression = new Expression('1.0 !== 2.0');
var shaderExpression = expression.getShaderExpression('', {});
var expected = '(1.0 != 2.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for binary not equals', function() {
var expression = new Expression('1.0 != 2.0');
var shaderExpression = expression.getShaderExpression('', {});
var expected = '(1.0 != 2.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for binary less than', function() {
var expression = new Expression('1.0 < 2.0');
var shaderExpression = expression.getShaderExpression('', {});
Expand Down