@@ -55,30 +55,28 @@ exports.fn = function(data, params) {
5555 path = relative2absolute ( EXTEND ( true , [ ] , pathElem . pathJS ) ) ,
5656 xs = [ ] ,
5757 ys = [ ] ,
58- controlPoint = [ 0 , 0 ] ,
58+ cubicСontrolPoint = [ 0 , 0 ] ,
59+ quadraticСontrolPoint = [ 0 , 0 ] ,
60+ lastPoint = [ 0 , 0 ] ,
5961 cubicBoundingBox ,
6062 quadraticBoundingBox ,
6163 i ,
62- segment ,
63- lastPoint = [ 0 , 0 ] ;
64+ segment ;
6465
6566 path . forEach ( function ( pathItem ) {
6667
6768 // ML
6869 if ( 'ML' . indexOf ( pathItem . instruction ) > - 1 ) {
6970
70- pathItem . data . forEach ( function ( d , i ) {
71-
71+ for ( i = 0 ; i < pathItem . data . length ; i ++ ) {
7272 if ( i % 2 === 0 ) {
73- xs . push ( d ) ;
73+ xs . push ( pathItem . data [ i ] ) ;
7474 } else {
75- ys . push ( d ) ;
75+ ys . push ( pathItem . data [ i ] ) ;
7676 }
77+ }
7778
78- } ) ;
79-
80- controlPoint = pathItem . data . slice ( - 2 ) ;
81- lastPoint = pathItem . data . slice ( - 2 ) ;
79+ lastPoint = cubicСontrolPoint = quadraticСontrolPoint = pathItem . data . slice ( - 2 ) ;
8280
8381 // H
8482 } else if ( pathItem . instruction === 'H' ) {
@@ -87,8 +85,7 @@ exports.fn = function(data, params) {
8785 xs . push ( d ) ;
8886 } ) ;
8987
90- controlPoint [ 0 ] = pathItem . data [ pathItem . data . length - 2 ] ;
91- lastPoint [ 0 ] = pathItem . data [ pathItem . data . length - 2 ] ;
88+ lastPoint [ 0 ] = cubicСontrolPoint [ 0 ] = quadraticСontrolPoint [ 0 ] = pathItem . data [ pathItem . data . length - 2 ] ;
9289
9390 // V
9491 } else if ( pathItem . instruction === 'V' ) {
@@ -97,8 +94,7 @@ exports.fn = function(data, params) {
9794 ys . push ( d ) ;
9895 } ) ;
9996
100- controlPoint [ 1 ] = pathItem . data [ pathItem . data . length - 1 ] ;
101- lastPoint [ 1 ] = pathItem . data [ pathItem . data . length - 1 ] ;
97+ lastPoint [ 1 ] = cubicСontrolPoint [ 1 ] = quadraticСontrolPoint [ 1 ] = pathItem . data [ pathItem . data . length - 1 ] ;
10298
10399 // C
104100 } else if ( pathItem . instruction === 'C' ) {
@@ -116,12 +112,12 @@ exports.fn = function(data, params) {
116112 ys . push ( cubicBoundingBox . maxy ) ;
117113
118114 // reflected control point for the next possible S
119- controlPoint = [
115+ cubicСontrolPoint = [
120116 2 * segment [ 4 ] - segment [ 2 ] ,
121117 2 * segment [ 5 ] - segment [ 3 ]
122118 ] ;
123119
124- lastPoint = pathItem . data . slice ( - 2 ) ;
120+ lastPoint = segment . slice ( - 2 ) ;
125121
126122 }
127123
@@ -132,7 +128,7 @@ exports.fn = function(data, params) {
132128
133129 segment = pathItem . data . slice ( i , i + 4 ) ;
134130
135- cubicBoundingBox = computeCubicBoundingBox . apply ( this , lastPoint . concat ( controlPoint ) . concat ( segment ) ) ;
131+ cubicBoundingBox = computeCubicBoundingBox . apply ( this , lastPoint . concat ( cubicСontrolPoint ) . concat ( segment ) ) ;
136132
137133 xs . push ( cubicBoundingBox . minx ) ;
138134 xs . push ( cubicBoundingBox . maxx ) ;
@@ -141,12 +137,12 @@ exports.fn = function(data, params) {
141137 ys . push ( cubicBoundingBox . maxy ) ;
142138
143139 // reflected control point for the next possible S
144- controlPoint = [
145- 2 * segment [ 2 ] - controlPoint [ 0 ] ,
146- 2 * segment [ 3 ] - controlPoint [ 1 ] ,
140+ cubicСontrolPoint = [
141+ 2 * segment [ 2 ] - cubicСontrolPoint [ 0 ] ,
142+ 2 * segment [ 3 ] - cubicСontrolPoint [ 1 ] ,
147143 ] ;
148144
149- lastPoint = pathItem . data . slice ( - 2 ) ;
145+ lastPoint = segment . slice ( - 2 ) ;
150146
151147 }
152148
@@ -166,12 +162,12 @@ exports.fn = function(data, params) {
166162 ys . push ( quadraticBoundingBox . maxy ) ;
167163
168164 // reflected control point for the next possible T
169- controlPoint = [
165+ quadraticСontrolPoint = [
170166 2 * segment [ 2 ] - segment [ 0 ] ,
171167 2 * segment [ 3 ] - segment [ 1 ]
172168 ] ;
173169
174- lastPoint = pathItem . data . slice ( - 2 ) ;
170+ lastPoint = segment . slice ( - 2 ) ;
175171
176172 }
177173
@@ -182,22 +178,21 @@ exports.fn = function(data, params) {
182178
183179 segment = pathItem . data . slice ( i , i + 2 ) ;
184180
185- quadraticBoundingBox = computeQuadraticBoundingBox . apply ( this , lastPoint . concat ( controlPoint ) . concat ( segment ) ) ;
181+ quadraticBoundingBox = computeQuadraticBoundingBox . apply ( this , lastPoint . concat ( quadraticСontrolPoint ) . concat ( segment ) ) ;
186182
187183 xs . push ( quadraticBoundingBox . minx ) ;
188184 xs . push ( quadraticBoundingBox . maxx ) ;
189185
190186 ys . push ( quadraticBoundingBox . miny ) ;
191187 ys . push ( quadraticBoundingBox . maxy ) ;
192188
193- // TODO: BUGGY
194189 // reflected control point for the next possible T
195- controlPoint = [
196- 2 * segment [ 0 ] - lastPoint [ 0 ] ,
197- 2 * segment [ 1 ] - lastPoint [ 1 ]
190+ quadraticСontrolPoint = [
191+ 2 * segment [ 0 ] - quadraticСontrolPoint [ 0 ] ,
192+ 2 * segment [ 1 ] - quadraticСontrolPoint [ 1 ]
198193 ] ;
199194
200- lastPoint = pathItem . data . slice ( - 2 ) ;
195+ lastPoint = segment . slice ( - 2 ) ;
201196
202197 }
203198
0 commit comments