-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
First commit with distance #5040
Conversation
@glee2244 in the future make a branch off of 3d-tiles and do your work there, this will make it easier to sync up your 3d-tiles branch with the origin. |
Ok yeah I see the problem now, Probably the best thing to do is be consistent with what's already there and set distance to point to a local function. (Example: https://github.com/AnalyticalGraphicsInc/cesium/blob/3d-tiles/Source/Scene/Expression.js#L107-L116). The function will just compute the distance between two numbers. Then inside |
You may just need to build, try running |
@glee2244 Do you have enough to go with here? |
@lilleyse Yes, thanks so much for the pointers! |
@lilleyse Should I be throwing a Developer Error if the distance function is called with mismatching inputs? For example, calling the distance between a number and a vec3? |
Yes, throw an error for those cases. |
@lilleyse I've pushed the changes as you've suggested, and it seems like the tests I've written pass, but I still get a failed check - Travis CI Build failed? Any ideas here? |
There are some unrelated test failures in the |
@lilleyse Alright, duly noted. I'm going to continue with implementing dot and cross. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far!
It's likely that #5044 will be merged first, so there may be some merge conflicts in getEvaluateBinaryFunction
.
Source/Scene/Expression.js
Outdated
isArray, | ||
CesiumMath, | ||
jsep, | ||
ExpressionNodeType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo this indentation changes in here and ExpressionSpec.js
.
However the rest of the formatting fixes seem fine.
Specs/Scene/ExpressionSpec.js
Outdated
@@ -2143,6 +2143,30 @@ defineSuite([ | |||
}).toThrowDeveloperError(); | |||
}); | |||
|
|||
it ('evaluates the distance function', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it (
-> it(
here and below.
return new Expression('distance(1, 3, 0)'); | ||
}).toThrowDeveloperError(); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also adds tests for mismatching types.
Pushing my implementations to dot and cross, but some of my tests are failing - will resolve them within the next couple days. |
@lilleyse Is cross meant to only take two parameters? I was trying to call Cartesian3.cross with two parameters but just realized that the function I wanted to use takes 3 (the third being the object onto which to store the result). https://cesiumjs.org/Cesium/Build/Documentation/Cartesian3.html?classFilter=Carte |
For that you can send in |
@lilleyse HI Sean, I've fixed my tests and some indentation/spacing that you pointed out before, and I've also refactored my implementations slightly. Let me know if there's anything else I should fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updates look good!
Source/Scene/Expression.js
Outdated
@@ -123,6 +126,44 @@ define([ | |||
|
|||
function log2(number) { | |||
return CesiumMath.logBase(number, 2.0); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
Source/Scene/Expression.js
Outdated
} else { | ||
throw new DeveloperError('Function dot requires matching types of inputs. Arguments are ' + x + ' and ' + y + '.'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
Source/Scene/Expression.js
Outdated
if (typeof x === 'number' && typeof y === 'number') { | ||
return Math.abs(x - y); | ||
} else if (x instanceof Cartesian2 && y instanceof Cartesian2) { | ||
return Cartesian2.distance(x ,y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting fix: (x ,y)
-> (x, y)
Source/Scene/Expression.js
Outdated
} else if (x instanceof Cartesian4 && y instanceof Cartesian4) { | ||
return Cartesian4.distance(x, y); | ||
} else { | ||
throw new DeveloperError('Function distance requires matching types of inputs. Arguments are ' + x + ' and ' + y + '.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap each of these three DeveloperError
with
//>>includeStart('debug', pragmas.debug);
throw new DeveloperError('.....')
//>>includeEnd('debug');
so that it is not included in release builds.
Source/Scene/Expression.js
Outdated
case ExpressionNodeType.LITERAL_UNDEFINED: | ||
//>>includeStart('debug', pragmas.debug); | ||
throw new DeveloperError('Error generating style shader: undefined is not supported.'); | ||
//>>includeEnd('debug'); | ||
//>>includeEnd('debug'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the indentation changes here.
Specs/Scene/ExpressionSpec.js
Outdated
it('throws if dot function takes an invalid number of arguments', function() { | ||
expect(function() { | ||
return new Expression('dot(0.0)'); | ||
}) .toThrowDeveloperError(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix formatting for }) .toThrowDeveloperError();
Specs/Scene/ExpressionSpec.js
Outdated
|
||
it('throws if distance function takes mismatching types of arguments', function() { | ||
expect(function() { | ||
return new Expression('distance(1, vec2(3.0, 2.0)').evaluate(frameState,undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: frameState,undefined
to frameState, undefined
for this and others.
Specs/Scene/ExpressionSpec.js
Outdated
}).toThrowDeveloperError(); | ||
}); | ||
|
||
it('throws if cross function takes mismatching types of arguments', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to throws if cross function does not take vec3 arguments
Specs/Scene/ExpressionSpec.js
Outdated
@@ -2167,6 +2266,7 @@ defineSuite([ | |||
}).toThrowDeveloperError(); | |||
}); | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line.
@@ -3016,7 +3116,7 @@ defineSuite([ | |||
expect(shaderExpression).toEqual(expected); | |||
}); | |||
|
|||
it('gets shader expression for sin', function() { | |||
it('gets shader expression for sin', function() { | |||
var expression = new Expression('sin(0.0)'); | |||
var shaderExpression = expression.getShaderExpression('', {}); | |||
var expected = 'sin(0.0)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add tests for distance
, dot
, and cross
for the shader expressions? Similar to
it('gets shader expression for min', function() {
var expression = new Expression('min(3.0,5.0)');
var shaderExpression = expression.getShaderExpression('', {});
var expected = 'min(3.0, 5.0)';
expect(shaderExpression).toEqual(expected);
});
Have added shader expression tests for distance, dot and cross and fixed spacing/indentation as requested, except for reverting indentation for includes here - for some odd reason the indentation keeps going back to incorrect spacing even after I update and save it. Will try to resolve asap. |
Source/Scene/Expression.js
Outdated
if (x instanceof Cartesian3 && y instanceof Cartesian3) { | ||
return Cartesian3.cross(x, y, ScratchStorage.getCartesian3()); | ||
} else { | ||
throw new DeveloperError('Invalid argument type for cross() function, must be vec3'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap this with //>>includeStart('debug', pragmas.debug);
and //>>includeEnd('debug');
too
Source/Scene/Expression.js
Outdated
@@ -1623,7 +1672,7 @@ define([ | |||
case ExpressionNodeType.FUNCTION_CALL: | |||
//>>includeStart('debug', pragmas.debug); | |||
throw new DeveloperError('Error generating style shader: "' + value + '" is not supported.'); | |||
//>>includeEnd('debug'); | |||
//>>includeEnd('debug'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo all these indentations as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very close...
Source/Scene/Expression.js
Outdated
if (typeof x === 'number' && typeof y === 'number') { | ||
return x * y; | ||
} else if (x instanceof Cartesian2 && y instanceof Cartesian2) { | ||
return Cartesian2.dot(x ,y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to (x, y)
@@ -872,6 +875,7 @@ define([ | |||
var hasNormals = content._hasNormals; | |||
var hasBatchIds = content._hasBatchIds; | |||
var backFaceCulling = content._backFaceCulling; | |||
//var normalShading = content._normalShading; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this commented normalShading
code.
Can you remove the |
Thanks @glee2244! |
I've attempted to include distance in the styling language for vectors. But I'm still confused as to how Cartesian3.distance() could work when the inputs could be anything other than type vec3. I've also tried to run my tests on my local server but the SpecRunner doesn't seem to display anything.
Issue #4865
@Dylan-Brown