From d09e4464d90a8ecd9aec5638b1664a0ab626ea9a Mon Sep 17 00:00:00 2001 From: Patrick Cozzi Date: Tue, 13 May 2014 20:35:17 -0400 Subject: [PATCH] Remove computeCircleBoundary and computeEllipseBoundary --- .../gallery/Circles and Ellipses.html | 85 ------- Apps/Sandcastle/gallery/Polyline Volume.html | 2 +- CHANGES.md | 1 + Source/Core/Shapes.js | 219 +----------------- Specs/Core/PolygonGeometrySpec.js | 11 +- Specs/Core/PolygonOutlineGeometrySpec.js | 11 +- Specs/Core/PolygonPipelineSpec.js | 12 - Specs/Core/ShapesSpec.js | 108 --------- 8 files changed, 17 insertions(+), 432 deletions(-) delete mode 100644 Apps/Sandcastle/gallery/Circles and Ellipses.html diff --git a/Apps/Sandcastle/gallery/Circles and Ellipses.html b/Apps/Sandcastle/gallery/Circles and Ellipses.html deleted file mode 100644 index 8b71c86b0896..000000000000 --- a/Apps/Sandcastle/gallery/Circles and Ellipses.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - - Cesium Demo - - - - - - -
-

Loading...

-
- - - diff --git a/Apps/Sandcastle/gallery/Polyline Volume.html b/Apps/Sandcastle/gallery/Polyline Volume.html index 191497694fca..6a2e3c082dbe 100644 --- a/Apps/Sandcastle/gallery/Polyline Volume.html +++ b/Apps/Sandcastle/gallery/Polyline Volume.html @@ -60,7 +60,7 @@ -89.0, 36.0 ]), vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT, - shapePositions : Cesium.Shapes.compute2DCircle(60000), + shapePositions : Cesium.Shapes.compute2DCircle(60000.0), cornerType : Cesium.CornerType.ROUNDED }), attributes : { diff --git a/CHANGES.md b/CHANGES.md index 0e62379112b0..0dd46e87bfdf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,7 @@ Beta Releases * Breaking changes ([why so many?](https://groups.google.com/forum/#!topic/cesium-dev/CQ0wCHjJ9x4)) * Removed `CesiumWidget.onRenderLoopError` and `Viewer.renderLoopError`. They have been replaced by `Scene.renderError`. + * Removed `Shapes.computeCircleBoundary` and `Shapes.computeEllipseBoundary`. Instead, use `CircleOutlineGeometry` and `EllipseOutlineGeometry`. See the [tutorial](http://cesiumjs.org/2013/11/04/Geometry-and-Appearances/). * Improved terrain and imagery rendering performance when very close to the surface. * Added `preRender` and `postRender` events to `Scene`. * Fixed dark lighting in 3D and Columbus View when viewing a primitive edge on. ([#592](https://github.com/AnalyticalGraphicsInc/cesium/issues/592)) diff --git a/Source/Core/Shapes.js b/Source/Core/Shapes.js index 7491b63abd07..89690aacc36e 100644 --- a/Source/Core/Shapes.js +++ b/Source/Core/Shapes.js @@ -1,233 +1,20 @@ /*global define*/ define([ './defaultValue', - './defined', - './DeveloperError', './Math', - './Cartesian2', - './Cartesian3', - './Quaternion', - './Matrix3' + './Cartesian2' ], function( defaultValue, - defined, - DeveloperError, CesiumMath, - Cartesian2, - Cartesian3, - Quaternion, - Matrix3) { + Cartesian2) { "use strict"; - function _computeEllipseQuadrant(cb, cbRadius, aSqr, bSqr, ab, ecc, unitPos, eastVec, northVec, rotation, - thetaPts, thetaPtsIndex, offset, clockDir, ellipsePts, ellipsePtsIndex, numPts) { - var angle; - var theta; - var radius; - var azimuth; - var temp; - var temp2; - var rotAxis; - var tempVec; - - for (var i = 0; i < numPts; i++, thetaPtsIndex += clockDir, ++ellipsePtsIndex) { - theta = (clockDir > 0) ? (thetaPts[thetaPtsIndex] + offset) : (offset - thetaPts[thetaPtsIndex]); - - azimuth = theta + rotation; - - temp = -Math.cos(azimuth); - - rotAxis = Cartesian3.multiplyByScalar(eastVec, temp); - - temp = Math.sin(azimuth); - tempVec = Cartesian3.multiplyByScalar(northVec, temp); - - rotAxis = Cartesian3.add(rotAxis, tempVec, rotAxis); - - temp = Math.cos(theta); - temp = temp * temp; - - temp2 = Math.sin(theta); - temp2 = temp2 * temp2; - - radius = ab / Math.sqrt(bSqr * temp + aSqr * temp2); - angle = radius / cbRadius; - - // Create the quaternion to rotate the position vector to the boundary of the ellipse. - temp = Math.sin(angle / 2.0); - - var unitQuat = Quaternion.normalize(new Quaternion(rotAxis.x * temp, rotAxis.y * temp, rotAxis.z * temp, Math.cos(angle / 2.0))); - var rotMtx = Matrix3.fromQuaternion(unitQuat); - - var tmpEllipsePts = Matrix3.multiplyByVector(rotMtx, unitPos); - var unitCart = Cartesian3.normalize(tmpEllipsePts); - tmpEllipsePts = Cartesian3.multiplyByScalar(unitCart, cbRadius); - ellipsePts[ellipsePtsIndex] = tmpEllipsePts; - } - } - /** - * Functions to compute the boundary positions for shapes, such as circles, - * drawn on the ellipsoid. + * Functions to compute the boundary positions for shapes. * * @exports Shapes - * - * @demo Cesium Sandcastle Circles and Ellipses Demo */ var Shapes = { - /** - * Computes boundary points for a circle on the ellipsoid. - *

- * The granularity determines the number of points - * in the boundary. A lower granularity results in more points and a more - * exact circle. - *

- * An outlined circle is rendered by passing the result of this function call to - * {@link Polyline#positions}. A filled circle is rendered by passing - * the result to {@link Polygon#positions}. - * - * @param {Ellipsoid} ellipsoid The ellipsoid the circle will be on. - * @param {Cartesian3} center The circle's center point in the fixed frame. - * @param {Number} radius The radius in meters. - * @param {Number} [granularity] The angular distance between points on the circle. - * - * @exception {DeveloperError} radius must be greater than zero. - * @exception {DeveloperError} granularity must be greater than zero. - * - * @see Polyline#positions - * @see Polygon#positions - * - * @example - * // Create a polyline of a circle - * var polyline = new Cesium.Polyline(); - * polyline.positions = Cesium.Shapes.computeCircleBoundary( - * ellipsoid, Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883), 100000.0); - */ - computeCircleBoundary : function(ellipsoid, center, radius, granularity) { - granularity = defaultValue(granularity, CesiumMath.RADIANS_PER_DEGREE); - - //>>includeStart('debug', pragmas.debug); - if (!defined(ellipsoid) || !defined(center) || !defined(radius)) { - throw new DeveloperError('ellipsoid, center, and radius are required.'); - } - if (radius <= 0.0) { - throw new DeveloperError('radius must be greater than zero.'); - } - if (granularity <= 0.0) { - throw new DeveloperError('granularity must be greater than zero.'); - } - //>>includeEnd('debug'); - - return this.computeEllipseBoundary(ellipsoid, center, radius, radius, 0, granularity); - }, - - /** - * Computes boundary points for an ellipse on the ellipsoid. - *

- * The granularity determines the number of points - * in the boundary. A lower granularity results in more points and a more - * exact circle. - *

- * An outlined ellipse is rendered by passing the result of this function call to - * {@link Polyline#positions}. A filled ellipse is rendered by passing - * the result to {@link Polygon#positions}. - * - * @param {Ellipsoid} ellipsoid The ellipsoid the ellipse will be on. - * @param {Cartesian3} center The ellipse's center point in the fixed frame. - * @param {Number} semiMajorAxis The length of the ellipse's semi-major axis in meters. - * @param {Number} semiMinorAxis The length of the ellipse's semi-minor axis in meters. - * @param {Number} [rotation] The angle from north (clockwise) in radians. The default is zero. - * @param {Number} [granularity] The angular distance between points on the circle. - * - * @exception {DeveloperError} Semi-major and semi-minor axes must be greater than zero. - * @exception {DeveloperError} granularity must be greater than zero. - * - * @see Polyline#positions - * @see Polygon#positions - * - * @returns The set of points that form the ellipse's boundary. - * - * @example - * // Create a filled ellipse. - * var polygon = new Cesium.Polygon(); - * polygon.positions = Cesium.Shapes.computeEllipseBoundary( - * ellipsoid, Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883), 500000.0, 300000.0, Cesium.Math.toRadians(60)); - */ - computeEllipseBoundary : function(ellipsoid, center, semiMajorAxis, semiMinorAxis, rotation, granularity) { - rotation = defaultValue(rotation, 0.0); - granularity = defaultValue(granularity, CesiumMath.RADIANS_PER_DEGREE); - - //>>includeStart('debug', pragmas.debug); - if (!defined(ellipsoid) || !defined(center) || !defined(semiMajorAxis) || !defined(semiMinorAxis)) { - throw new DeveloperError('ellipsoid, center, semiMajorAxis, and semiMinorAxis are required.'); - } - if (semiMajorAxis <= 0.0 || semiMinorAxis <= 0.0) { - throw new DeveloperError('Semi-major and semi-minor axes must be greater than zero.'); - } - if (granularity <= 0.0) { - throw new DeveloperError('granularity must be greater than zero.'); - } - //>>includeEnd('debug'); - - if (semiMajorAxis < semiMinorAxis) { - var t = semiMajorAxis; - semiMajorAxis = semiMinorAxis; - semiMinorAxis = t; - } - - var MAX_ANOMALY_LIMIT = 2.31; - - var aSqr = semiMajorAxis * semiMajorAxis; - var bSqr = semiMinorAxis * semiMinorAxis; - var ab = semiMajorAxis * semiMinorAxis; - - var value = 1.0 - (bSqr / aSqr); - var ecc = Math.sqrt(value); - - var surfPos = Cartesian3.clone(center); - var surfPosMag = Cartesian3.magnitude(surfPos); - - var tempVec = new Cartesian3(0.0, 0.0, 1); - var temp = 1.0 / surfPosMag; - - var unitPos = Cartesian3.multiplyByScalar(surfPos, temp); - var eastVec = Cartesian3.normalize(Cartesian3.cross(tempVec, surfPos)); - var northVec = Cartesian3.cross(unitPos, eastVec); - - var numQuadrantPts = 1 + Math.ceil(CesiumMath.PI_OVER_TWO / granularity); - var deltaTheta = MAX_ANOMALY_LIMIT / (numQuadrantPts - 1); - var thetaPts = []; - var thetaPtsIndex = 0; - - var sampleTheta = 0.0; - for (var i = 0; i < numQuadrantPts; i++, sampleTheta += deltaTheta, ++thetaPtsIndex) { - thetaPts[thetaPtsIndex] = sampleTheta - ecc * Math.sin(sampleTheta); - if (thetaPts[thetaPtsIndex] >= CesiumMath.PI_OVER_TWO) { - thetaPts[thetaPtsIndex] = CesiumMath.PI_OVER_TWO; - numQuadrantPts = i + 1; - break; - } - } - - var ellipsePts = []; - - _computeEllipseQuadrant(ellipsoid, surfPosMag, aSqr, bSqr, ab, ecc, unitPos, eastVec, northVec, rotation, - thetaPts, 0.0, 0.0, 1, ellipsePts, 0, numQuadrantPts - 1); - - _computeEllipseQuadrant(ellipsoid, surfPosMag, aSqr, bSqr, ab, ecc, unitPos, eastVec, northVec, rotation, - thetaPts, numQuadrantPts - 1, Math.PI, -1, ellipsePts, numQuadrantPts - 1, numQuadrantPts - 1); - - _computeEllipseQuadrant(ellipsoid, surfPosMag, aSqr, bSqr, ab, ecc, unitPos, eastVec, northVec, rotation, - thetaPts, 0.0, Math.PI, 1, ellipsePts, (2 * numQuadrantPts) - 2, numQuadrantPts - 1); - - _computeEllipseQuadrant(ellipsoid, surfPosMag, aSqr, bSqr, ab, ecc, unitPos, eastVec, northVec, rotation, - thetaPts, numQuadrantPts - 1, CesiumMath.TWO_PI, -1, ellipsePts, (3 * numQuadrantPts) - 3, numQuadrantPts); - - ellipsePts.push(Cartesian3.clone(ellipsePts[0])); // Duplicates first and last point for polyline - - return ellipsePts; - }, - /** * Computes a 2D circle about the origin. * diff --git a/Specs/Core/PolygonGeometrySpec.js b/Specs/Core/PolygonGeometrySpec.js index 35eab45c1922..a2b8019ed4aa 100644 --- a/Specs/Core/PolygonGeometrySpec.js +++ b/Specs/Core/PolygonGeometrySpec.js @@ -272,13 +272,14 @@ defineSuite([ }); it('computes correct bounding sphere at height 0', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = new Cartographic(0.2930215893394521, 0.818292397338644, 1880.6159971414636); - var positions = Shapes.computeCircleBoundary(ellipsoid, ellipsoid.cartographicToCartesian(center), 10000); - var p = PolygonGeometry.createGeometry(PolygonGeometry.fromPositions({ vertexFormat : VertexFormat.ALL, - positions : positions, + positions : Cartesian3.fromDegreesArray([ + -108.0, 1.0, + -108.0, -1.0, + -106.0, -1.0, + -106.0, 1.0 + ]), granularity : CesiumMath.PI_OVER_THREE })); diff --git a/Specs/Core/PolygonOutlineGeometrySpec.js b/Specs/Core/PolygonOutlineGeometrySpec.js index b8a6cd706ff6..88ea24f90cdb 100644 --- a/Specs/Core/PolygonOutlineGeometrySpec.js +++ b/Specs/Core/PolygonOutlineGeometrySpec.js @@ -209,12 +209,13 @@ defineSuite([ }); it('computes correct bounding sphere at height 0', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = new Cartographic(0.2930215893394521, 0.818292397338644, 1880.6159971414636); - var positions = Shapes.computeCircleBoundary(ellipsoid, ellipsoid.cartographicToCartesian(center), 10000); - var p = PolygonOutlineGeometry.createGeometry(PolygonOutlineGeometry.fromPositions({ - positions : positions, + positions : Cartesian3.fromDegreesArray([ + -108.0, 1.0, + -108.0, -1.0, + -106.0, -1.0, + -106.0, 1.0 + ]), granularity : CesiumMath.PI_OVER_THREE })); diff --git a/Specs/Core/PolygonPipelineSpec.js b/Specs/Core/PolygonPipelineSpec.js index 2e3d9d72195d..0c2627296852 100644 --- a/Specs/Core/PolygonPipelineSpec.js +++ b/Specs/Core/PolygonPipelineSpec.js @@ -556,16 +556,4 @@ defineSuite([ expect(positions.length).toEqual(28); }); - it('elimitate holes does not add undefined to returned positions', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = new Cartographic(0.2930215893394521, 0.818292397338644, 1880.6159971414636); - var radius = 10000; - var outer = Shapes.computeCircleBoundary(ellipsoid, ellipsoid.cartographicToCartesian(center), radius); - var inner = Shapes.computeCircleBoundary(ellipsoid, ellipsoid.cartographicToCartesian(center), radius * 0.8); - - var positions = PolygonPipeline.eliminateHoles(outer, [inner], ellipsoid); - expect(function() { - PolygonPipeline.removeDuplicates(positions); - }).not.toThrow(); - }); }); \ No newline at end of file diff --git a/Specs/Core/ShapesSpec.js b/Specs/Core/ShapesSpec.js index d3e60ed6e4b1..11c67b5a3e00 100644 --- a/Specs/Core/ShapesSpec.js +++ b/Specs/Core/ShapesSpec.js @@ -12,114 +12,6 @@ defineSuite([ "use strict"; /*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/ - it('computeCircleBoundary computes a closed loop', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - var positions = Shapes.computeCircleBoundary(ellipsoid, center, 1.0); - - expect(positions[0]).toEqual(positions[positions.length - 1]); - }); - - it('computeCircleBoundary uses custom granularity', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - var positions = Shapes.computeCircleBoundary(ellipsoid, center, 1.0, CesiumMath.toRadians(60)); - - expect(positions.length).toEqual(10); - }); - - it('computeCircleBoundary throws without an ellipsoid', function() { - expect(function() { - Shapes.computeCircleBoundary(); - }).toThrowDeveloperError(); - }); - - it('computeCircleBoundary throws without a center', function() { - var ellipsoid = Ellipsoid.WGS84; - expect(function() { - Shapes.computeCircleBoundary(ellipsoid); - }).toThrowDeveloperError(); - }); - - it('computeCircleBoundary throws without a radius', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - expect(function() { - Shapes.computeCircleBoundary(ellipsoid, center); - }).toThrowDeveloperError(); - }); - - it('computeCircleBoundary throws with a negative radius', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - expect(function() { - Shapes.computeCircleBoundary(ellipsoid, center, -1.0); - }).toThrowDeveloperError(); - }); - - it('computeCircleBoundary throws with a negative granularity', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - expect(function() { - Shapes.computeCircleBoundary(ellipsoid, center, 1.0, -1.0); - }).toThrowDeveloperError(); - }); - - it('computeEllipseBoundary computes a closed loop', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - var positions = Shapes.computeEllipseBoundary(ellipsoid, center, 5.0, 1.0); - - expect(positions[0]).toEqual(positions[positions.length - 1]); - }); - - it('computeEllipseBoundary can swap the semi major and minor axes', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - var points = Shapes.computeEllipseBoundary(ellipsoid, center, 1.0, 5.0); - expect(points.length).toBeGreaterThan(0); - }); - - it('computeEllipseBoundary throws without an ellipsoid', function() { - expect(function() { - Shapes.computeEllipseBoundary(); - }).toThrowDeveloperError(); - }); - - it('computeEllipseBoundary throws without a center', function() { - var ellipsoid = Ellipsoid.WGS84; - expect(function() { - Shapes.computeEllipseBoundary(ellipsoid); - }).toThrowDeveloperError(); - }); - - it('computeEllipseBoundary throws without a semi-major axis', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - expect(function() { - Shapes.computeEllipseBoundary(ellipsoid, center, 1.0); - }).toThrowDeveloperError(); - }); - - it('computeEllipseBoundary with a negative axis length', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - expect(function() { - Shapes.computeEllipseBoundary(ellipsoid, center, -1.0, 1.0); - }).toThrowDeveloperError(); - expect(function() { - Shapes.computeEllipseBoundary(ellipsoid, center, 1.0, -1.0); - }).toThrowDeveloperError(); - }); - - it('computeEllipseBoundary throws with a negative granularity', function() { - var ellipsoid = Ellipsoid.WGS84; - var center = ellipsoid.cartographicToCartesian(Cartographic.ZERO); - expect(function() { - Shapes.computeEllipseBoundary(ellipsoid, center, 1.0, 1.0, 0, -1.0); - }).toThrowDeveloperError(); - }); - it('compute2DCircle returns a unit circle by default', function() { var points = Shapes.compute2DCircle(); expect(points.length).toBeGreaterThan(0);