@@ -3487,6 +3487,33 @@ d3 = function() {
34873487 }
34883488 return stream ;
34893489 }
3490+ var d3_geo_pathDistanceSum , d3_geo_pathDistancePolygon , d3_geo_pathDistance = {
3491+ point : d3_noop ,
3492+ lineStart : d3_geo_pathDistanceLineStart ,
3493+ lineEnd : d3_noop ,
3494+ polygonStart : function ( ) {
3495+ d3_geo_pathDistancePolygon = true ;
3496+ } ,
3497+ polygonEnd : function ( ) {
3498+ d3_geo_pathDistancePolygon = false ;
3499+ }
3500+ } ;
3501+ function d3_geo_pathDistanceLineStart ( ) {
3502+ var x00 , y00 , x0 , y0 ;
3503+ d3_geo_pathDistance . point = function ( x , y ) {
3504+ d3_geo_pathDistance . point = nextPoint ;
3505+ x00 = x0 = x , y00 = y0 = y ;
3506+ } ;
3507+ d3_geo_pathDistance . lineEnd = function ( ) {
3508+ if ( d3_geo_pathDistancePolygon ) nextPoint ( x00 , y00 ) ;
3509+ d3_geo_pathDistance . point = d3_geo_pathDistance . lineEnd = d3_noop ;
3510+ } ;
3511+ function nextPoint ( x , y ) {
3512+ var dx = x - x0 , dy = y - y0 ;
3513+ d3_geo_pathDistanceSum += Math . sqrt ( dx * dx + dy * dy ) ;
3514+ x0 = x , y0 = y ;
3515+ }
3516+ }
34903517 function d3_geo_resample ( project ) {
34913518 var δ2 = .5 , cosMinDistance = Math . cos ( 30 * d3_radians ) , maxDepth = 16 ;
34923519 function resample ( stream ) {
@@ -3613,6 +3640,11 @@ d3 = function() {
36133640 d3 . geo . stream ( object , projectStream ( d3_geo_pathBounds ) ) ;
36143641 return [ [ d3_geo_pathBoundsX0 , d3_geo_pathBoundsY0 ] , [ d3_geo_pathBoundsX1 , d3_geo_pathBoundsY1 ] ] ;
36153642 } ;
3643+ path . distance = function ( object ) {
3644+ d3_geo_pathDistanceSum = 0 ;
3645+ d3 . geo . stream ( object , projectStream ( d3_geo_pathDistance ) ) ;
3646+ return d3_geo_pathDistanceSum ;
3647+ } ;
36163648 path . projection = function ( _ ) {
36173649 if ( ! arguments . length ) return projection ;
36183650 projectStream = ( projection = _ ) ? _ . stream || d3_geo_pathProjectStream ( _ ) : d3_identity ;
0 commit comments