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 unary ops #4628

Merged
merged 23 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ec8ff9e
added sin, tan #4603
Dylan-Brown Nov 6, 2016
d4eaf60
added acos, asin, atan #4603
Dylan-Brown Nov 6, 2016
3c5b870
small adjustment for 3d demo, separated trig, arc trig functions #4603
Dylan-Brown Nov 6, 2016
8bafd01
added radians, degrees, not to demo #4603
Dylan-Brown Nov 6, 2016
68ac1a1
data driven #4603
Dylan-Brown Nov 10, 2016
c185368
data driven #4603 removed excess functions, added degrees/radians
Dylan-Brown Nov 10, 2016
9dd5f1e
forgot to delete a few lines #4603
Dylan-Brown Nov 10, 2016
5689d49
styling examples #4603
Dylan-Brown Nov 10, 2016
f951df0
fixed merge #4603
Dylan-Brown Nov 15, 2016
31a3e76
updated based on suggestions #4603
Dylan-Brown Nov 15, 2016
0f11c24
removed abs, sqrt section #4603
Dylan-Brown Nov 15, 2016
0477a6f
updated conversion from 0 radians to pi #4603
Dylan-Brown Nov 15, 2016
4ee3b34
removed duplicate functions, imported CesiumMath, styling update(?) #…
Dylan-Brown Nov 18, 2016
9cd51cf
#4603 found math issue
Dylan-Brown Nov 18, 2016
24cd1be
#4603 merge conflict resolved
Dylan-Brown Nov 18, 2016
6c56dac
includes? #5603
Dylan-Brown Nov 18, 2016
d6fa4d7
I really don't understand this define function and can't test so I'm …
Dylan-Brown Nov 18, 2016
91c6b69
#4603 hope this works
Dylan-Brown Nov 18, 2016
4463339
updated test cases
Dylan-Brown Nov 18, 2016
5d99266
nevermind
Dylan-Brown Nov 18, 2016
f94c4ce
alright
Dylan-Brown Nov 18, 2016
341c363
alright pt. 2
Dylan-Brown Nov 18, 2016
3b7f6e5
updated to reflect PI in the styling language
Dylan-Brown Nov 21, 2016
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
9 changes: 7 additions & 2 deletions Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@
color : "color() * abs(${temperature} - 0.5)"
});

addStyle('Cos', {
color : "color() * abs(cos(${temperature} + TILES3D_TILESET_TIME))"
addStyle('Trigonometric Functions', {
color : "color() * radians(cos(${temperature})) + color() * sin(${temperature}) + color() * tan(${temperature})"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but extra whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where I should put it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pjcozzi means just to remove it.

});

addStyle('Arc Trigonometric Functions', {
color : "color() * acos(degrees(${temperature})) + color() * asin(${temperature}) + color() * atan(${temperature})"
});

addStyle('Sqrt', {
Expand Down
62 changes: 27 additions & 35 deletions Source/Scene/Expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ define([
'../Core/defineProperties',
'../Core/DeveloperError',
'../Core/isArray',
'../Core/Math',
'../ThirdParty/jsep',
'./ExpressionNodeType'
], function(
Expand All @@ -13,6 +14,7 @@ define([
defineProperties,
DeveloperError,
isArray,
CesiumMath,
jsep,
ExpressionNodeType) {
"use strict";
Expand Down Expand Up @@ -43,6 +45,19 @@ define([
}
};

var unaryFunctions = {
abs : Math.abs,
sqrt : Math.sqrt,
cos : Math.cos,
sin : Math.sin,
tan : Math.tan,
acos : Math.acos,
asin : Math.asin,
atan : Math.atan,
radians : CesiumMath.toRadians,
degrees : CesiumMath.toDegrees
};

/**
* Evaluates an expression defined using the
* {@link https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/Styling|3D Tiles Styling language}.
Expand Down Expand Up @@ -340,23 +355,7 @@ define([
}
val = createRuntimeAst(expression, args[0]);
return new Node(ExpressionNodeType.UNARY, call, val);
} else if (call === 'abs') {
//>>includeStart('debug', pragmas.debug);
if (args.length < 1 || args.length > 1) {
throw new DeveloperError('Error: ' + call + ' requires exactly one argument.');
}
//>>includeEnd('debug');
val = createRuntimeAst(expression, args[0]);
return new Node(ExpressionNodeType.UNARY, call, val);
} else if (call === 'cos') {
//>>includeStart('debug', pragmas.debug);
if (args.length < 1 || args.length > 1) {
throw new DeveloperError('Error: ' + call + ' requires exactly one argument.');
}
//>>includeEnd('debug');
val = createRuntimeAst(expression, args[0]);
return new Node(ExpressionNodeType.UNARY, call, val);
} else if (call === 'sqrt') {
} else if (defined(unaryFunctions[call])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the abs section above.

//>>includeStart('debug', pragmas.debug);
if (args.length < 1 || args.length > 1) {
throw new DeveloperError('Error: ' + call + ' requires exactly one argument.');
Expand Down Expand Up @@ -599,12 +598,8 @@ define([
node.evaluate = node._evaluateNaN;
} else if (node._value === 'isFinite') {
node.evaluate = node._evaluateIsFinite;
} else if (node._value === 'abs') {
node.evaluate = node._evaluateAbsoluteValue;
} else if (node._value === 'cos') {
node.evaluate = node._evaluateCosine;
} else if (node._value === 'sqrt') {
node.evaluate = node._evaluateSquareRoot;
} else if (defined(unaryFunctions[node._value])) {
node.evaluate = getEvaluateUnaryFunction(node._value);
} else if (node._value === 'Boolean') {
node.evaluate = node._evaluateBooleanConversion;
} else if (node._value === 'Number') {
Expand Down Expand Up @@ -643,6 +638,13 @@ define([
return feature._content._tileset.timeSinceLoad;
}

function getEvaluateUnaryFunction(call) {
var evaluate = unaryFunctions[call];
return function(feature) {
return evaluate(this._left.evaluate(feature));
};
}

Node.prototype._evaluateLiteral = function(frameState, feature) {
return this._value;
};
Expand Down Expand Up @@ -940,18 +942,6 @@ define([
return isFinite(this._left.evaluate(frameState, feature));
};

Node.prototype._evaluateAbsoluteValue = function(frameState, feature) {
return Math.abs(this._left.evaluate(frameState, feature));
};

Node.prototype._evaluateCosine = function(frameState, feature) {
return Math.cos(this._left.evaluate(frameState, feature));
};

Node.prototype._evaluateSquareRoot = function(frameState, feature) {
return Math.sqrt(this._left.evaluate(frameState, feature));
};

Node.prototype._evaluateBooleanConversion = function(frameState, feature) {
return Boolean(this._left.evaluate(frameState, feature));
};
Expand Down Expand Up @@ -1169,6 +1159,8 @@ define([
return 'bool(' + left + ')';
} else if (value === 'Number') {
return 'float(' + left + ')';
} else if (defined(unaryFunctions[value])) {
return value + '(' + left + ')';
} else if (value === 'abs') {
return 'abs(' + left + ')';
} else if (value === 'cos') {
Expand Down
142 changes: 142 additions & 0 deletions Specs/Scene/ExpressionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
defineSuite([
'Scene/Expression',
'Core/Color',
'Core/Math',
'Scene/ExpressionNodeType'
], function(
Expression,
Color,
CesiumMath,
ExpressionNodeType) {
'use strict';

Expand Down Expand Up @@ -860,6 +862,111 @@ defineSuite([
}).toThrowDeveloperError();
});

it('evaluates sin function', function() {
var expression = new Expression('sin(0)');
expect(expression.evaluate(undefined)).toEqual(0);
});

it('throws if sin function takes an invalid number of arguments', function() {
expect(function() {
return new Expression('sin()');
}).toThrowDeveloperError();

expect(function() {
return new Expression('sin(1, 2)');
}).toThrowDeveloperError();
});

it('evaluates tan function', function() {
var expression = new Expression('tan(0)');
expect(expression.evaluate(undefined)).toEqual(0);
});

it('throws if tan function takes an invalid number of arguments', function() {
expect(function() {
return new Expression('tan()');
}).toThrowDeveloperError();

expect(function() {
return new Expression('tan(1, 2)');
}).toThrowDeveloperError();
});

it('evaluates acos function', function() {
var expression = new Expression('acos(1)');
expect(expression.evaluate(undefined)).toEqual(0);
});

it('throws if acos function takes an invalid number of arguments', function() {
expect(function() {
return new Expression('acos()');
}).toThrowDeveloperError();

expect(function() {
return new Expression('acos(1, 2)');
}).toThrowDeveloperError();
});

it('evaluates asin function', function() {
var expression = new Expression('asin(0)');
expect(expression.evaluate(undefined)).toEqual(0);
});

it('throws if asin function takes an invalid number of arguments', function() {
expect(function() {
return new Expression('asin()');
}).toThrowDeveloperError();

expect(function() {
return new Expression('asin(1, 2)');
}).toThrowDeveloperError();
});

it('evaluates atan function', function() {
var expression = new Expression('atan(0)');
expect(expression.evaluate(undefined)).toEqual(0);
});

it('throws if atan function takes an invalid number of arguments', function() {
expect(function() {
return new Expression('atan()');
}).toThrowDeveloperError();

expect(function() {
return new Expression('atan(1, 2)');
}).toThrowDeveloperError();
});

it('evaluates radians function', function() {
var expression = new Expression('radians(180)');
expect(expression.evaluate(undefined)).toEqualEpsilon(Math.PI, CesiumMath.EPSILON10);
});

it('throws if radians function takes an invalid number of arguments', function() {
expect(function() {
return new Expression('radians()');
}).toThrowDeveloperError();

expect(function() {
return new Expression('radians(1, 2)');
}).toThrowDeveloperError();
});

it('evaluates degrees function', function() {
var expression = new Expression('degrees(2 * PI)');
expect(expression.evaluate(undefined)).toEqualEpsilon(360, CesiumMath.EPSILON10);
});

it('throws if degrees function takes an invalid number of arguments', function() {
expect(function() {
return new Expression('degrees()');
}).toThrowDeveloperError();

expect(function() {
return new Expression('degrees(1, 2)');
});
});

it('evaluates sqrt function', function() {
var expression = new Expression('sqrt(1.0)');
expect(expression.evaluate(frameState, undefined)).toEqual(1.0);
Expand Down Expand Up @@ -1658,6 +1765,41 @@ defineSuite([
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for sin', function() {
var expression = new Expression('sin(0.0)');
var shaderExpression = expression.getShaderExpression('', {});
var expected = 'sin(0.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for tan', function() {
var expression = new Expression('tan(0.0)');
var shaderExpression = expression.getShaderExpression('', {});
var expected = 'tan(0.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for acos', function() {
var expression = new Expression('acos(0.0)');
var shaderExpression = expression.getShaderExpression('', {});
var expected = 'acos(0.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for asin', function() {
var expression = new Expression('asin(0.0)');
var shaderExpression = expression.getShaderExpression('', {});
var expected = 'asin(0.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for atan', function() {
var expression = new Expression('atan(0.0)');
var shaderExpression = expression.getShaderExpression('', {});
var expected = 'atan(0.0)';
expect(shaderExpression).toEqual(expected);
});

it('gets shader expression for sqrt', function() {
var expression = new Expression('sqrt(1.0)');
var shaderExpression = expression.getShaderExpression('', {});
Expand Down