Skip to content

Commit

Permalink
Remove computeCircleBoundary and computeEllipseBoundary
Browse files Browse the repository at this point in the history
  • Loading branch information
pjcozzi committed May 14, 2014
1 parent bf7b2ea commit d09e446
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 432 deletions.
85 changes: 0 additions & 85 deletions Apps/Sandcastle/gallery/Circles and Ellipses.html

This file was deleted.

2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Polyline Volume.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 : {
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
219 changes: 3 additions & 216 deletions Source/Core/Shapes.js
Original file line number Diff line number Diff line change
@@ -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 <a href="http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Circles%20and%20Ellipses.html">Cesium Sandcastle Circles and Ellipses Demo</a>
*/
var Shapes = {
/**
* Computes boundary points for a circle on the ellipsoid.
* <br /><br />
* The <code>granularity</code> determines the number of points
* in the boundary. A lower granularity results in more points and a more
* exact circle.
* <br /><br />
* 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.
* <br /><br />
* The <code>granularity</code> determines the number of points
* in the boundary. A lower granularity results in more points and a more
* exact circle.
* <br /><br />
* 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.
*
Expand Down
11 changes: 6 additions & 5 deletions Specs/Core/PolygonGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));

Expand Down
11 changes: 6 additions & 5 deletions Specs/Core/PolygonOutlineGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}));

Expand Down
12 changes: 0 additions & 12 deletions Specs/Core/PolygonPipelineSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Loading

0 comments on commit d09e446

Please sign in to comment.