Skip to content

Commit

Permalink
Merge pull request #1201 from DavidHudlow/FixComplexTriangulationFailure
Browse files Browse the repository at this point in the history
Tolerate (but don't fully render) complex polygons
  • Loading branch information
pjcozzi committed Sep 30, 2013
2 parents 16f409f + f951711 commit 92babfa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Beta Releases
becomes

return primitives.add(new Primitive(/* ... */));
* Fixed bug in triangulation that fails on complex polygons. Instead, it makes a "best effort" to render what it can.

### b20 - 2013-09-03

Expand Down
5 changes: 5 additions & 0 deletions Source/Core/GeometryPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ define([

for ( var i = 0; i < values3D.length; i += 3) {
var value = Cartesian3.fromArray(values3D, i, scratchProjectTo2DCartesian3);

if (Cartesian3.equals(value, Cartesian3.ZERO)) {
continue;
}

var lonLat = ellipsoid.cartesianToCartographic(value, scratchProjectTo2DCartographic);
var projectedLonLat = projection.project(lonLat, scratchProjectTo2DCartesian3);

Expand Down
4 changes: 4 additions & 0 deletions Source/Core/PolygonGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ define([
}

var indices = PolygonPipeline.triangulate(positions2D);
/* If polygon is completely unrenderable, just use the first three vertices */
if (indices.length < 3) {
indices = [0, 1, 2];
}
return new GeometryInstance({
geometry : PolygonPipeline.computeSubdivision(positions, indices, granularity)
});
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/PolygonPipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ define([
* @returns {Array} Index array representing triangles that fill the polygon
*
* @exception {DeveloperError} Invalid polygon: must have at least three vertices.
* @exception {DeveloperERror} Tried x times to find a vild cut and couldn't.
*
* @private
*/
Expand Down Expand Up @@ -736,7 +735,8 @@ define([
// Make sure we don't go into an endless loop
var maxTries = nodeArray.length * 10;
if (tries > maxTries) {
throw new DeveloperError('Tried ' + maxTries + ' times to find a valid cut and couldn\'t.');
// Hopefully that part of the polygon isn't important
return [];
}
tries++;

Expand Down

0 comments on commit 92babfa

Please sign in to comment.