|
1116 | 1116 | var rect = container.getBoundingClientRect();
|
1117 | 1117 | return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
|
1118 | 1118 | }
|
1119 |
| - d3.touches = function(container, touches) { |
1120 |
| - if (arguments.length < 2) touches = d3_eventSource().touches; |
1121 |
| - return touches ? d3_array(touches).map(function(touch) { |
1122 |
| - var point = d3_mousePoint(container, touch); |
1123 |
| - point.identifier = touch.identifier; |
1124 |
| - return point; |
1125 |
| - }) : []; |
| 1119 | + d3.touch = function(container, touches, identifier) { |
| 1120 | + if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches; |
| 1121 | + if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) { |
| 1122 | + if ((touch = touches[i]).identifier === identifier) { |
| 1123 | + return d3_mousePoint(container, touch); |
| 1124 | + } |
| 1125 | + } |
1126 | 1126 | };
|
1127 | 1127 | d3.behavior.drag = function() {
|
1128 | 1128 | var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_behavior_dragMouseSubject, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_behavior_dragTouchSubject, "touchmove", "touchend");
|
|
1182 | 1182 | function d3_behavior_dragMouseSubject() {
|
1183 | 1183 | return d3_window;
|
1184 | 1184 | }
|
| 1185 | + d3.touches = function(container, touches) { |
| 1186 | + if (arguments.length < 2) touches = d3_eventSource().touches; |
| 1187 | + return touches ? d3_array(touches).map(function(touch) { |
| 1188 | + var point = d3_mousePoint(container, touch); |
| 1189 | + point.identifier = touch.identifier; |
| 1190 | + return point; |
| 1191 | + }) : []; |
| 1192 | + }; |
1185 | 1193 | var π = Math.PI, τ = 2 * π, halfπ = π / 2, ε = 1e-6, ε2 = ε * ε, d3_radians = π / 180, d3_degrees = 180 / π;
|
1186 | 1194 | function d3_sgn(x) {
|
1187 | 1195 | return x > 0 ? 1 : x < 0 ? -1 : 0;
|
|
2022 | 2030 | };
|
2023 | 2031 | d3.csv = d3.dsv(",", "text/csv");
|
2024 | 2032 | d3.tsv = d3.dsv(" ", "text/tab-separated-values");
|
2025 |
| - d3.touch = function(container, touches, identifier) { |
2026 |
| - if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches; |
2027 |
| - if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) { |
2028 |
| - if ((touch = touches[i]).identifier === identifier) { |
2029 |
| - return d3_mousePoint(container, touch); |
2030 |
| - } |
2031 |
| - } |
2032 |
| - }; |
2033 | 2033 | var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_active, d3_timer_frame = d3_window[d3_vendorSymbol(d3_window, "requestAnimationFrame")] || function(callback) {
|
2034 | 2034 | setTimeout(callback, 17);
|
2035 | 2035 | };
|
|
3320 | 3320 | function d3_geo_clipSort(a, b) {
|
3321 | 3321 | return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
|
3322 | 3322 | }
|
3323 |
| - function d3_geo_pointInPolygon(point, polygon) { |
3324 |
| - var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0; |
3325 |
| - d3_geo_areaRingSum.reset(); |
3326 |
| - for (var i = 0, n = polygon.length; i < n; ++i) { |
3327 |
| - var ring = polygon[i], m = ring.length; |
3328 |
| - if (!m) continue; |
3329 |
| - var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1; |
3330 |
| - while (true) { |
3331 |
| - if (j === m) j = 0; |
3332 |
| - point = ring[j]; |
3333 |
| - var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ; |
3334 |
| - d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ))); |
3335 |
| - polarAngle += antimeridian ? dλ + sdλ * τ : dλ; |
3336 |
| - if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) { |
3337 |
| - var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point)); |
3338 |
| - d3_geo_cartesianNormalize(arc); |
3339 |
| - var intersection = d3_geo_cartesianCross(meridianNormal, arc); |
3340 |
| - d3_geo_cartesianNormalize(intersection); |
3341 |
| - var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]); |
3342 |
| - if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) { |
3343 |
| - winding += antimeridian ^ dλ >= 0 ? 1 : -1; |
3344 |
| - } |
3345 |
| - } |
3346 |
| - if (!j++) break; |
3347 |
| - λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point; |
3348 |
| - } |
3349 |
| - } |
3350 |
| - return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1; |
3351 |
| - } |
3352 | 3323 | var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
|
3353 | 3324 | function d3_geo_clipAntimeridianLine(listener) {
|
3354 | 3325 | var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
|
|
3416 | 3387 | listener.point(to[0], to[1]);
|
3417 | 3388 | }
|
3418 | 3389 | }
|
| 3390 | + function d3_geo_pointInPolygon(point, polygon) { |
| 3391 | + var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0; |
| 3392 | + d3_geo_areaRingSum.reset(); |
| 3393 | + for (var i = 0, n = polygon.length; i < n; ++i) { |
| 3394 | + var ring = polygon[i], m = ring.length; |
| 3395 | + if (!m) continue; |
| 3396 | + var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1; |
| 3397 | + while (true) { |
| 3398 | + if (j === m) j = 0; |
| 3399 | + point = ring[j]; |
| 3400 | + var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ; |
| 3401 | + d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ))); |
| 3402 | + polarAngle += antimeridian ? dλ + sdλ * τ : dλ; |
| 3403 | + if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) { |
| 3404 | + var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point)); |
| 3405 | + d3_geo_cartesianNormalize(arc); |
| 3406 | + var intersection = d3_geo_cartesianCross(meridianNormal, arc); |
| 3407 | + d3_geo_cartesianNormalize(intersection); |
| 3408 | + var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]); |
| 3409 | + if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) { |
| 3410 | + winding += antimeridian ^ dλ >= 0 ? 1 : -1; |
| 3411 | + } |
| 3412 | + } |
| 3413 | + if (!j++) break; |
| 3414 | + λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point; |
| 3415 | + } |
| 3416 | + } |
| 3417 | + return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < 0) ^ winding & 1; |
| 3418 | + } |
3419 | 3419 | function d3_geo_clipCircle(radius) {
|
3420 | 3420 | var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
|
3421 | 3421 | return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
|
|
0 commit comments