@@ -4,9 +4,8 @@ import "../math/trigonometry";
44import "clip-polygon" ;
55
66function d3_geo_clip ( pointVisible , clipLine , interpolate , clipStart ) {
7- return function ( rotate , listener ) {
8- var line = clipLine ( listener ) ,
9- rotatedClipStart = rotate . invert ( clipStart [ 0 ] , clipStart [ 1 ] ) ;
7+ return function ( sink ) {
8+ var line = clipLine ( sink ) ;
109
1110 var clip = {
1211 point : point ,
@@ -25,63 +24,56 @@ function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
2524 clip . lineEnd = lineEnd ;
2625
2726 segments = d3 . merge ( segments ) ;
28- var clipStartInside = d3_geo_pointInPolygon ( rotatedClipStart , polygon ) ;
27+ var clipStartInside = d3_geo_pointInPolygon ( clipStart , polygon ) ;
2928 if ( segments . length ) {
30- if ( ! polygonStarted ) listener . polygonStart ( ) , polygonStarted = true ;
31- d3_geo_clipPolygon ( segments , d3_geo_clipSort , clipStartInside , interpolate , listener ) ;
29+ if ( ! polygonStarted ) sink . polygonStart ( ) , polygonStarted = true ;
30+ d3_geo_clipPolygon ( segments , d3_geo_clipSort , clipStartInside , interpolate , sink ) ;
3231 } else if ( clipStartInside ) {
33- if ( ! polygonStarted ) listener . polygonStart ( ) , polygonStarted = true ;
34- listener . lineStart ( ) ;
35- interpolate ( null , null , 1 , listener ) ;
36- listener . lineEnd ( ) ;
32+ if ( ! polygonStarted ) sink . polygonStart ( ) , polygonStarted = true ;
33+ sink . lineStart ( ) ;
34+ interpolate ( null , null , 1 , sink ) ;
35+ sink . lineEnd ( ) ;
3736 }
38- if ( polygonStarted ) listener . polygonEnd ( ) , polygonStarted = false ;
37+ if ( polygonStarted ) sink . polygonEnd ( ) , polygonStarted = false ;
3938 segments = polygon = null ;
4039 } ,
4140 sphere : function ( ) {
42- listener . polygonStart ( ) ;
43- listener . lineStart ( ) ;
44- interpolate ( null , null , 1 , listener ) ;
45- listener . lineEnd ( ) ;
46- listener . polygonEnd ( ) ;
41+ sink . polygonStart ( ) ;
42+ sink . lineStart ( ) ;
43+ interpolate ( null , null , 1 , sink ) ;
44+ sink . lineEnd ( ) ;
45+ sink . polygonEnd ( ) ;
4746 }
4847 } ;
4948
50- function point ( λ , φ ) {
51- var point = rotate ( λ , φ ) ;
52- if ( pointVisible ( λ = point [ 0 ] , φ = point [ 1 ] ) ) listener . point ( λ , φ ) ;
53- }
54- function pointLine ( λ , φ ) {
55- var point = rotate ( λ , φ ) ;
56- line . point ( point [ 0 ] , point [ 1 ] ) ;
57- }
49+ function point ( λ , φ ) { if ( pointVisible ( λ , φ ) ) sink . point ( λ , φ ) ; }
50+ function pointLine ( λ , φ ) { line . point ( λ , φ ) ; }
5851 function lineStart ( ) { clip . point = pointLine ; line . lineStart ( ) ; }
5952 function lineEnd ( ) { clip . point = point ; line . lineEnd ( ) ; }
6053
6154 var segments ;
6255
63- var buffer = d3_geo_clipBufferListener ( ) ,
64- ringListener = clipLine ( buffer ) ,
56+ var buffer = d3_geo_clipBufferSink ( ) ,
57+ ringSink = clipLine ( buffer ) ,
6558 polygonStarted = false ,
6659 polygon ,
6760 ring ;
6861
6962 function pointRing ( λ , φ ) {
7063 ring . push ( [ λ , φ ] ) ;
71- var point = rotate ( λ , φ ) ;
72- ringListener . point ( point [ 0 ] , point [ 1 ] ) ;
64+ ringSink . point ( λ , φ ) ;
7365 }
7466
7567 function ringStart ( ) {
76- ringListener . lineStart ( ) ;
68+ ringSink . lineStart ( ) ;
7769 ring = [ ] ;
7870 }
7971
8072 function ringEnd ( ) {
8173 pointRing ( ring [ 0 ] [ 0 ] , ring [ 0 ] [ 1 ] ) ;
82- ringListener . lineEnd ( ) ;
74+ ringSink . lineEnd ( ) ;
8375
84- var clean = ringListener . clean ( ) ,
76+ var clean = ringSink . clean ( ) ,
8577 ringSegments = buffer . buffer ( ) ,
8678 segment ,
8779 n = ringSegments . length ;
@@ -99,16 +91,16 @@ function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
9991 i = - 1 ,
10092 point ;
10193 if ( n > 0 ) {
102- if ( ! polygonStarted ) listener . polygonStart ( ) , polygonStarted = true ;
103- listener . lineStart ( ) ;
104- while ( ++ i < n ) listener . point ( ( point = segment [ i ] ) [ 0 ] , point [ 1 ] ) ;
105- listener . lineEnd ( ) ;
94+ if ( ! polygonStarted ) sink . polygonStart ( ) , polygonStarted = true ;
95+ sink . lineStart ( ) ;
96+ while ( ++ i < n ) sink . point ( ( point = segment [ i ] ) [ 0 ] , point [ 1 ] ) ;
97+ sink . lineEnd ( ) ;
10698 }
10799 return ;
108100 }
109101
110102 // Rejoin connected segments.
111- // TODO reuse bufferListener .rejoin()?
103+ // TODO reuse bufferSink .rejoin()?
112104 if ( n > 1 && clean & 2 ) ringSegments . push ( ringSegments . pop ( ) . concat ( ringSegments . shift ( ) ) ) ;
113105
114106 segments . push ( ringSegments . filter ( d3_geo_clipSegmentLength1 ) ) ;
@@ -122,7 +114,7 @@ function d3_geo_clipSegmentLength1(segment) {
122114 return segment . length > 1 ;
123115}
124116
125- function d3_geo_clipBufferListener ( ) {
117+ function d3_geo_clipBufferSink ( ) {
126118 var lines = [ ] ,
127119 line ;
128120 return {
0 commit comments