| 134124 | }); |
| 134125 | } |
| 134126 | function resample(project, delta2) { |
| 134127 | function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) { |
| 134128 | var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy; |
| 134129 | if (d2 > 4 * delta2 && depth--) { |
| 134130 | var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = (0, _mathJs.sqrt)(a * a + b * b + c * c), phi2 = (0, _mathJs.asin)(c /= m), lambda2 = (0, _mathJs.abs)((0, _mathJs.abs)(c) - 1) < (0, _mathJs.epsilon) || (0, _mathJs.abs)(lambda0 - lambda1) < (0, _mathJs.epsilon) ? (lambda0 + lambda1) / 2 : (0, _mathJs.atan2)(b, a), p = project(lambda2, phi2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2; |
| 134131 | if (dz * dz / d2 > delta2 // perpendicular projected distance |
| 134132 | || (0, _mathJs.abs)((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3 // midpoint close to an end |
| 134133 | || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) { |
| 134134 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream); |
| 134135 | stream.point(x2, y2); |
| 134136 | resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream); |
| 134137 | } |
| 134138 | } |
| 134139 | } |
| 134140 | return function(stream) { |
| 134141 | var lambda00, x00, y00, a00, b00, c00, lambda0, x0, y0, a0, b0, c0; // previous point |
| 134142 | var resampleStream = { |
| 134143 | point: point, |
| 134144 | lineStart: lineStart, |
| 134145 | lineEnd: lineEnd, |
| 134146 | polygonStart: function() { |
| 134147 | stream.polygonStart(); |
| 134148 | resampleStream.lineStart = ringStart; |
| 134149 | }, |
| 134150 | polygonEnd: function() { |
| 134151 | stream.polygonEnd(); |
| 134152 | resampleStream.lineStart = lineStart; |
| 134153 | } |
| 134154 | }; |
| 134155 | function point(x, y) { |
| 134156 | x = project(x, y); |
| 134157 | stream.point(x[0], x[1]); |
| 134158 | } |
| 134159 | function lineStart() { |
| 134160 | x0 = NaN; |
| 134161 | resampleStream.point = linePoint; |
| 134162 | stream.lineStart(); |
| 134163 | } |
| 134164 | function linePoint(lambda, phi) { |
| 134165 | var c = (0, _cartesianJs.cartesian)([ |
| 134166 | lambda, |
| 134167 | phi |
| 134168 | ]), p = project(lambda, phi); |
| 134169 | 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); |
| 134170 | stream.point(x0, y0); |
| 134171 | } |
| 134172 | function lineEnd() { |
| 134173 | resampleStream.point = point; |
| 134174 | stream.lineEnd(); |
| 134175 | } |
| 134176 | function ringStart() { |
| 134177 | lineStart(); |
| 134178 | resampleStream.point = ringPoint; |
| 134179 | resampleStream.lineEnd = ringEnd; |
| 134180 | } |
| 134181 | function ringPoint(lambda, phi) { |
| 134182 | linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0; |
| 134183 | resampleStream.point = linePoint; |