-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Draft of support for vectors in binary and ternary expressions #5044
Conversation
I'm not sure if it's my throw new DeveloperError notation that's wrong, but I don't see why all of my Error-throwing tests are failing :( The good news is, properly-formated expression calls seem to all be passing!
|
Dylan just took a look and couldn't figure out why these cases aren't throwing errors properly. Could you take a look at my syntax quickly? Thanks! |
Sure, I'll take a look at this later today. |
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.
This is an awesome start!
Specs/Scene/ExpressionSpec.js
Outdated
expect(expression.evaluate(frameState, undefined).x).toEqualEpsilon(0.0, CesiumMath.EPSILON10); | ||
expect(expression.evaluate(frameState, undefined).y).toEqualEpsilon(0.5 * Math.PI, CesiumMath.EPSILON10); | ||
expect(expression.evaluate(frameState, undefined).z).toEqualEpsilon(0.25 * Math.PI, CesiumMath.EPSILON10); | ||
expect(expression.evaluate(frameState, undefined).w).toEqualEpsilon(0.5 * Math.PI, CesiumMath.EPSILON10); |
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.
For each of these, just evaluate the expression once and do a toEqualEpsilon
on a Cartesian, like evaluates pow function
below.
Specs/Scene/ExpressionSpec.js
Outdated
|
||
expression = new Expression('pow(vec4(5,4,3,2),vec4(0,2,3,5))'); | ||
expect(expression.evaluate(frameState, undefined)).toEqual(new Cartesian4(1.0, 16.0, 27.0, 32.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.
Specs/Scene/ExpressionSpec.js
Outdated
@@ -2089,12 +2104,36 @@ defineSuite([ | |||
}).toThrowDeveloperError(); | |||
}); | |||
|
|||
it('throws if atan2 function takes invalid types / instances 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.
Just throws if atan2 function takes mismatching types
is fine.
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.
Same comment for the other tests.
Specs/Scene/ExpressionSpec.js
Outdated
}).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.
Source/Scene/Expression.js
Outdated
atan2 : { evaluate: Math.atan2, requireTypeMatch: true }, | ||
pow : { evaluate: Math.pow, requireTypeMatch: true }, | ||
min : { evaluate: Math.min, requireTypeMatch: false }, | ||
max : { evaluate: Math.max, requireTypeMatch: false } |
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.
While this is more automated, I think its slightly overbuilt considering there are only 4 function. It should be fine to check the call name in getEvaluateBinaryFunction
and apply the special cases.
For those cases the error is thrown when the expression is evaluated, not when it's created. Take a look at https://github.com/AnalyticalGraphicsInc/cesium/blob/3d-tiles/Specs/Scene/ExpressionSpec.js#L815-L820 and others. |
Also what errors are your receiving when running locally? Are you able to access the page at http://localhost:8080? Edit: this sounds like a build issue - if you run |
@Jane-Of-Art any updates here? |
@lilleyse Apologies, we were on spring break last week! All rested now and will update this ticket later this week :) |
Vector support for binary and ternary should all be here now! Your comments have been addressed and all tests should work. The tests now run locally as well, so thanks for the |
As far as I can tell, the build errors are all rendering related, and the ExpressionSpec has passed. Can you tell if it's an error in the files that I edited? Thanks! |
One of those errors should be fixed in #5100, but yeah they seem unrelated to this code. I'll review soon. |
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. I just left some small style suggestions.
@@ -2143,6 +2292,19 @@ defineSuite([ | |||
}).toThrowDeveloperError(); | |||
}); | |||
|
|||
it('throws if min function takes mismatching types', 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.
min
-> max
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.
Changed min -> max in the correct location below. I believe it should be min here
Specs/Scene/ExpressionSpec.js
Outdated
}).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.
Source/Scene/Expression.js
Outdated
}; | ||
} | ||
|
||
function getEvaluateTernaryFunction(call) { | ||
var evaluate = ternaryFunctions[call]; | ||
return function(feature) { | ||
return evaluate(this._left.evaluate(feature), this._right.evaluate(feature), this._test.evaluate(feature)); | ||
|
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.
Comments fixed, functionality for length and normalize added. I can delete the length functionality this week if you prefer the other implementation, but Dylan wanted me to implement it this week and I was pretty much done so I figured I'd include it for now. Also, I noticed that there were shaderExpression tests at the bottom of the expressionSpec. Is that something we should worry about writing? Thanks! |
Specs/Scene/ExpressionSpec.js
Outdated
@@ -2011,11 +2011,61 @@ defineSuite([ | |||
|
|||
it('throws if fract function takes an invalid number of arguments', function() { | |||
expect(function() { | |||
return new Expression('log2()'); | |||
return new Expression('fract()'); | |||
}).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.
Fixed what I believe was a copy & paste error here
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.
Ah yes, thanks for fixing that!
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.
Ah... looks like this was already fixed in 3d-tiles
actually.
Source/Scene/Expression.js
Outdated
return 1.0; | ||
} else if (arg instanceof Cartesian2) { | ||
length = Cartesian2.magnitude(arg); | ||
return Cartesian2.fromElements(arg.x / length, arg.y / length, ScratchStorage.getCartesian2()); |
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.
Use Cartesian2.normalize
instead.
Specs/Scene/ExpressionSpec.js
Outdated
@@ -2011,11 +2011,61 @@ defineSuite([ | |||
|
|||
it('throws if fract function takes an invalid number of arguments', function() { | |||
expect(function() { | |||
return new Expression('log2()'); | |||
return new Expression('fract()'); | |||
}).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.
Ah yes, thanks for fixing that!
Specs/Scene/ExpressionSpec.js
Outdated
@@ -2011,11 +2011,61 @@ defineSuite([ | |||
|
|||
it('throws if fract function takes an invalid number of arguments', function() { | |||
expect(function() { | |||
return new Expression('log2()'); | |||
return new Expression('fract()'); | |||
}).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.
Ah... looks like this was already fixed in 3d-tiles
actually.
It's fine to take yours since you already finished it, I didn't know the other PR would come so soon. I like how
Yeah I forgot about that, please add tests there as well. |
Everything should be good now! Should I resolve the conflicts? These mostly arise from the fact that length is in there twice. |
Yes resolve the conflicts, just keep your versions. |
@Jane-Of-Art Still ready to go, just fix the merge conflicts. |
@lilleyse Rebased code! |
I think something went wrong, the PR now has a lot of extraneous files. Instead of a rebase could you try a merge? Or cherry-pick your commits on top of origin/3d-tiles and force push. |
Also sorry to add more work here, but #5040 is now merged and introduced some conflicts. |
@Jane-Of-Art @lilleyse what is the plan here? Do we want to get this into |
@Jane-Of-Art hopefully you don't mind but I fixed up the PR and fixed the merge conflicts. As before the code looks good, so this is ready to merge. |
Draft of the changes I'm proposing for supporting vectors in all binary expressions (min, max, pow, atan2). Unfortunately I couldn't get my local machine to run and check everything yet so I will have to see if all new specs pass!
This is a part of ticket #4865
@lilleyse @Dylan-Brown