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

Draft of support for vectors in binary and ternary expressions #5044

Merged
merged 9 commits into from
May 12, 2017

Conversation

Jane-Of-Art
Copy link
Contributor

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

@Jane-Of-Art
Copy link
Contributor Author

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!

  Scene/Expression
    ✗ throws if atan2 function takes invalid types / instances of arguments
	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2110:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2114:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2118:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

    ✗ throws if pow function takes invalid types / instances of arguments
	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2152:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2156:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2160:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

    ✗ throws if min function takes invalid types / instances of arguments
	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2196:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2200:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

    ✗ throws if min function takes invalid types / instances of arguments
	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2236:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

	Expected function to throw DeveloperError.
	    at Specs/Scene/ExpressionSpec.js:2240:12
	    at Object.<anonymous> (Specs/customizeJasmine.js:80:30)

@Jane-Of-Art
Copy link
Contributor Author

@lilleyse

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!

@lilleyse
Copy link
Contributor

Sure, I'll take a look at this later today.

Copy link
Contributor

@lilleyse lilleyse left a 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!

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);
Copy link
Contributor

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.


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));

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line.

@@ -2089,12 +2104,36 @@ defineSuite([
}).toThrowDeveloperError();
});

it('throws if atan2 function takes invalid types / instances of arguments', function() {
Copy link
Contributor

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.

Copy link
Contributor

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.

}).toThrowDeveloperError();
});


Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line.

atan2 : { evaluate: Math.atan2, requireTypeMatch: true },
pow : { evaluate: Math.pow, requireTypeMatch: true },
min : { evaluate: Math.min, requireTypeMatch: false },
max : { evaluate: Math.max, requireTypeMatch: false }
Copy link
Contributor

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.

@lilleyse
Copy link
Contributor

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 :(

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.

@lilleyse
Copy link
Contributor

lilleyse commented Feb 28, 2017

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 npm run build does it work?

@lilleyse
Copy link
Contributor

@Jane-Of-Art any updates here?

@Jane-Of-Art
Copy link
Contributor Author

@lilleyse Apologies, we were on spring break last week! All rested now and will update this ticket later this week :)

@Jane-Of-Art
Copy link
Contributor Author

@lilleyse

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 npm run build suggestion :)

@Jane-Of-Art Jane-Of-Art changed the title Draft of support for vectors in binary expressions Draft of support for vectors in binary and ternary expressions Mar 20, 2017
@Jane-Of-Art
Copy link
Contributor Author

@lilleyse

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!
Jane

@lilleyse
Copy link
Contributor

One of those errors should be fixed in #5100, but yeah they seem unrelated to this code.

I'll review soon.

Copy link
Contributor

@lilleyse lilleyse left a 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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

min -> max

Copy link
Contributor Author

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

}).toThrowDeveloperError();
});


Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line.

};
}

function getEvaluateTernaryFunction(call) {
var evaluate = ternaryFunctions[call];
return function(feature) {
return evaluate(this._left.evaluate(feature), this._right.evaluate(feature), this._test.evaluate(feature));

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove empty line.

@Jane-Of-Art
Copy link
Contributor Author

@lilleyse @Dylan-Brown

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!
Jane

@@ -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();
Copy link
Contributor Author

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

Copy link
Contributor

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!

Copy link
Contributor

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.

return 1.0;
} else if (arg instanceof Cartesian2) {
length = Cartesian2.magnitude(arg);
return Cartesian2.fromElements(arg.x / length, arg.y / length, ScratchStorage.getCartesian2());
Copy link
Contributor

Choose a reason for hiding this comment

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

Use Cartesian2.normalize instead.

@@ -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();
Copy link
Contributor

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!

@@ -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();
Copy link
Contributor

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.

@lilleyse
Copy link
Contributor

I can delete the length functionality

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 length is separated out, and it makes me think we could do that for a lot of the special case functions, not just here but in #5040 .

Also, I noticed that there were shaderExpression tests at the bottom of the expressionSpec. Is that something we should worry about writing?

Yeah I forgot about that, please add tests there as well.

@glee2244 these comments also apply to #5040

@Jane-Of-Art
Copy link
Contributor Author

@lilleyse

Everything should be good now! Should I resolve the conflicts? These mostly arise from the fact that length is in there twice.

@lilleyse
Copy link
Contributor

lilleyse commented Apr 3, 2017

Yes resolve the conflicts, just keep your versions.

@lilleyse
Copy link
Contributor

@Jane-Of-Art Still ready to go, just fix the merge conflicts.

@Jane-Of-Art
Copy link
Contributor Author

@lilleyse Rebased code!

@lilleyse
Copy link
Contributor

lilleyse commented Apr 25, 2017

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.

@lilleyse
Copy link
Contributor

Also sorry to add more work here, but #5040 is now merged and introduced some conflicts.

@pjcozzi
Copy link
Contributor

pjcozzi commented May 10, 2017

@Jane-Of-Art @lilleyse what is the plan here? Do we want to get this into 3d-tiles soon so we get that branch in shape for master?

@lilleyse lilleyse mentioned this pull request May 10, 2017
23 tasks
@lilleyse
Copy link
Contributor

@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.

@lilleyse lilleyse merged commit abf3864 into CesiumGS:3d-tiles May 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants