Cartographic.fromCartesian() returns undefined for a point in the origin, that is Cartesian3(0, 0, 0). I checked the source code of scaleToGeodeticSurface and in line 73 undefined is returned if ratio is infinite, and in turn Cartographic.fromCartesian() returns undefined. Are there any scenarios where returning undefined is preferred to returning a Cartographic point in the origin, such as Cartographic(0, 0, -Ellipsoid.default.radii.x)? Just wondering if this edge case should be handled by the developers or whether it is worth creating a pull request with a fix. Thanks!
This is “tracked” in Rendering error for entity at origin · Issue #12150 · CesiumGS/cesium · GitHub with a pending PR and some additional considerations ( tagging @mzschwartz5 : Not sure about the state of Safeguards project from undefined cartographic value by mzschwartz5 · Pull Request #12671 · CesiumGS/cesium · GitHub )
That was the first issue I picked up for Cesium… would not say I have plans to get back to it any time soon. It was mired down by indecision about how to best handle the scenario, but also seemed like a relatively low impact issue for all the discussion it was generating…
If you’re interested, definitely give the linked issue / PR a read - maybe there’s an easy way forward I just didn’t have the experience to see at the time.
I had a look at the comments on the issue and the PR. I think that if Cartesian(0, 0, 0) is a valid point, then both Cartographic.fromCartesian() and Ellipsoid.cartesianToCartographic() should return an valid instance of Cartographic rather than undefined. Both methods call scaleToGeodeticSurface() and then they do
if (!defined(p)) {
return undefined;
}
The code above has an additional problem. A result passed as an input is not modified in this scenario, and therefore the value of result and the value returned by the function are different.
I would replace the code above with:
if (!defined(p)) {
const origin = new Cartographic(0, 0, ellipsoid ? -ellipsoid.radii.x : -Ellipsoid.default.radii.x);
if (!result) {
return origin;
}
result.longitude = origin.longitude;
result.latitude = origin.latitude;
result.height = origin.height;
return result;
}