|
6331 | 6331 | buffer = []; |
6332 | 6332 | return result; |
6333 | 6333 | } |
6334 | | - path.area = d3_geo_type({ |
6335 | | - Feature: function(feature) { |
6336 | | - return areaType.geometry(feature.geometry); |
6337 | | - }, |
6338 | | - FeatureCollection: function(collection) { |
6339 | | - return d3.sum(collection.features, areaType.Feature); |
6340 | | - }, |
6341 | | - GeometryCollection: function(collection) { |
6342 | | - return d3.sum(collection.geometries, areaType.geometry); |
6343 | | - }, |
6344 | | - LineString: d3_zero, |
6345 | | - MultiLineString: d3_zero, |
6346 | | - MultiPoint: d3_zero, |
6347 | | - MultiPolygon: objectArea, |
6348 | | - Point: d3_zero, |
6349 | | - Polygon: objectArea, |
6350 | | - Sphere: objectArea |
6351 | | - }); |
6352 | | - function objectArea(o) { |
6353 | | - o = projection.object(o); |
6354 | | - return o ? o.type === "Polygon" ? polygonArea(o.coordinates) : d3.sum(o.coordinates, polygonArea) : 0; |
6355 | | - } |
6356 | | - function polygonArea(polygon) { |
6357 | | - return Math.abs(d3.sum(polygon, ringArea)); |
6358 | | - } |
6359 | | - function ringArea(ring) { |
6360 | | - return d3.geom.polygon(ring).area(); |
6361 | | - } |
| 6334 | + path.area = function(object) { |
| 6335 | + d3_geo_areaSum = 0; |
| 6336 | + d3.geo.stream(object, projection.stream(d3_geo_pathArea)); |
| 6337 | + return d3_geo_areaSum; |
| 6338 | + }; |
6362 | 6339 | path.bounds = function(object) { |
6363 | 6340 | return d3_geo_bounds(projection)(object); |
6364 | 6341 | }; |
|
6449 | 6426 | function d3_geo_pathCircle(radius) { |
6450 | 6427 | return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + +2 * radius + "z"; |
6451 | 6428 | } |
| 6429 | + var d3_geo_pathExterior; |
| 6430 | + var d3_geo_pathArea = { |
| 6431 | + point: d3_noop, |
| 6432 | + lineStart: d3_noop, |
| 6433 | + lineEnd: d3_noop, |
| 6434 | + polygonStart: function() { |
| 6435 | + d3_geo_pathExterior = true; |
| 6436 | + d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart; |
| 6437 | + d3_geo_pathArea.lineEnd = d3_geo_pathAreaRingEnd; |
| 6438 | + }, |
| 6439 | + polygonEnd: function() { |
| 6440 | + d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop; |
| 6441 | + } |
| 6442 | + }; |
| 6443 | + function d3_geo_pathAreaRingStart() { |
| 6444 | + var x0, y0; |
| 6445 | + d3_geo_pathArea.point = function(x, y) { |
| 6446 | + d3_geo_pathArea.point = nextPoint; |
| 6447 | + x0 = x, y0 = y; |
| 6448 | + }; |
| 6449 | + function nextPoint(x, y) { |
| 6450 | + d3_geo_areaRing += y0 * x - x0 * y; |
| 6451 | + x0 = x, y0 = y; |
| 6452 | + } |
| 6453 | + } |
| 6454 | + function d3_geo_pathAreaRingEnd() { |
| 6455 | + d3_geo_areaSum += Math.abs(d3_geo_areaRing) / (d3_geo_pathExterior ? 2 : -2); |
| 6456 | + d3_geo_pathExterior = false; |
| 6457 | + } |
6452 | 6458 | d3.geo.area = function(object) { |
6453 | 6459 | d3_geo_areaSum = 0; |
6454 | 6460 | d3.geo.stream(object, d3_geo_area); |
|
6468 | 6474 | }, |
6469 | 6475 | polygonEnd: function() { |
6470 | 6476 | d3_geo_areaSum += d3_geo_areaRing < 0 ? 4 * π + d3_geo_areaRing : d3_geo_areaRing; |
6471 | | - d3_geo_area.point = d3_geo_area.lineStart = d3_noop; |
| 6477 | + d3_geo_area.lineStart = d3_geo_area.point = d3_noop; |
6472 | 6478 | } |
6473 | 6479 | }; |
6474 | 6480 | function d3_geo_areaRingStart() { |
6475 | 6481 | var λ00, φ00, λ0, φ0, cosφ0, sinφ0; |
6476 | 6482 | d3_geo_area.point = function(λ, φ) { |
6477 | | - λ00 = λ0 = λ * d3_radians, φ00 = φ0 = φ * d3_radians, cosφ0 = Math.cos(φ0), sinφ0 = Math.sin(φ0); |
6478 | 6483 | d3_geo_area.point = nextPoint; |
| 6484 | + λ00 = λ0 = λ * d3_radians, φ00 = φ0 = φ * d3_radians, cosφ0 = Math.cos(φ0), sinφ0 = Math.sin(φ0); |
6479 | 6485 | }; |
6480 | 6486 | function nextPoint(λ, φ) { |
6481 | 6487 | λ *= d3_radians, φ *= d3_radians; |
|
0 commit comments