|
21 | 21 | function d3_source(d) { |
22 | 22 | return d.source; |
23 | 23 | } |
| 24 | + function d3_acos(x) { |
| 25 | + return Math.acos(Math.max(-1, Math.min(1, x))); |
| 26 | + } |
24 | 27 | function d3_class(ctor, properties) { |
25 | 28 | try { |
26 | 29 | for (var key in properties) { |
|
5418 | 5421 | d[1] /= l; |
5419 | 5422 | d[2] /= l; |
5420 | 5423 | } |
| 5424 | + d3.geo.distance = function(a, b) { |
| 5425 | + var λ0 = a[0] * d3_radians, φ0 = a[1] * d3_radians, λ1 = b[0] * d3_radians, φ1 = b[1] * d3_radians; |
| 5426 | + return d3_acos(Math.sin(φ0) * Math.sin(φ1) + Math.cos(φ0) * Math.cos(φ1) * Math.cos(λ1 - λ0)); |
| 5427 | + }; |
5421 | 5428 | function d3_geo_resample(project) { |
5422 | 5429 | var δ2 = .5, maxDepth = 16; |
5423 | 5430 | function resample(stream) { |
|
5715 | 5722 | var a = d3_geo_cartesian(point); |
5716 | 5723 | a[0] -= cr; |
5717 | 5724 | d3_geo_cartesianNormalize(a); |
5718 | | - var angle = Math.acos(Math.max(-1, Math.min(1, -a[1]))); |
| 5725 | + var angle = d3_acos(-a[1]); |
5719 | 5726 | return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI); |
5720 | 5727 | } |
5721 | 5728 | function d3_geo_clip(pointVisible, clipLine, interpolate) { |
|
6149 | 6156 | graticule.precision = function(_) { |
6150 | 6157 | if (!arguments.length) return precision; |
6151 | 6158 | precision = +_; |
6152 | | - x = d3_geo_graticuleX(y0, y1, precision); |
| 6159 | + x = d3_geo_graticuleX(y0, y1, 90); |
6153 | 6160 | y = d3_geo_graticuleY(x0, x1, precision); |
6154 | | - X = d3_geo_graticuleX(Y0, Y1, precision); |
| 6161 | + X = d3_geo_graticuleX(Y0, Y1, 90); |
6155 | 6162 | Y = d3_geo_graticuleY(X0, X1, precision); |
6156 | 6163 | return graticule; |
6157 | 6164 | }; |
|
6177 | 6184 | return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians); |
6178 | 6185 | }; |
6179 | 6186 | function d3_geo_interpolate(x0, y0, x1, y1) { |
6180 | | - var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = Math.acos(Math.max(-1, Math.min(1, sy0 * sy1 + cy0 * cy1 * Math.cos(x1 - x0)))), k = 1 / Math.sin(d); |
| 6187 | + var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = d3_acos(sy0 * sy1 + cy0 * cy1 * Math.cos(x1 - x0)), k = 1 / Math.sin(d); |
6181 | 6188 | function interpolate(t) { |
6182 | 6189 | var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1; |
6183 | 6190 | return [ Math.atan2(y, x) / d3_radians, Math.atan2(z, Math.sqrt(x * x + y * y)) / d3_radians ]; |
|
6186 | 6193 | return interpolate; |
6187 | 6194 | } |
6188 | 6195 | d3.geo.greatArc = function() { |
6189 | | - var source = d3_source, source_, target = d3_target, target_, precision = 6 * d3_radians, interpolate; |
| 6196 | + var source = d3_source, source_, target = d3_target, target_; |
6190 | 6197 | function greatArc() { |
6191 | | - var p0 = source_ || source.apply(this, arguments), p1 = target_ || target.apply(this, arguments), i = interpolate || d3.geo.interpolate(p0, p1), t = 0, dt = precision / i.distance, coordinates = [ p0 ]; |
6192 | | - while ((t += dt) < 1) coordinates.push(i(t)); |
6193 | | - coordinates.push(p1); |
6194 | 6198 | return { |
6195 | 6199 | type: "LineString", |
6196 | | - coordinates: coordinates |
| 6200 | + coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ] |
6197 | 6201 | }; |
6198 | 6202 | } |
6199 | 6203 | greatArc.distance = function() { |
6200 | | - return (interpolate || d3.geo.interpolate(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments))).distance; |
| 6204 | + return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments)); |
6201 | 6205 | }; |
6202 | 6206 | greatArc.source = function(_) { |
6203 | 6207 | if (!arguments.length) return source; |
6204 | 6208 | source = _, source_ = typeof _ === "function" ? null : _; |
6205 | | - interpolate = source_ && target_ ? d3.geo.interpolate(source_, target_) : null; |
6206 | 6209 | return greatArc; |
6207 | 6210 | }; |
6208 | 6211 | greatArc.target = function(_) { |
6209 | 6212 | if (!arguments.length) return target; |
6210 | 6213 | target = _, target_ = typeof _ === "function" ? null : _; |
6211 | | - interpolate = source_ && target_ ? d3.geo.interpolate(source_, target_) : null; |
6212 | 6214 | return greatArc; |
6213 | 6215 | }; |
6214 | | - greatArc.precision = function(_) { |
6215 | | - if (!arguments.length) return precision / d3_radians; |
6216 | | - precision = _ * d3_radians; |
6217 | | - return greatArc; |
| 6216 | + greatArc.precision = function() { |
| 6217 | + return arguments.length ? greatArc : 0; |
6218 | 6218 | }; |
6219 | 6219 | return greatArc; |
6220 | 6220 | }; |
|
0 commit comments