Skip to content

Commit

Permalink
Merge pull request #2265 from AnalyticalGraphicsInc/polylineGaps
Browse files Browse the repository at this point in the history
Polyline Gaps
  • Loading branch information
shunter committed Dec 15, 2014
2 parents 23dd1a2 + 3a930b0 commit 3656898
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 76 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Change Log
* `ConstantProperty` now accepts `HTMLElement` instances as valid values.
* `BillboardGraphics.image` and `ImageMaterialProperty.image` now accept `Property` instances that represent an `Image` or `Canvas` in addition to a url.
* Added `Math.mod` which computes `m % n` but also works when `m` is negative.
* Fixed a bug in `PolylineGeometry` that would cause gaps in the line. [#2136](https://github.com/AnalyticalGraphicsInc/cesium/issues/2136)
* Fixed imagery providers whose rectangle crosses the IDL. Added `Rectangle.computeWidth`, `Rectangle.computeHeight`, `Rectangle.width`, and `Rectangle.height`. [#2195](https://github.com/AnalyticalGraphicsInc/cesium/issues/2195)

### 1.4 - 2014-12-01
Expand Down
21 changes: 8 additions & 13 deletions Source/Core/Cartesian2.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,26 +654,21 @@ define([

/**
* Compares the provided Cartesians componentwise and returns
* <code>true</code> if they are within the provided epsilon,
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {Cartesian2} [left] The first Cartesian.
* @param {Cartesian2} [right] The second Cartesian.
* @param {Number} epsilon The epsilon to use for equality testing.
* @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
* @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
*/
Cartesian2.equalsEpsilon = function(left, right, epsilon) {
//>>includeStart('debug', pragmas.debug);
if (typeof epsilon !== 'number') {
throw new DeveloperError('epsilon is required and must be a number.');
}
//>>includeEnd('debug');

Cartesian2.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
return (left === right) ||
((defined(left)) &&
(defined(right)) &&
(Math.abs(left.x - right.x) <= epsilon) &&
(Math.abs(left.y - right.y) <= epsilon));
(defined(left) &&
defined(right) &&
CesiumMath.equalsEpsilon(left.x, right.x, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(left.y, right.y, relativeEpsilon, absoluteEpsilon));
};

/**
Expand Down
23 changes: 9 additions & 14 deletions Source/Core/Cartesian3.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,27 +705,22 @@ define([

/**
* Compares the provided Cartesians componentwise and returns
* <code>true</code> if they are within the provided epsilon,
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {Cartesian3} [left] The first Cartesian.
* @param {Cartesian3} [right] The second Cartesian.
* @param {Number} epsilon The epsilon to use for equality testing.
* @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
* @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
*/
Cartesian3.equalsEpsilon = function(left, right, epsilon) {
//>>includeStart('debug', pragmas.debug);
if (typeof epsilon !== 'number') {
throw new DeveloperError('epsilon is required and must be a number.');
}
//>>includeEnd('debug');

Cartesian3.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
return (left === right) ||
((defined(left)) &&
(defined(right)) &&
(Math.abs(left.x - right.x) <= epsilon) &&
(Math.abs(left.y - right.y) <= epsilon) &&
(Math.abs(left.z - right.z) <= epsilon));
(defined(left) &&
defined(right) &&
CesiumMath.equalsEpsilon(left.x, right.x, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(left.y, right.y, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(left.z, right.z, relativeEpsilon, absoluteEpsilon));
};

/**
Expand Down
31 changes: 14 additions & 17 deletions Source/Core/Cartesian4.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ define([
'./defaultValue',
'./defined',
'./DeveloperError',
'./freezeObject'
'./freezeObject',
'./Math'
], function(
defaultValue,
defined,
DeveloperError,
freezeObject) {
freezeObject,
CesiumMath) {
"use strict";

/**
Expand Down Expand Up @@ -704,28 +706,23 @@ define([

/**
* Compares the provided Cartesians componentwise and returns
* <code>true</code> if they are within the provided epsilon,
* <code>true</code> if they pass an absolute or relative tolerance test,
* <code>false</code> otherwise.
*
* @param {Cartesian4} [left] The first Cartesian.
* @param {Cartesian4} [right] The second Cartesian.
* @param {Number} epsilon The epsilon to use for equality testing.
* @param {Number} relativeEpsilon The relative epsilon tolerance to use for equality testing.
* @param {Number} [absoluteEpsilon=relativeEpsilon] The absolute epsilon tolerance to use for equality testing.
* @returns {Boolean} <code>true</code> if left and right are within the provided epsilon, <code>false</code> otherwise.
*/
Cartesian4.equalsEpsilon = function(left, right, epsilon) {
//>>includeStart('debug', pragmas.debug);
if (typeof epsilon !== 'number') {
throw new DeveloperError('epsilon is required and must be a number.');
}
//>>includeEnd('debug');

Cartesian4.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
return (left === right) ||
((defined(left)) &&
(defined(right)) &&
(Math.abs(left.x - right.x) <= epsilon) &&
(Math.abs(left.y - right.y) <= epsilon) &&
(Math.abs(left.z - right.z) <= epsilon) &&
(Math.abs(left.w - right.w) <= epsilon));
(defined(left) &&
defined(right) &&
CesiumMath.equalsEpsilon(left.x, right.x, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(left.y, right.y, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(left.z, right.z, relativeEpsilon, absoluteEpsilon) &&
CesiumMath.equalsEpsilon(left.w, right.w, relativeEpsilon, absoluteEpsilon));
};

/**
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/EllipseGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ define([
var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
var height = defaultValue(options.height, 0.0);
var extrudedHeight = options.extrudedHeight;
var extrude = (defined(extrudedHeight) && !CesiumMath.equalsEpsilon(height, extrudedHeight, 1.0));
var extrude = (defined(extrudedHeight) && Math.abs(height - extrudedHeight) > 1.0);

//>>includeStart('debug', pragmas.debug);
if (!defined(center)) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/EllipseOutlineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ define([
var granularity = defaultValue(options.granularity, CesiumMath.RADIANS_PER_DEGREE);
var height = defaultValue(options.height, 0.0);
var extrudedHeight = options.extrudedHeight;
var extrude = (defined(extrudedHeight) && !CesiumMath.equalsEpsilon(height, extrudedHeight, 1.0));
var extrude = (defined(extrudedHeight) && Math.abs(height - extrudedHeight) > 1.0);

//>>includeStart('debug', pragmas.debug);
if (!defined(center)) {
Expand Down
24 changes: 16 additions & 8 deletions Source/Core/Math.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,30 +520,38 @@ define([
};

/**
* Determines if two values are equal within the provided epsilon. This is useful
* to avoid problems due to roundoff error when comparing floating-point values directly.
* Determines if two values are equal using an absolute or relative tolerance test. This is useful
* to avoid problems due to roundoff error when comparing floating-point values directly. The values are
* first compared using an absolute tolerance test. If that fails, a relative tolerance test is performed.
* Use this test if you are unsure of the magnitudes of left and right.
*
* @param {Number} left The first value to compare.
* @param {Number} right The other value to compare.
* @param {Number} [epsilon=0.0] The maximum inclusive delta between <code>left</code> and <code>right</code> where they will be considered equal.
* @param {Number} relativeEpsilon The maximum inclusive delta between <code>left</code> and <code>right</code> for the relative tolerance test.
* @param {Number} [absoluteEpsilon=relativeEpsilon] The maximum inclusive delta between <code>left</code> and <code>right</code> for the absolute tolerance test.
* @returns {Boolean} <code>true</code> if the values are equal within the epsilon; otherwise, <code>false</code>.
*
* @example
* var b = Cesium.Math.equalsEpsilon(0.0, 0.01, Cesium.Math.EPSILON2); // true
* var a = Cesium.Math.equalsEpsilon(0.0, 0.01, Cesium.Math.EPSILON2); // true
* var b = Cesium.Math.equalsEpsilon(0.0, 0.1, Cesium.Math.EPSILON2); // false
* var c = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON7); // true
* var d = Cesium.Math.equalsEpsilon(3699175.1634344, 3699175.2, Cesium.Math.EPSILON9); // false
*/
CesiumMath.equalsEpsilon = function(left, right, epsilon) {
CesiumMath.equalsEpsilon = function(left, right, relativeEpsilon, absoluteEpsilon) {
//>>includeStart('debug', pragmas.debug);
if (!defined(left)) {
throw new DeveloperError('left is required.');
}

if (!defined(right)) {
throw new DeveloperError('right is required.');
}
if (!defined(relativeEpsilon)) {
throw new DeveloperError('relativeEpsilon is required.');
}
//>>includeEnd('debug');
epsilon = defaultValue(epsilon, 0.0);
return Math.abs(left - right) <= epsilon;
absoluteEpsilon = defaultValue(absoluteEpsilon, relativeEpsilon);
var absDiff = Math.abs(left - right);
return absDiff <= absoluteEpsilon || absDiff <= relativeEpsilon * Math.max(Math.abs(left), Math.abs(right));
};

var factorials = [1];
Expand Down
8 changes: 5 additions & 3 deletions Source/Core/PolylineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ define([
var p1;
var c0;
var c1;
var positions = polylineGeometry._positions;

var positions = PolylinePipeline.removeDuplicates(polylineGeometry._positions);
if (!defined(positions)) {
positions = polylineGeometry._positions;
}

if (followSurface) {
var heights = PolylinePipeline.extractHeights(positions, ellipsoid);
Expand Down Expand Up @@ -197,8 +201,6 @@ define([
ellipsoid: ellipsoid,
height: heights
});
} else {
positions = polylineGeometry._positions;
}

var size = positions.length * 4.0 - 4.0;
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/PolylinePipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ define([
};
};

var removeDuplicatesEpsilon = CesiumMath.EPSILON7;

/**
* Removes adjacent duplicate positions in an array of positions.
*
Expand Down Expand Up @@ -228,7 +230,7 @@ define([
for (i = 1; i < length; ++i) {
v0 = positions[i - 1];
v1 = positions[i];
if (Cartesian3.equals(v0, v1)) {
if (Cartesian3.equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
break;
}
}
Expand All @@ -237,13 +239,11 @@ define([
return undefined;
}

var cleanedPositions = [];
cleanedPositions.push(positions[0]);

var cleanedPositions = positions.slice(0, i);
for (; i < length; ++i) {
v0 = positions[i - 1];
v1 = positions[i];
if (!Cartesian3.equals(v0, v1)) {
if (!Cartesian3.equalsEpsilon(v0, v1, removeDuplicatesEpsilon)) {
cleanedPositions.push(Cartesian3.clone(v1));
}
}
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/RectangleGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ define([
var p = Cartesian3.fromArray(positions, i, positionScratch);

if (vertexFormat.normal || vertexFormat.tangent || vertexFormat.binormal) {
var p1 = Cartesian3.fromArray(positions, i + 6, v1Scratch);
var p1 = Cartesian3.fromArray(positions, (i + 6) % length, v1Scratch);
if (recomputeNormal) {
var p2 = Cartesian3.fromArray(positions, i + 3, v2Scratch);
var p2 = Cartesian3.fromArray(positions, (i + 3) % length, v2Scratch);
Cartesian3.subtract(p1, p, p1);
Cartesian3.subtract(p2, p, p2);
normal = Cartesian3.normalize(Cartesian3.cross(p2, p1, normal), normal);
Expand Down Expand Up @@ -468,14 +468,14 @@ define([
var index = 0;
for (i = 0; i < length - 1; i+=2) {
upperLeft = i;
upperRight = upperLeft + 2;
upperRight = (upperLeft + 2) % length;
var p1 = Cartesian3.fromArray(wallPositions, upperLeft * 3, v1Scratch);
var p2 = Cartesian3.fromArray(wallPositions, upperRight * 3, v2Scratch);
if (Cartesian3.equalsEpsilon(p1, p2, CesiumMath.EPSILON10)) {
continue;
}
lowerLeft = upperLeft + 1;
lowerRight = lowerLeft + 2;
lowerLeft = (upperLeft + 1) % length;
lowerRight = (lowerLeft + 2) % length;
wallIndices[index++] = upperLeft;
wallIndices[index++] = lowerLeft;
wallIndices[index++] = upperRight;
Expand Down
12 changes: 10 additions & 2 deletions Specs/Core/Cartesian2Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,16 @@ defineSuite([
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(1.0, 2.0), 1.0)).toEqual(true);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(2.0, 2.0), 1.0)).toEqual(true);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(1.0, 3.0), 1.0)).toEqual(true);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(2.0, 2.0), 0.99999)).toEqual(false);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(1.0, 3.0), 0.99999)).toEqual(false);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(1.0, 3.0), CesiumMath.EPSILON6)).toEqual(false);
expect(Cartesian2.equalsEpsilon(cartesian, undefined, 1)).toEqual(false);

cartesian = new Cartesian2(3000000.0, 4000000.0);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(3000000.0, 4000000.0), 0.0)).toEqual(true);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(3000000.0, 4000000.2), CesiumMath.EPSILON7)).toEqual(true);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(3000000.2, 4000000.0), CesiumMath.EPSILON7)).toEqual(true);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(3000000.2, 4000000.2), CesiumMath.EPSILON7)).toEqual(true);
expect(Cartesian2.equalsEpsilon(cartesian, new Cartesian2(3000000.2, 4000000.2), CesiumMath.EPSILON9)).toEqual(false);
expect(Cartesian2.equalsEpsilon(undefined, cartesian, 1)).toEqual(false);
expect(Cartesian2.equalsEpsilon(cartesian, undefined, 1)).toEqual(false);
});

Expand Down
16 changes: 13 additions & 3 deletions Specs/Core/Cartesian3Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,19 @@ defineSuite([
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(2.0, 2.0, 3.0), 1.0)).toEqual(true);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(1.0, 3.0, 3.0), 1.0)).toEqual(true);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(1.0, 2.0, 4.0), 1.0)).toEqual(true);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(2.0, 2.0, 3.0), 0.99999)).toEqual(false);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(1.0, 3.0, 3.0), 0.99999)).toEqual(false);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(1.0, 2.0, 4.0), 0.99999)).toEqual(false);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(2.0, 2.0, 3.0), CesiumMath.EPSILON6)).toEqual(false);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(1.0, 3.0, 3.0), CesiumMath.EPSILON6)).toEqual(false);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(1.0, 2.0, 4.0), CesiumMath.EPSILON6)).toEqual(false);
expect(Cartesian3.equalsEpsilon(cartesian, undefined, 1)).toEqual(false);

cartesian = new Cartesian3(3000000.0, 4000000.0, 5000000.0);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(3000000.0, 4000000.0, 5000000.0), 0.0)).toEqual(true);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(3000000.2, 4000000.0, 5000000.0), CesiumMath.EPSILON7)).toEqual(true);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(3000000.0, 4000000.2, 5000000.0), CesiumMath.EPSILON7)).toEqual(true);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(3000000.0, 4000000.0, 5000000.2), CesiumMath.EPSILON7)).toEqual(true);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(3000000.2, 4000000.2, 5000000.2), CesiumMath.EPSILON7)).toEqual(true);
expect(Cartesian3.equalsEpsilon(cartesian, new Cartesian3(3000000.2, 4000000.2, 5000000.2), CesiumMath.EPSILON9)).toEqual(false);
expect(Cartesian3.equalsEpsilon(undefined, cartesian, 1)).toEqual(false);
expect(Cartesian3.equalsEpsilon(cartesian, undefined, 1)).toEqual(false);
});

Expand Down
Loading

0 comments on commit 3656898

Please sign in to comment.