Skip to content

Commit

Permalink
Merge pull request #6387 from AnalyticalGraphicsInc/rectangle-on-demand
Browse files Browse the repository at this point in the history
Only create rectangle for geometry if requested
  • Loading branch information
bagnell authored Mar 29, 2018
2 parents e247462 + ee48d68 commit fa3a642
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 41 deletions.
15 changes: 5 additions & 10 deletions Source/Core/CorridorGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,13 @@ define([
this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
this._shadowVolume = defaultValue(options.shadowVolume, false);
this._workerName = 'createCorridorGeometry';
this._rectangle = computeRectangle(positions, this._ellipsoid, width, this._cornerType);
this._rectangle = undefined;

/**
* The number of elements used to pack the object into an array.
* @type {Number}
*/
this.packedLength = 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 6;
this.packedLength = 1 + positions.length * Cartesian3.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 6;
}

/**
Expand Down Expand Up @@ -867,9 +867,6 @@ define([
VertexFormat.pack(value._vertexFormat, array, startingIndex);
startingIndex += VertexFormat.packedLength;

Rectangle.pack(value._rectangle, array, startingIndex);
startingIndex += Rectangle.packedLength;

array[startingIndex++] = value._width;
array[startingIndex++] = value._height;
array[startingIndex++] = value._extrudedHeight;
Expand All @@ -882,7 +879,6 @@ define([

var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
var scratchVertexFormat = new VertexFormat();
var scratchRectangle = new Rectangle();
var scratchOptions = {
positions : undefined,
ellipsoid : scratchEllipsoid,
Expand Down Expand Up @@ -925,9 +921,6 @@ define([
var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
startingIndex += VertexFormat.packedLength;

var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle);
startingIndex += Rectangle.packedLength;

var width = array[startingIndex++];
var height = array[startingIndex++];
var extrudedHeight = array[startingIndex++];
Expand All @@ -954,7 +947,6 @@ define([
result._extrudedHeight = extrudedHeight;
result._cornerType = cornerType;
result._granularity = granularity;
result._rectangle = Rectangle.clone(rectangle);
result._shadowVolume = shadowVolume;

return result;
Expand Down Expand Up @@ -1047,6 +1039,9 @@ define([
*/
rectangle : {
get : function() {
if (!defined(this._rectangle)) {
this._rectangle = computeRectangle(this._positions, this._ellipsoid, this._width, this._cornerType);
}
return this._rectangle;
}
}
Expand Down
26 changes: 11 additions & 15 deletions Source/Core/PolygonGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,18 +601,13 @@ define([
this._shadowVolume = defaultValue(options.shadowVolume, false);
this._workerName = 'createPolygonGeometry';

var positions = polygonHierarchy.positions;
if (!defined(positions) || positions.length < 3) {
this._rectangle = new Rectangle();
} else {
this._rectangle = Rectangle.fromCartesianArray(positions, ellipsoid);
}
this._rectangle = undefined;

/**
* The number of elements used to pack the object into an array.
* @type {Number}
*/
this.packedLength = PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 10;
this.packedLength = PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Ellipsoid.packedLength + VertexFormat.packedLength + 10;
}

/**
Expand Down Expand Up @@ -696,9 +691,6 @@ define([
VertexFormat.pack(value._vertexFormat, array, startingIndex);
startingIndex += VertexFormat.packedLength;

Rectangle.pack(value._rectangle, array, startingIndex);
startingIndex += Rectangle.packedLength;

array[startingIndex++] = value._height;
array[startingIndex++] = value._extrudedHeight;
array[startingIndex++] = value._granularity;
Expand All @@ -715,7 +707,6 @@ define([

var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
var scratchVertexFormat = new VertexFormat();
var scratchRectangle = new Rectangle();

//Only used to avoid inaability to default construct.
var dummyOptions = {
Expand Down Expand Up @@ -746,9 +737,6 @@ define([
var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
startingIndex += VertexFormat.packedLength;

var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle);
startingIndex += Rectangle.packedLength;

var height = array[startingIndex++];
var extrudedHeight = array[startingIndex++];
var granularity = array[startingIndex++];
Expand All @@ -775,7 +763,6 @@ define([
result._perPositionHeight = perPositionHeight;
result._closeTop = closeTop;
result._closeBottom = closeBottom;
result._rectangle = Rectangle.clone(rectangle);
result._shadowVolume = shadowVolume;
result.packedLength = packedLength;
return result;
Expand Down Expand Up @@ -931,6 +918,15 @@ define([
*/
rectangle : {
get : function() {
if (!defined(this._rectangle)) {
var positions = this._polygonHierarchy.positions;
if (!defined(positions) || positions.length < 3) {
this._rectangle = new Rectangle();
} else {
this._rectangle = Rectangle.fromCartesianArray(positions, this._ellipsoid);
}
}

return this._rectangle;
}
}
Expand Down
15 changes: 5 additions & 10 deletions Source/Core/RectangleGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,14 @@ define([
this._extrude = defined(options.extrudedHeight);
this._shadowVolume = defaultValue(options.shadowVolume, false);
this._workerName = 'createRectangleGeometry';
this._rotatedRectangle = computeRectangle(this._rectangle, this._ellipsoid, rotation);
this._rotatedRectangle = undefined;
}

/**
* The number of elements used to pack the object into an array.
* @type {Number}
*/
RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 7;
RectangleGeometry.packedLength = Rectangle.packedLength + Ellipsoid.packedLength + VertexFormat.packedLength + 7;

/**
* Stores the provided instance into the provided array.
Expand Down Expand Up @@ -698,9 +698,6 @@ define([
VertexFormat.pack(value._vertexFormat, array, startingIndex);
startingIndex += VertexFormat.packedLength;

Rectangle.pack(value._rotatedRectangle, array, startingIndex);
startingIndex += Rectangle.packedLength;

array[startingIndex++] = value._granularity;
array[startingIndex++] = value._surfaceHeight;
array[startingIndex++] = value._rotation;
Expand All @@ -713,7 +710,6 @@ define([
};

var scratchRectangle = new Rectangle();
var scratchRotatedRectangle = new Rectangle();
var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
var scratchOptions = {
rectangle : scratchRectangle,
Expand Down Expand Up @@ -751,9 +747,6 @@ define([
var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
startingIndex += VertexFormat.packedLength;

var rotatedRectangle = Rectangle.unpack(array, startingIndex, scratchRotatedRectangle);
startingIndex += Rectangle.packedLength;

var granularity = array[startingIndex++];
var surfaceHeight = array[startingIndex++];
var rotation = array[startingIndex++];
Expand Down Expand Up @@ -781,7 +774,6 @@ define([
result._stRotation = stRotation;
result._extrudedHeight = extrude ? extrudedHeight : undefined;
result._extrude = extrude;
result._rotatedRectangle = rotatedRectangle;
result._shadowVolume = shadowVolume;

return result;
Expand Down Expand Up @@ -892,6 +884,9 @@ define([
*/
rectangle : {
get : function() {
if (!defined(this._rotatedRectangle)) {
this._rotatedRectangle = computeRectangle(this._rectangle, this._ellipsoid, this._rotation);
}
return this._rotatedRectangle;
}
}
Expand Down
3 changes: 1 addition & 2 deletions Specs/Core/CorridorGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,10 @@ defineSuite([
width : 30000.0,
granularity : 0.1
});
var rectangle = new Rectangle(1.568055205533759, -0.5410504013439219, 1.573537448056034, -0.5235971737132246);

var packedInstance = [2, positions[0].x, positions[0].y, positions[0].z, positions[1].x, positions[1].y, positions[1].z];
packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z);
packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0);
packedInstance.push(rectangle.west, rectangle.south, rectangle.east, rectangle.north);
packedInstance.push(30000.0, 0.0, 0.0, 2.0, 0.1, 0.0);
createPackableSpecs(CorridorGeometry, corridor, packedInstance);
});
5 changes: 2 additions & 3 deletions Specs/Core/PolygonGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ defineSuite([
array.push(positions[i].x, positions[i].y, positions[i].z);
}
}
var rectangle = new Rectangle(-0.21642082724729672, 0.06108652381980151, -0.20943951023931984, 0.06981317007977318);

var packedInstance = [3.0, 1.0];
addPositions(packedInstance, positions);
packedInstance.push(3.0, 1.0);
Expand All @@ -696,7 +696,6 @@ defineSuite([
addPositions(packedInstance, holePositions1);
packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z);
packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0);
packedInstance.push(rectangle.west, rectangle.south, rectangle.east, rectangle.north);
packedInstance.push(0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 1.0, 0, 1, 0, 56);
packedInstance.push(0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 1.0, 0, 1, 0, 52);
createPackableSpecs(PolygonGeometry, polygon, packedInstance);
});
2 changes: 1 addition & 1 deletion Specs/Core/RectangleGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,6 @@ defineSuite([
granularity : 1.0,
ellipsoid : Ellipsoid.UNIT_SPHERE
});
var packedInstance = [-2.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -2.0, -1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
var packedInstance = [-2.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
createPackableSpecs(RectangleGeometry, rectangle, packedInstance);
});

0 comments on commit fa3a642

Please sign in to comment.