| 6421 | // Accumulate, smooth contour rings, assign holes to exterior rings. |
| 6422 | // Based on https://github.com/mbostock/shapefile/blob/v0.6.2/shp/polygon.js |
| 6423 | function contour(values, value) { |
| 6424 | const v = value == null ? NaN : +value; |
| 6425 | if (isNaN(v)) throw new Error(`invalid value: ${value}`); |
| 6426 | |
| 6427 | var polygons = [], |
| 6428 | holes = []; |
| 6429 | |
| 6430 | isorings(values, v, function(ring) { |
| 6431 | smooth(ring, values, v); |
| 6432 | if (area$3(ring) > 0) polygons.push([ring]); |
| 6433 | else holes.push(ring); |
| 6434 | }); |
| 6435 | |
| 6436 | holes.forEach(function(hole) { |
| 6437 | for (var i = 0, n = polygons.length, polygon; i < n; ++i) { |
| 6438 | if (contains$2((polygon = polygons[i])[0], hole) !== -1) { |
| 6439 | polygon.push(hole); |
| 6440 | return; |
| 6441 | } |
| 6442 | } |
| 6443 | }); |
| 6444 | |
| 6445 | return { |
| 6446 | type: "MultiPolygon", |
| 6447 | value: value, |
| 6448 | coordinates: polygons |
| 6449 | }; |
| 6450 | } |
| 6451 | |
| 6452 | // Marching squares with isolines stitched into rings. |
| 6453 | // Based on https://github.com/topojson/topojson-client/blob/v3.0.0/src/stitch.js |