MCPcopy Create free account
hub / github.com/breck7/scroll / hull

Function hull

external/.d3.js:14374–14400  ·  view source on GitHub ↗
(points)

Source from the content-addressed store, hash-verified

14372}
14373
14374function hull(points) {
14375 if ((n = points.length) < 3) return null;
14376
14377 var i,
14378 n,
14379 sortedPoints = new Array(n),
14380 flippedPoints = new Array(n);
14381
14382 for (i = 0; i < n; ++i) sortedPoints[i] = [+points[i][0], +points[i][1], i];
14383 sortedPoints.sort(lexicographicOrder);
14384 for (i = 0; i < n; ++i) flippedPoints[i] = [sortedPoints[i][0], -sortedPoints[i][1]];
14385
14386 var upperIndexes = computeUpperHullIndexes(sortedPoints),
14387 lowerIndexes = computeUpperHullIndexes(flippedPoints);
14388
14389 // Construct the hull polygon, removing possible duplicate endpoints.
14390 var skipLeft = lowerIndexes[0] === upperIndexes[0],
14391 skipRight = lowerIndexes[lowerIndexes.length - 1] === upperIndexes[upperIndexes.length - 1],
14392 hull = [];
14393
14394 // Add upper hull in right-to-l order.
14395 // Then add lower hull in left-to-right order.
14396 for (i = upperIndexes.length - 1; i >= 0; --i) hull.push(points[sortedPoints[upperIndexes[i]][2]]);
14397 for (i = +skipLeft; i < lowerIndexes.length - skipRight; ++i) hull.push(points[sortedPoints[lowerIndexes[i]][2]]);
14398
14399 return hull;
14400}
14401
14402function contains(polygon, point) {
14403 var n = polygon.length,

Callers

nothing calls this directly

Calls 2

computeUpperHullIndexesFunction · 0.85
sortMethod · 0.80

Tested by

no test coverage detected