MCPcopy Create free account
hub / github.com/microsoft/SandDance / contour

Function contour

docs/app/js/sanddance-app.js:130470–130490  ·  view source on GitHub ↗
(values, value)

Source from the content-addressed store, hash-verified

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).

Callers 1

contours1Function · 0.70

Calls 4

isoringsFunction · 0.70
areaFunction · 0.70
containsFunction · 0.70
forEachMethod · 0.45

Tested by

no test coverage detected