| 130468 | } // Accumulate, smooth contour rings, assign holes to exterior rings. |
| 130469 | // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js |
| 130470 | function contour(values, value) { |
| 130471 | var polygons = [], holes = []; |
| 130472 | isorings(values, value, (ring)=>{ |
| 130473 | smooth(ring, values, value); |
| 130474 | if (area(ring) > 0) polygons.push([ |
| 130475 | ring |
| 130476 | ]); |
| 130477 | else holes.push(ring); |
| 130478 | }); |
| 130479 | holes.forEach((hole)=>{ |
| 130480 | for(var i = 0, n = polygons.length, polygon; i < n; ++i)if (contains((polygon = polygons[i])[0], hole) !== -1) { |
| 130481 | polygon.push(hole); |
| 130482 | return; |
| 130483 | } |
| 130484 | }); |
| 130485 | return { |
| 130486 | type: "MultiPolygon", |
| 130487 | value: value, |
| 130488 | coordinates: polygons |
| 130489 | }; |
| 130490 | } // Marching squares with isolines stitched into rings. |
| 130491 | // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js |
| 130492 | function isorings(values, value, callback) { |
| 130493 | var fragmentByStart = new Array(), fragmentByEnd = new Array(), x, y, t0, t1, t2, t3; // Special case for the first row (y = -1, t2 = t3 = 0). |