Skip to content

Commit

Permalink
Merge pull request #3305 from AnalyticalGraphicsInc/polylineEpsilon
Browse files Browse the repository at this point in the history
Don't throw out short polylines
  • Loading branch information
bagnell committed Dec 10, 2015
2 parents a17b43b + 8762420 commit c796c61
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Change Log
* Removed `TerrainMesh` from the public API. It is now private and subject to change without notice.
* Removed `jsonp`. Use `loadJsonp` instead.
* Reduced the amount of both GPU and CPU memory used by terrain. The CPU memory was reduced by up to 40%.
* `CorridorGeometry` and `PolylineVolumeGeometry` render short segments [#3293](https://github.com/AnalyticalGraphicsInc/cesium/issues/3293)

### 1.16 - 2015-12-01

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/PolylinePipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ define([
};
};

var removeDuplicatesEpsilon = CesiumMath.EPSILON7;
var removeDuplicatesEpsilon = CesiumMath.EPSILON10;

/**
* Removes adjacent duplicate positions in an array of positions.
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/PolylineVolumeGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define([
'./IndexDatatype',
'./Math',
'./PolygonPipeline',
'./PolylinePipeline',
'./PolylineVolumeGeometryLibrary',
'./PrimitiveType',
'./VertexFormat',
Expand All @@ -39,6 +40,7 @@ define([
IndexDatatype,
CesiumMath,
PolygonPipeline,
PolylinePipeline,
PolylineVolumeGeometryLibrary,
PrimitiveType,
VertexFormat,
Expand Down Expand Up @@ -374,7 +376,7 @@ define([
*/
PolylineVolumeGeometry.createGeometry = function(polylineVolumeGeometry) {
var positions = polylineVolumeGeometry._positions;
var cleanPositions = PolylineVolumeGeometryLibrary.removeDuplicatesFromPositions(positions, polylineVolumeGeometry._ellipsoid);
var cleanPositions = PolylinePipeline.removeDuplicates(positions);
var shape2D = polylineVolumeGeometry._shape;
shape2D = PolylineVolumeGeometryLibrary.removeDuplicatesFromShape(shape2D);

Expand Down
28 changes: 0 additions & 28 deletions Source/Core/PolylineVolumeGeometryLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,34 +262,6 @@ define([
return ((prev.x * next.y) - (prev.y * next.x)) >= 0.0;
};

function latLonEquals(c0, c1) {
return ((CesiumMath.equalsEpsilon(c0.latitude, c1.latitude, CesiumMath.EPSILON6)) && (CesiumMath.equalsEpsilon(c0.longitude, c1.longitude, CesiumMath.EPSILON6)));
}
var carto0 = new Cartographic();
var carto1 = new Cartographic();
PolylineVolumeGeometryLibrary.removeDuplicatesFromPositions = function(positions, ellipsoid) {
var length = positions.length;
if (length < 2) {
return positions.slice(0);
}

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

for (var i = 1; i < length; ++i) {
var v0 = positions[i - 1];
var v1 = positions[i];
var c0 = ellipsoid.cartesianToCartographic(v0, carto0);
var c1 = ellipsoid.cartesianToCartographic(v1, carto1);

if (!latLonEquals(c0, c1)) {
cleanedPositions.push(v1); // Shallow copy!
}
}

return cleanedPositions;
};

var scratchForwardProjection = new Cartesian3();
var scratchBackwardProjection = new Cartesian3();

Expand Down
4 changes: 3 additions & 1 deletion Source/Core/PolylineVolumeOutlineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ define([
'./IndexDatatype',
'./Math',
'./PolygonPipeline',
'./PolylinePipeline',
'./PolylineVolumeGeometryLibrary',
'./PrimitiveType',
'./WindingOrder'
Expand All @@ -36,6 +37,7 @@ define([
IndexDatatype,
CesiumMath,
PolygonPipeline,
PolylinePipeline,
PolylineVolumeGeometryLibrary,
PrimitiveType,
WindingOrder) {
Expand Down Expand Up @@ -280,7 +282,7 @@ define([
*/
PolylineVolumeOutlineGeometry.createGeometry = function(polylineVolumeOutlineGeometry) {
var positions = polylineVolumeOutlineGeometry._positions;
var cleanPositions = PolylineVolumeGeometryLibrary.removeDuplicatesFromPositions(positions, polylineVolumeOutlineGeometry._ellipsoid);
var cleanPositions = PolylinePipeline.removeDuplicates(positions);
var shape2D = polylineVolumeOutlineGeometry._shape;
shape2D = PolylineVolumeGeometryLibrary.removeDuplicatesFromShape(shape2D);

Expand Down
36 changes: 0 additions & 36 deletions Specs/Core/PolylineGeometrySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,42 +111,6 @@ defineSuite([
expect(line.attributes.color.values.length).toEqual(numVertices * 4);
});

it('removes duplicates within absolute epsilon 7', function() {
var positions = [
new Cartesian3(1.0, 0.0, 0.0),
new Cartesian3(1.0, 0.0, 0.0),
new Cartesian3(1.0 + CesiumMath.EPSILON7, 0.0, 0.0),
new Cartesian3(0.0, 1.0, 0.0),
new Cartesian3(0.0, 0.0, 1.0)];
var line = PolylineGeometry.createGeometry(new PolylineGeometry({
positions : positions,
width : 10.0,
vertexFormat : VertexFormat.POSITION_ONLY,
followSurface : false
}));

var numVertices = ((positions.length - 2) * 4 - 4);
expect(line.attributes.position.values.length).toEqual(numVertices * 3);
});

it('removes duplicates within relative epsilon 7', function() {
var positions = [
new Cartesian3(3000000.0, 0.0, 0.0),
new Cartesian3(3000000.0, 0.0, 0.0),
new Cartesian3(3000000.2, 0.0, 0.0),
new Cartesian3(0.0, 3000000.0, 0.0),
new Cartesian3(0.0, 0.0, 3000000.0)];
var line = PolylineGeometry.createGeometry(new PolylineGeometry({
positions : positions,
width : 10.0,
vertexFormat : VertexFormat.POSITION_ONLY,
followSurface : false
}));

var numVertices = ((positions.length - 2) * 4 - 4);
expect(line.attributes.position.values.length).toEqual(numVertices * 3);
});

it('createGeometry returns undefined without at least 2 unique positions', function() {
var position = new Cartesian3(100000.0, -200000.0, 300000.0);
var positions = [position, Cartesian3.clone(position)];
Expand Down
20 changes: 10 additions & 10 deletions Specs/Core/PolylinePipelineSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,40 @@ defineSuite([
expect(noDuplicates).toEqual(positions);
});

it('removeDuplicates to remove positions within absolute epsilon 7', function() {
it('removeDuplicates to remove positions within absolute epsilon 10', function() {
var positions = [
new Cartesian3(1.0, 1.0, 1.0),
new Cartesian3(1.0, 2.0, 3.0),
new Cartesian3(1.0, 2.0, 3.0 + CesiumMath.EPSILON7)];
new Cartesian3(1.0, 2.0, 3.0 + CesiumMath.EPSILON10)];
var expectedPositions = [
new Cartesian3(1.0, 1.0, 1.0),
new Cartesian3(1.0, 2.0, 3.0)];
var noDuplicates = PolylinePipeline.removeDuplicates(positions);
expect(noDuplicates).toEqual(expectedPositions);
});

it('removeDuplicates to remove positions within relative epsilon 7', function() {
it('removeDuplicates to remove positions within relative epsilon 10', function() {
var positions = [
new Cartesian3(0.0, 0.0, 1000000.0),
new Cartesian3(0.0, 0.0, 3000000.0),
new Cartesian3(0.0, 0.0, 3000000.2)];
new Cartesian3(0.0, 0.0, 3000000.0002)];
var expectedPositions = [
new Cartesian3(0.0, 0.0, 1000000.0),
new Cartesian3(0.0, 0.0, 3000000.0)];
var noDuplicates = PolylinePipeline.removeDuplicates(positions);
expect(noDuplicates).toEqual(expectedPositions);
});

it('removeDuplicates keeps positions that add up past relative epsilon 7', function() {
var eightyPercentOfEpsilon7 = 0.8 * CesiumMath.EPSILON7;
it('removeDuplicates keeps positions that add up past relative epsilon 10', function() {
var eightyPercentOfEpsilon = 0.8 * CesiumMath.EPSILON10;
var positions = [
new Cartesian3(0.0, 0.0, 1.0),
new Cartesian3(0.0, 0.0, 1.0 + eightyPercentOfEpsilon7),
new Cartesian3(0.0, 0.0, 1.0 + (2 * eightyPercentOfEpsilon7)),
new Cartesian3(0.0, 0.0, 1.0 + (3 * eightyPercentOfEpsilon7))];
new Cartesian3(0.0, 0.0, 1.0 + eightyPercentOfEpsilon),
new Cartesian3(0.0, 0.0, 1.0 + (2 * eightyPercentOfEpsilon)),
new Cartesian3(0.0, 0.0, 1.0 + (3 * eightyPercentOfEpsilon))];
var expectedPositions = [
new Cartesian3(0.0, 0.0, 1.0),
new Cartesian3(0.0, 0.0, 1.0 + (2 * eightyPercentOfEpsilon7))];
new Cartesian3(0.0, 0.0, 1.0 + (2 * eightyPercentOfEpsilon))];
var noDuplicates = PolylinePipeline.removeDuplicates(positions);
expect(noDuplicates).toEqual(expectedPositions);
});
Expand Down

0 comments on commit c796c61

Please sign in to comment.