| 116356 | } |
| 116357 | |
| 116358 | function resample(project, delta2) { |
| 116359 | function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) { |
| 116360 | var dx = x1 - x0, |
| 116361 | dy = y1 - y0, |
| 116362 | d2 = dx * dx + dy * dy; |
| 116363 | |
| 116364 | if (d2 > 4 * delta2 && depth--) { |
| 116365 | var a = a0 + a1, |
| 116366 | b = b0 + b1, |
| 116367 | c = c0 + c1, |
| 116368 | m = (0, _math.sqrt)(a * a + b * b + c * c), |
| 116369 | phi2 = (0, _math.asin)(c /= m), |
| 116370 | lambda2 = (0, _math.abs)((0, _math.abs)(c) - 1) < _math.epsilon || (0, _math.abs)(lambda0 - lambda1) < _math.epsilon ? (lambda0 + lambda1) / 2 : (0, _math.atan2)(b, a), |
| 116371 | p = project(lambda2, phi2), |
| 116372 | x2 = p[0], |
| 116373 | y2 = p[1], |
| 116374 | dx2 = x2 - x0, |
| 116375 | dy2 = y2 - y0, |
| 116376 | dz = dy * dx2 - dx * dy2; |
| 116377 | |
| 116378 | if (dz * dz / d2 > delta2 // perpendicular projected distance |
| 116379 | || (0, _math.abs)((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end |
| 116380 | || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { |
| 116381 | // angular distance |
| 116382 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream); |
| 116383 | stream.point(x2, y2); |
| 116384 | resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream); |
| 116385 | } |
| 116386 | } |
| 116387 | } |
| 116388 | |
| 116389 | return function (stream) { |
| 116390 | var lambda00, x00, y00, a00, b00, c00, // first point |
| 116391 | lambda0, x0, y0, a0, b0, c0; // previous point |
| 116392 | |
| 116393 | var resampleStream = { |
| 116394 | point: point, |
| 116395 | lineStart: lineStart, |
| 116396 | lineEnd: lineEnd, |
| 116397 | polygonStart: function () { |
| 116398 | stream.polygonStart(); |
| 116399 | resampleStream.lineStart = ringStart; |
| 116400 | }, |
| 116401 | polygonEnd: function () { |
| 116402 | stream.polygonEnd(); |
| 116403 | resampleStream.lineStart = lineStart; |
| 116404 | } |
| 116405 | }; |
| 116406 | |
| 116407 | function point(x, y) { |
| 116408 | x = project(x, y); |
| 116409 | stream.point(x[0], x[1]); |
| 116410 | } |
| 116411 | |
| 116412 | function lineStart() { |
| 116413 | x0 = NaN; |
| 116414 | resampleStream.point = linePoint; |
| 116415 | stream.lineStart(); |