-
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
pragmatically and precisely compute ellipse rectangle on demand #6382
Merged
hpinkos
merged 3 commits into
CesiumGS:master
from
likangning93:fixEllipseRectanglePragmatic
Mar 28, 2018
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -653,37 +653,30 @@ define([ | |
}; | ||
} | ||
|
||
var scratchEnuToFixedMatrix = new Matrix4(); | ||
var scratchFixedToEnuMatrix = new Matrix4(); | ||
var scratchRotationMatrix = new Matrix3(); | ||
var scratchRectanglePoints = [new Cartesian3(), new Cartesian3(), new Cartesian3(), new Cartesian3()]; | ||
var scratchCartographicPoints = [new Cartographic(), new Cartographic(), new Cartographic(), new Cartographic()]; | ||
|
||
function computeRectangle(center, ellipsoid, semiMajorAxis, semiMinorAxis, rotation) { | ||
Transforms.eastNorthUpToFixedFrame(center, ellipsoid, scratchEnuToFixedMatrix); | ||
Matrix4.inverseTransformation(scratchEnuToFixedMatrix, scratchFixedToEnuMatrix); | ||
|
||
// Find the 4 extreme points of the ellipse in ENU | ||
var i; | ||
for (i = 0; i < 4; ++i) { | ||
Cartesian3.clone(Cartesian3.ZERO, scratchRectanglePoints[i]); | ||
} | ||
scratchRectanglePoints[0].x += semiMajorAxis; | ||
scratchRectanglePoints[1].x -= semiMajorAxis; | ||
scratchRectanglePoints[2].y += semiMinorAxis; | ||
scratchRectanglePoints[3].y -= semiMinorAxis; | ||
|
||
Matrix3.fromRotationZ(rotation, scratchRotationMatrix); | ||
for (i = 0; i < 4; ++i) { | ||
// Apply the rotation | ||
Matrix3.multiplyByVector(scratchRotationMatrix, scratchRectanglePoints[i], scratchRectanglePoints[i]); | ||
|
||
// Convert back to fixed and then to cartographic | ||
Matrix4.multiplyByPoint(scratchEnuToFixedMatrix, scratchRectanglePoints[i], scratchRectanglePoints[i]); | ||
ellipsoid.cartesianToCartographic(scratchRectanglePoints[i], scratchCartographicPoints[i]); | ||
} | ||
|
||
return Rectangle.fromCartographicArray(scratchCartographicPoints); | ||
function computeRectangle(ellipseGeometry) { | ||
var cep = EllipseGeometryLibrary.computeEllipsePositions({ | ||
center : ellipseGeometry._center, | ||
semiMajorAxis : ellipseGeometry._semiMajorAxis, | ||
semiMinorAxis : ellipseGeometry._semiMinorAxis, | ||
rotation : ellipseGeometry._rotation, | ||
granularity : ellipseGeometry._granularity | ||
}, false, true); | ||
var positionsFlat = cep.outerPositions; | ||
var positionsCount = positionsFlat.length / 3; | ||
var positions = new Array(positionsCount); | ||
for (var i = 0; i < positionsCount; ++i) { | ||
positions[i] = Cartesian3.fromArray(positionsFlat, i * 3); | ||
} | ||
var rectangle = Rectangle.fromCartesianArray(positions); | ||
// Rectangle width goes beyond 180 degrees when the ellipse crosses a pole. | ||
// When this happens, make the rectangle into a "circle" around the pole | ||
if (rectangle.width > CesiumMath.PI) { | ||
rectangle.north = rectangle.north > 0.0 ? CesiumMath.PI_OVER_TWO - CesiumMath.EPSILON7 : rectangle.north; | ||
rectangle.south = rectangle.south < 0.0 ? CesiumMath.EPSILON7 - CesiumMath.PI_OVER_TWO : rectangle.south; | ||
rectangle.east = CesiumMath.PI; | ||
rectangle.west = -CesiumMath.PI; | ||
} | ||
return rectangle; | ||
} | ||
|
||
/** | ||
|
@@ -766,14 +759,14 @@ define([ | |
this._shadowVolume = defaultValue(options.shadowVolume, false); | ||
this._workerName = 'createEllipseGeometry'; | ||
|
||
this._rectangle = computeRectangle(this._center, this._ellipsoid, semiMajorAxis, semiMinorAxis, this._rotation); | ||
this._rectangle = undefined; | ||
} | ||
|
||
/** | ||
* The number of elements used to pack the object into an array. | ||
* @type {Number} | ||
*/ | ||
EllipseGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 9; | ||
EllipseGeometry.packedLength = Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 9; | ||
|
||
/** | ||
* Stores the provided instance into the provided array. | ||
|
@@ -805,9 +798,6 @@ define([ | |
VertexFormat.pack(value._vertexFormat, array, startingIndex); | ||
startingIndex += VertexFormat.packedLength; | ||
|
||
Rectangle.pack(value._rectangle, array, startingIndex); | ||
startingIndex += Rectangle.packedLength; | ||
|
||
array[startingIndex++] = value._semiMajorAxis; | ||
array[startingIndex++] = value._semiMinorAxis; | ||
array[startingIndex++] = value._rotation; | ||
|
@@ -824,7 +814,6 @@ define([ | |
var scratchCenter = new Cartesian3(); | ||
var scratchEllipsoid = new Ellipsoid(); | ||
var scratchVertexFormat = new VertexFormat(); | ||
var scratchRectangle = new Rectangle(); | ||
var scratchOptions = { | ||
center : scratchCenter, | ||
ellipsoid : scratchEllipsoid, | ||
|
@@ -865,9 +854,6 @@ define([ | |
var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat); | ||
startingIndex += VertexFormat.packedLength; | ||
|
||
var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle); | ||
startingIndex += Rectangle.packedLength; | ||
|
||
var semiMajorAxis = array[startingIndex++]; | ||
var semiMinorAxis = array[startingIndex++]; | ||
var rotation = array[startingIndex++]; | ||
|
@@ -902,7 +888,6 @@ define([ | |
result._extrudedHeight = extrudedHeight; | ||
result._extrude = extrude; | ||
result._shadowVolume = shadowVolume; | ||
result._rectangle = Rectangle.clone(rectangle); | ||
|
||
return result; | ||
}; | ||
|
@@ -980,6 +965,9 @@ define([ | |
*/ | ||
rectangle : { | ||
get : function() { | ||
if (!defined(this._rectangle)) { | ||
this._rectangle = computeRectangle(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. It can be in a separate PR, but we should also update |
||
} | ||
return this._rectangle; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this needed anymore?