MCPcopy Create free account
hub / github.com/breck7/scroll / resample$1

Function resample$1

external/.d3.js:12120–12201  ·  view source on GitHub ↗
(project, delta2)

Source from the content-addressed store, hash-verified

12118}
12119
12120function resample$1(project, delta2) {
12121
12122 function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
12123 var dx = x1 - x0,
12124 dy = y1 - y0,
12125 d2 = dx * dx + dy * dy;
12126 if (d2 > 4 * delta2 && depth--) {
12127 var a = a0 + a1,
12128 b = b0 + b1,
12129 c = c0 + c1,
12130 m = sqrt$2(a * a + b * b + c * c),
12131 phi2 = asin$1(c /= m),
12132 lambda2 = abs$1(abs$1(c) - 1) < epsilon$1 || abs$1(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2$1(b, a),
12133 p = project(lambda2, phi2),
12134 x2 = p[0],
12135 y2 = p[1],
12136 dx2 = x2 - x0,
12137 dy2 = y2 - y0,
12138 dz = dy * dx2 - dx * dy2;
12139 if (dz * dz / d2 > delta2 // perpendicular projected distance
12140 || abs$1((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end
12141 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { // angular distance
12142 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
12143 stream.point(x2, y2);
12144 resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
12145 }
12146 }
12147 }
12148 return function(stream) {
12149 var lambda00, x00, y00, a00, b00, c00, // first point
12150 lambda0, x0, y0, a0, b0, c0; // previous point
12151
12152 var resampleStream = {
12153 point: point,
12154 lineStart: lineStart,
12155 lineEnd: lineEnd,
12156 polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
12157 polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
12158 };
12159
12160 function point(x, y) {
12161 x = project(x, y);
12162 stream.point(x[0], x[1]);
12163 }
12164
12165 function lineStart() {
12166 x0 = NaN;
12167 resampleStream.point = linePoint;
12168 stream.lineStart();
12169 }
12170
12171 function linePoint(lambda, phi) {
12172 var c = cartesian([lambda, phi]), p = project(lambda, phi);
12173 resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
12174 stream.point(x0, y0);
12175 }
12176
12177 function lineEnd() {

Callers 1

resampleFunction · 0.85

Calls 2

polygonStartMethod · 0.80
polygonEndMethod · 0.80

Tested by

no test coverage detected