Skip to content

Tolerate (but don't fully render) complex polygons #1201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 30, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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