|
6376 | 6376 | polygonStart: function() { |
6377 | 6377 | d3_geo_pathAreaScale = .5; |
6378 | 6378 | d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart; |
6379 | | - d3_geo_pathArea.lineEnd = d3_geo_pathAreaRingEnd; |
6380 | 6379 | }, |
6381 | 6380 | polygonEnd: function() { |
6382 | 6381 | d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop; |
6383 | 6382 | } |
6384 | 6383 | }; |
6385 | 6384 | function d3_geo_pathAreaRingStart() { |
6386 | | - var x0, y0; |
6387 | | - d3_geo_areaRing = 0; |
| 6385 | + var x00, y00, x0, y0, area = 0; |
6388 | 6386 | d3_geo_pathArea.point = function(x, y) { |
6389 | 6387 | d3_geo_pathArea.point = nextPoint; |
6390 | | - x0 = x, y0 = y; |
| 6388 | + x00 = x0 = x, y00 = y0 = y; |
6391 | 6389 | }; |
6392 | 6390 | function nextPoint(x, y) { |
6393 | | - d3_geo_areaRing += y0 * x - x0 * y; |
| 6391 | + area += y0 * x - x0 * y; |
6394 | 6392 | x0 = x, y0 = y; |
6395 | 6393 | } |
6396 | | - } |
6397 | | - function d3_geo_pathAreaRingEnd() { |
6398 | | - d3_geo_areaSum += Math.abs(d3_geo_areaRing) * d3_geo_pathAreaScale; |
6399 | | - d3_geo_pathAreaScale = -.5; |
| 6394 | + d3_geo_pathArea.lineEnd = function() { |
| 6395 | + nextPoint(x00, y00); |
| 6396 | + d3_geo_areaSum += Math.abs(area) * d3_geo_pathAreaScale; |
| 6397 | + d3_geo_pathAreaScale = -.5; |
| 6398 | + }; |
6400 | 6399 | } |
6401 | 6400 | var d3_geo_pathCentroid = { |
6402 | | - point: function(x, y) { |
6403 | | - d3_geo_centroidX += x; |
6404 | | - d3_geo_centroidY += y; |
6405 | | - ++d3_geo_centroidZ; |
6406 | | - }, |
| 6401 | + point: d3_geo_pathCentroidPoint, |
6407 | 6402 | lineStart: d3_geo_pathCentroidLineStart, |
6408 | | - lineEnd: function() { |
6409 | | - d3_geo_pathCentroid.point = d3_noop; |
6410 | | - }, |
| 6403 | + lineEnd: d3_geo_pathCentroidLineEnd, |
6411 | 6404 | polygonStart: function() { |
6412 | 6405 | d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart; |
6413 | 6406 | }, |
6414 | 6407 | polygonEnd: function() { |
| 6408 | + d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint; |
6415 | 6409 | d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart; |
| 6410 | + d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd; |
6416 | 6411 | } |
6417 | 6412 | }; |
| 6413 | + function d3_geo_pathCentroidPoint(x, y) { |
| 6414 | + d3_geo_centroidX += x; |
| 6415 | + d3_geo_centroidY += y; |
| 6416 | + ++d3_geo_centroidZ; |
| 6417 | + } |
6418 | 6418 | function d3_geo_pathCentroidLineStart() { |
6419 | 6419 | var x0, y0; |
6420 | 6420 | d3_geo_pathCentroid.point = function(x, y) { |
|
6429 | 6429 | x0 = x, y0 = y; |
6430 | 6430 | } |
6431 | 6431 | } |
| 6432 | + function d3_geo_pathCentroidLineEnd() { |
| 6433 | + d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint; |
| 6434 | + } |
6432 | 6435 | function d3_geo_pathCentroidRingStart() { |
6433 | 6436 | var x00, y00, x0, y0; |
6434 | 6437 | d3_geo_pathCentroid.point = function(x, y) { |
|
6442 | 6445 | d3_geo_centroidZ += z * 3; |
6443 | 6446 | x0 = x, y0 = y; |
6444 | 6447 | } |
| 6448 | + d3_geo_pathCentroid.lineEnd = function() { |
| 6449 | + nextPoint(x00, y00); |
| 6450 | + }; |
6445 | 6451 | } |
6446 | 6452 | d3.geo.area = function(object) { |
6447 | 6453 | d3_geo_areaSum = 0; |
|
6462 | 6468 | }, |
6463 | 6469 | polygonEnd: function() { |
6464 | 6470 | d3_geo_areaSum += d3_geo_areaRing < 0 ? 4 * π + d3_geo_areaRing : d3_geo_areaRing; |
6465 | | - d3_geo_area.lineStart = d3_geo_area.point = d3_noop; |
| 6471 | + d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop; |
6466 | 6472 | } |
6467 | 6473 | }; |
6468 | 6474 | function d3_geo_areaRingStart() { |
6469 | | - var λ00, φ00, λ0, φ0, cosφ0, sinφ0; |
| 6475 | + var λ00, φ00, λ1, λ0, φ0, cosφ0, sinφ0; |
6470 | 6476 | d3_geo_area.point = function(λ, φ) { |
6471 | 6477 | d3_geo_area.point = nextPoint; |
6472 | | - λ00 = λ0 = λ * d3_radians, φ00 = φ0 = φ * d3_radians, cosφ0 = Math.cos(φ0), sinφ0 = Math.sin(φ0); |
| 6478 | + λ1 = λ0 = (λ00 = λ) * d3_radians, φ0 = (φ00 = φ) * d3_radians, cosφ0 = Math.cos(φ0), |
| 6479 | + sinφ0 = Math.sin(φ0); |
6473 | 6480 | }; |
6474 | 6481 | function nextPoint(λ, φ) { |
6475 | 6482 | λ *= d3_radians, φ *= d3_radians; |
6476 | 6483 | if (Math.abs(Math.abs(φ0) - π / 2) < ε && Math.abs(Math.abs(φ) - π / 2) < ε) return; |
6477 | 6484 | var cosφ = Math.cos(φ), sinφ = Math.sin(φ); |
6478 | | - if (Math.abs(φ0 - π / 2) < ε) d3_geo_areaRing += (λ - λ00) * 2; else { |
| 6485 | + if (Math.abs(φ0 - π / 2) < ε) d3_geo_areaRing += (λ - λ1) * 2; else { |
6479 | 6486 | var dλ = λ - λ0, cosdλ = Math.cos(dλ), d = Math.atan2(Math.sqrt((d = cosφ * Math.sin(dλ)) * d + (d = cosφ0 * sinφ - sinφ0 * cosφ * cosdλ) * d), sinφ0 * sinφ + cosφ0 * cosφ * cosdλ), s = (d + π + φ0 + φ) / 4; |
6480 | 6487 | d3_geo_areaRing += (dλ < 0 && dλ > -π || dλ > π ? -4 : 4) * Math.atan(Math.sqrt(Math.abs(Math.tan(s) * Math.tan(s - d / 2) * Math.tan(s - π / 4 - φ0 / 2) * Math.tan(s - π / 4 - φ / 2)))); |
6481 | 6488 | } |
6482 | | - λ00 = λ0, φ00 = φ0, λ0 = λ, φ0 = φ, cosφ0 = cosφ, sinφ0 = sinφ; |
| 6489 | + λ1 = λ0, φ1 = φ0, λ0 = λ, φ0 = φ, cosφ0 = cosφ, sinφ0 = sinφ; |
6483 | 6490 | } |
| 6491 | + d3_geo_area.lineEnd = function() { |
| 6492 | + nextPoint(λ00, φ00); |
| 6493 | + }; |
6484 | 6494 | } |
6485 | 6495 | d3.geo.projection = d3_geo_projection; |
6486 | 6496 | d3.geo.projectionMutator = d3_geo_projectionMutator; |
|
0 commit comments