Skip to content

Commit fa3a642

Browse files
authored
Merge pull request #6387 from AnalyticalGraphicsInc/rectangle-on-demand
Only create rectangle for geometry if requested
2 parents e247462 + ee48d68 commit fa3a642

6 files changed

+25
-41
lines changed

Source/Core/CorridorGeometry.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,13 @@ define([
823823
this._granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
824824
this._shadowVolume = defaultValue(options.shadowVolume, false);
825825
this._workerName = 'createCorridorGeometry';
826-
this._rectangle = computeRectangle(positions, this._ellipsoid, width, this._cornerType);
826+
this._rectangle = undefined;
827827

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

835835
/**
@@ -867,9 +867,6 @@ define([
867867
VertexFormat.pack(value._vertexFormat, array, startingIndex);
868868
startingIndex += VertexFormat.packedLength;
869869

870-
Rectangle.pack(value._rectangle, array, startingIndex);
871-
startingIndex += Rectangle.packedLength;
872-
873870
array[startingIndex++] = value._width;
874871
array[startingIndex++] = value._height;
875872
array[startingIndex++] = value._extrudedHeight;
@@ -882,7 +879,6 @@ define([
882879

883880
var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
884881
var scratchVertexFormat = new VertexFormat();
885-
var scratchRectangle = new Rectangle();
886882
var scratchOptions = {
887883
positions : undefined,
888884
ellipsoid : scratchEllipsoid,
@@ -925,9 +921,6 @@ define([
925921
var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
926922
startingIndex += VertexFormat.packedLength;
927923

928-
var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle);
929-
startingIndex += Rectangle.packedLength;
930-
931924
var width = array[startingIndex++];
932925
var height = array[startingIndex++];
933926
var extrudedHeight = array[startingIndex++];
@@ -954,7 +947,6 @@ define([
954947
result._extrudedHeight = extrudedHeight;
955948
result._cornerType = cornerType;
956949
result._granularity = granularity;
957-
result._rectangle = Rectangle.clone(rectangle);
958950
result._shadowVolume = shadowVolume;
959951

960952
return result;
@@ -1047,6 +1039,9 @@ define([
10471039
*/
10481040
rectangle : {
10491041
get : function() {
1042+
if (!defined(this._rectangle)) {
1043+
this._rectangle = computeRectangle(this._positions, this._ellipsoid, this._width, this._cornerType);
1044+
}
10501045
return this._rectangle;
10511046
}
10521047
}

Source/Core/PolygonGeometry.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -601,18 +601,13 @@ define([
601601
this._shadowVolume = defaultValue(options.shadowVolume, false);
602602
this._workerName = 'createPolygonGeometry';
603603

604-
var positions = polygonHierarchy.positions;
605-
if (!defined(positions) || positions.length < 3) {
606-
this._rectangle = new Rectangle();
607-
} else {
608-
this._rectangle = Rectangle.fromCartesianArray(positions, ellipsoid);
609-
}
604+
this._rectangle = undefined;
610605

611606
/**
612607
* The number of elements used to pack the object into an array.
613608
* @type {Number}
614609
*/
615-
this.packedLength = PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Ellipsoid.packedLength + VertexFormat.packedLength + Rectangle.packedLength + 10;
610+
this.packedLength = PolygonGeometryLibrary.computeHierarchyPackedLength(polygonHierarchy) + Ellipsoid.packedLength + VertexFormat.packedLength + 10;
616611
}
617612

618613
/**
@@ -696,9 +691,6 @@ define([
696691
VertexFormat.pack(value._vertexFormat, array, startingIndex);
697692
startingIndex += VertexFormat.packedLength;
698693

699-
Rectangle.pack(value._rectangle, array, startingIndex);
700-
startingIndex += Rectangle.packedLength;
701-
702694
array[startingIndex++] = value._height;
703695
array[startingIndex++] = value._extrudedHeight;
704696
array[startingIndex++] = value._granularity;
@@ -715,7 +707,6 @@ define([
715707

716708
var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
717709
var scratchVertexFormat = new VertexFormat();
718-
var scratchRectangle = new Rectangle();
719710

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

749-
var rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle);
750-
startingIndex += Rectangle.packedLength;
751-
752740
var height = array[startingIndex++];
753741
var extrudedHeight = array[startingIndex++];
754742
var granularity = array[startingIndex++];
@@ -775,7 +763,6 @@ define([
775763
result._perPositionHeight = perPositionHeight;
776764
result._closeTop = closeTop;
777765
result._closeBottom = closeBottom;
778-
result._rectangle = Rectangle.clone(rectangle);
779766
result._shadowVolume = shadowVolume;
780767
result.packedLength = packedLength;
781768
return result;
@@ -931,6 +918,15 @@ define([
931918
*/
932919
rectangle : {
933920
get : function() {
921+
if (!defined(this._rectangle)) {
922+
var positions = this._polygonHierarchy.positions;
923+
if (!defined(positions) || positions.length < 3) {
924+
this._rectangle = new Rectangle();
925+
} else {
926+
this._rectangle = Rectangle.fromCartesianArray(positions, this._ellipsoid);
927+
}
928+
}
929+
934930
return this._rectangle;
935931
}
936932
}

Source/Core/RectangleGeometry.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -663,14 +663,14 @@ define([
663663
this._extrude = defined(options.extrudedHeight);
664664
this._shadowVolume = defaultValue(options.shadowVolume, false);
665665
this._workerName = 'createRectangleGeometry';
666-
this._rotatedRectangle = computeRectangle(this._rectangle, this._ellipsoid, rotation);
666+
this._rotatedRectangle = undefined;
667667
}
668668

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

675675
/**
676676
* Stores the provided instance into the provided array.
@@ -698,9 +698,6 @@ define([
698698
VertexFormat.pack(value._vertexFormat, array, startingIndex);
699699
startingIndex += VertexFormat.packedLength;
700700

701-
Rectangle.pack(value._rotatedRectangle, array, startingIndex);
702-
startingIndex += Rectangle.packedLength;
703-
704701
array[startingIndex++] = value._granularity;
705702
array[startingIndex++] = value._surfaceHeight;
706703
array[startingIndex++] = value._rotation;
@@ -713,7 +710,6 @@ define([
713710
};
714711

715712
var scratchRectangle = new Rectangle();
716-
var scratchRotatedRectangle = new Rectangle();
717713
var scratchEllipsoid = Ellipsoid.clone(Ellipsoid.UNIT_SPHERE);
718714
var scratchOptions = {
719715
rectangle : scratchRectangle,
@@ -751,9 +747,6 @@ define([
751747
var vertexFormat = VertexFormat.unpack(array, startingIndex, scratchVertexFormat);
752748
startingIndex += VertexFormat.packedLength;
753749

754-
var rotatedRectangle = Rectangle.unpack(array, startingIndex, scratchRotatedRectangle);
755-
startingIndex += Rectangle.packedLength;
756-
757750
var granularity = array[startingIndex++];
758751
var surfaceHeight = array[startingIndex++];
759752
var rotation = array[startingIndex++];
@@ -781,7 +774,6 @@ define([
781774
result._stRotation = stRotation;
782775
result._extrudedHeight = extrude ? extrudedHeight : undefined;
783776
result._extrude = extrude;
784-
result._rotatedRectangle = rotatedRectangle;
785777
result._shadowVolume = shadowVolume;
786778

787779
return result;
@@ -892,6 +884,9 @@ define([
892884
*/
893885
rectangle : {
894886
get : function() {
887+
if (!defined(this._rotatedRectangle)) {
888+
this._rotatedRectangle = computeRectangle(this._rectangle, this._ellipsoid, this._rotation);
889+
}
895890
return this._rotatedRectangle;
896891
}
897892
}

Specs/Core/CorridorGeometrySpec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,10 @@ defineSuite([
292292
width : 30000.0,
293293
granularity : 0.1
294294
});
295-
var rectangle = new Rectangle(1.568055205533759, -0.5410504013439219, 1.573537448056034, -0.5235971737132246);
295+
296296
var packedInstance = [2, positions[0].x, positions[0].y, positions[0].z, positions[1].x, positions[1].y, positions[1].z];
297297
packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z);
298298
packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0);
299-
packedInstance.push(rectangle.west, rectangle.south, rectangle.east, rectangle.north);
300299
packedInstance.push(30000.0, 0.0, 0.0, 2.0, 0.1, 0.0);
301300
createPackableSpecs(CorridorGeometry, corridor, packedInstance);
302301
});

Specs/Core/PolygonGeometrySpec.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ defineSuite([
687687
array.push(positions[i].x, positions[i].y, positions[i].z);
688688
}
689689
}
690-
var rectangle = new Rectangle(-0.21642082724729672, 0.06108652381980151, -0.20943951023931984, 0.06981317007977318);
690+
691691
var packedInstance = [3.0, 1.0];
692692
addPositions(packedInstance, positions);
693693
packedInstance.push(3.0, 1.0);
@@ -696,7 +696,6 @@ defineSuite([
696696
addPositions(packedInstance, holePositions1);
697697
packedInstance.push(Ellipsoid.WGS84.radii.x, Ellipsoid.WGS84.radii.y, Ellipsoid.WGS84.radii.z);
698698
packedInstance.push(1.0, 0.0, 0.0, 0.0, 0.0, 0.0);
699-
packedInstance.push(rectangle.west, rectangle.south, rectangle.east, rectangle.north);
700-
packedInstance.push(0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 1.0, 0, 1, 0, 56);
699+
packedInstance.push(0.0, 0.0, CesiumMath.PI_OVER_THREE, 0.0, 0.0, 1.0, 0, 1, 0, 52);
701700
createPackableSpecs(PolygonGeometry, polygon, packedInstance);
702701
});

Specs/Core/RectangleGeometrySpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,6 @@ defineSuite([
348348
granularity : 1.0,
349349
ellipsoid : Ellipsoid.UNIT_SPHERE
350350
});
351-
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];
351+
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];
352352
createPackableSpecs(RectangleGeometry, rectangle, packedInstance);
353353
});

0 commit comments

Comments
 (0)