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

First commit with distance #5040

Merged
merged 12 commits into from
Apr 28, 2017
Merged

First commit with distance #5040

merged 12 commits into from
Apr 28, 2017

Conversation

glee2244
Copy link
Contributor

@glee2244 glee2244 commented Feb 27, 2017

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

@lilleyse
Copy link
Contributor

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

@lilleyse
Copy link
Contributor

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.

Ok yeah I see the problem now, distance, dot, and cross will need to be handled differently than the other binary functions because they are geometric operations / don't work component-wise like the others.

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 getEvaluateBinaryFunction there will need to be a special case for distance. It will be a separate block that looks similar to the if/else already there. For the number/number check, use the evaluate function that you set above. For the vector cases, use Cartesian2/3/4.distance on the left and right.

@lilleyse
Copy link
Contributor

I've also tried to run my tests on my local server but the SpecRunner doesn't seem to display anything.

You may just need to build, try running npm run build. This is important whenever switching between branches that have different files, like going between master and 3d-tiles.

@lilleyse
Copy link
Contributor

@glee2244 Do you have enough to go with here?

@glee2244
Copy link
Contributor Author

@lilleyse Yes, thanks so much for the pointers!

@glee2244
Copy link
Contributor Author

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

@lilleyse
Copy link
Contributor

Yes, throw an error for those cases.

@glee2244
Copy link
Contributor Author

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

@lilleyse
Copy link
Contributor

There are some unrelated test failures in the 3d-tiles branch right now, just ignore for now.

@glee2244
Copy link
Contributor Author

@lilleyse Alright, duly noted. I'm going to continue with implementing dot and cross.

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 so far!

It's likely that #5044 will be merged first, so there may be some merge conflicts in getEvaluateBinaryFunction.

isArray,
CesiumMath,
jsep,
ExpressionNodeType) {
Copy link
Contributor

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.

@@ -2143,6 +2143,30 @@ defineSuite([
}).toThrowDeveloperError();
});

it ('evaluates the distance function', function() {
Copy link
Contributor

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

Copy link
Contributor

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.

@glee2244
Copy link
Contributor Author

Pushing my implementations to dot and cross, but some of my tests are failing - will resolve them within the next couple days.

@glee2244
Copy link
Contributor Author

glee2244 commented Apr 3, 2017

@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

@lilleyse
Copy link
Contributor

lilleyse commented Apr 3, 2017

For that you can send in ScratchStorage.getCartesian3()

@glee2244
Copy link
Contributor Author

glee2244 commented Apr 9, 2017

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

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.

The updates look good!

@@ -123,6 +126,44 @@ define([

function log2(number) {
return CesiumMath.logBase(number, 2.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.

} else {
throw new DeveloperError('Function dot requires matching types of inputs. Arguments are ' + x + ' and ' + y + '.');
}

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.

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

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)

} 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 + '.');
Copy link
Contributor

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.

case ExpressionNodeType.LITERAL_UNDEFINED:
//>>includeStart('debug', pragmas.debug);
throw new DeveloperError('Error generating style shader: undefined is not supported.');
//>>includeEnd('debug');
//>>includeEnd('debug');
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 indentation changes here.

it('throws if dot function takes an invalid number of arguments', function() {
expect(function() {
return new Expression('dot(0.0)');
}) .toThrowDeveloperError();
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix formatting for }) .toThrowDeveloperError();


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

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.

}).toThrowDeveloperError();
});

it('throws if cross function takes mismatching types 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.

Rename to throws if cross function does not take vec3 arguments

@@ -2167,6 +2266,7 @@ defineSuite([
}).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.

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

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

@glee2244
Copy link
Contributor Author

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.

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

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

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

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.

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.

Very close...

if (typeof x === 'number' && typeof y === 'number') {
return x * y;
} else if (x instanceof Cartesian2 && y instanceof Cartesian2) {
return Cartesian2.dot(x ,y);
Copy link
Contributor

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

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.

@lilleyse
Copy link
Contributor

Can you remove the normalShading code entirely? That should only belong in the other PR.

@lilleyse
Copy link
Contributor

Thanks @glee2244!

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.

2 participants