-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
improve sanity check for geodesic distance calc #7457
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,14 +171,18 @@ define([ | |
ellipsoidGeodesic._uSquared = uSquared; | ||
} | ||
|
||
//>>includeStart('debug', pragmas.debug); | ||
var scratchCart1 = new Cartesian3(); | ||
var scratchCart2 = new Cartesian3(); | ||
//>>includeEnd('debug'); | ||
function computeProperties(ellipsoidGeodesic, start, end, ellipsoid) { | ||
var firstCartesian = Cartesian3.normalize(ellipsoid.cartographicToCartesian(start, scratchCart2), scratchCart1); | ||
var lastCartesian = Cartesian3.normalize(ellipsoid.cartographicToCartesian(end, scratchCart2), scratchCart2); | ||
|
||
//>>includeStart('debug', pragmas.debug); | ||
Check.typeOf.number.greaterThanOrEquals('value', Math.abs(Math.abs(Cartesian3.angleBetween(firstCartesian, lastCartesian)) - Math.PI), 0.0125); | ||
var startCartesian = Cartesian3.normalize(ellipsoid.cartographicToCartesian(start, scratchCart2), scratchCart1); | ||
var endCartesian = Cartesian3.normalize(ellipsoid.cartographicToCartesian(end, scratchCart2), scratchCart2); | ||
var includedAngle = Math.abs(Math.abs(Cartesian3.angleBetween(startCartesian, endCartesian)) - CesiumMath.PI); | ||
// maxLambda is an approximation, assuming an oblate ellipsoid, and zero latitude (equatorial; phi = 0) | ||
var maxLambda = (1 - (ellipsoid.maximumRadius - ellipsoid.minimumRadius) / ellipsoid.maximumRadius) * CesiumMath.PI; | ||
Check.typeOf.number.lessThanOrEquals('value', includedAngle, maxLambda); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved that logic into the pragma block because it is only used for the check. |
||
//>>includeEnd('debug'); | ||
|
||
vincentyInverseFormula(ellipsoidGeodesic, ellipsoid.maximumRadius, ellipsoid.minimumRadius, | ||
|
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.
I wonder about these scratch variables:
Why do these scratch variables live outside the only scope they're used?
Why use scratch variables like this?
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 debugging (the web worker) I ran into a case where the "subdivide heights" scratch array had a zero-length even though the code that was being debugged had presumably just initialized it... I reproduced it once after a refresh (left the debugger open). I've noticed strange behavior while debugging web workers with Chrome, so it's possible it's an artifact of that and not an issue with the logic (shared scratch) and some kind of race condition (between worker/worker or worker/main -- ... apologies I'm not well versed 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.
The scratch variables are at this scope so they can be reused each time the function is called instead of creating new instances each time. This is something we do commonly for performance. See https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/CodingGuide#result-parameters-and-scratch-variables
So you'll need to remove the pragmas 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.
Same here with adding the pragma block: these scratch variables are only used for the debug check.