@@ -157,14 +157,14 @@ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha)
157157 {
158158 // halfway through a line? start a new one!
159159 this . drawShape ( new PIXI . Polygon ( this . currentPath . shape . points . slice ( - 2 ) ) ) ;
160- return this ;
161160 }
162-
163- // otherwise its empty so lets just set the line properties
164- this . currentPath . lineWidth = this . lineWidth ;
165- this . currentPath . lineColor = this . lineColor ;
166- this . currentPath . lineAlpha = this . lineAlpha ;
167-
161+ else
162+ {
163+ // otherwise its empty so lets just set the line properties
164+ this . currentPath . lineWidth = this . lineWidth ;
165+ this . currentPath . lineColor = this . lineColor ;
166+ this . currentPath . lineAlpha = this . lineAlpha ;
167+ }
168168 }
169169
170170 return this ;
@@ -222,22 +222,30 @@ PIXI.Graphics.prototype.quadraticCurveTo = function(cpX, cpY, toX, toY)
222222{
223223 if ( this . currentPath )
224224 {
225- if ( this . currentPath . shape . points . length === 0 ) this . currentPath . shape . points = [ 0 , 0 ] ;
225+ if ( this . currentPath . shape . points . length === 0 )
226+ {
227+ this . currentPath . shape . points = [ 0 , 0 ] ;
228+ }
226229 }
227230 else
228231 {
229232 this . moveTo ( 0 , 0 ) ;
230233 }
231234
232- var xa , ya , n = 20 , points = this . currentPath . shape . points ;
235+ var xa ,
236+ ya ,
237+ n = 20 ,
238+ points = this . currentPath . shape . points ;
233239
234- if ( points . length === 0 ) this . moveTo ( 0 , 0 ) ;
240+ if ( points . length === 0 )
241+ {
242+ this . moveTo ( 0 , 0 ) ;
243+ }
235244
236245 var fromX = points [ points . length - 2 ] ;
237246 var fromY = points [ points . length - 1 ] ;
238247 var j = 0 ;
239-
240- for ( var i = 1 ; i <= n ; i ++ )
248+ for ( var i = 1 ; i <= n ; ++ i )
241249 {
242250 j = i / n ;
243251
@@ -269,20 +277,29 @@ PIXI.Graphics.prototype.bezierCurveTo = function(cpX, cpY, cpX2, cpY2, toX, toY)
269277{
270278 if ( this . currentPath )
271279 {
272- if ( this . currentPath . shape . points . length === 0 ) this . currentPath . shape . points = [ 0 , 0 ] ;
280+ if ( this . currentPath . shape . points . length === 0 )
281+ {
282+ this . currentPath . shape . points = [ 0 , 0 ] ;
283+ }
273284 }
274285 else
275286 {
276287 this . moveTo ( 0 , 0 ) ;
277288 }
278289
279- var n = 20 , dt , dt2 , dt3 , t2 , t3 , points = this . currentPath . shape . points ;
290+ var n = 20 ,
291+ dt ,
292+ dt2 ,
293+ dt3 ,
294+ t2 ,
295+ t3 ,
296+ points = this . currentPath . shape . points ;
280297
281298 var fromX = points [ points . length - 2 ] ;
282299 var fromY = points [ points . length - 1 ] ;
283300 var j = 0 ;
284301
285- for ( var i = 1 ; i <= n ; i ++ )
302+ for ( var i = 1 ; i <= n ; ++ i )
286303 {
287304 j = i / n ;
288305
@@ -329,14 +346,14 @@ PIXI.Graphics.prototype.arcTo = function(x1, y1, x2, y2, radius)
329346 this . moveTo ( x1 , y1 ) ;
330347 }
331348
332- var points = this . currentPath . shape . points ;
333- var fromX = points [ points . length - 2 ] ;
334- var fromY = points [ points . length - 1 ] ;
335- var a1 = fromY - y1 ;
336- var b1 = fromX - x1 ;
337- var a2 = y2 - y1 ;
338- var b2 = x2 - x1 ;
339- var mm = Math . abs ( a1 * b2 - b1 * a2 ) ;
349+ var points = this . currentPath . shape . points ,
350+ fromX = points [ points . length - 2 ] ,
351+ fromY = points [ points . length - 1 ] ,
352+ a1 = fromY - y1 ,
353+ b1 = fromX - x1 ,
354+ a2 = y2 - y1 ,
355+ b2 = x2 - x1 ,
356+ mm = Math . abs ( a1 * b2 - b1 * a2 ) ;
340357
341358 if ( mm < 1.0e-8 || radius === 0 )
342359 {
@@ -347,21 +364,21 @@ PIXI.Graphics.prototype.arcTo = function(x1, y1, x2, y2, radius)
347364 }
348365 else
349366 {
350- var dd = a1 * a1 + b1 * b1 ;
351- var cc = a2 * a2 + b2 * b2 ;
352- var tt = a1 * a2 + b1 * b2 ;
353- var k1 = radius * Math . sqrt ( dd ) / mm ;
354- var k2 = radius * Math . sqrt ( cc ) / mm ;
355- var j1 = k1 * tt / dd ;
356- var j2 = k2 * tt / cc ;
357- var cx = k1 * b2 + k2 * b1 ;
358- var cy = k1 * a2 + k2 * a1 ;
359- var px = b1 * ( k2 + j1 ) ;
360- var py = a1 * ( k2 + j1 ) ;
361- var qx = b2 * ( k1 + j2 ) ;
362- var qy = a2 * ( k1 + j2 ) ;
363- var startAngle = Math . atan2 ( py - cy , px - cx ) ;
364- var endAngle = Math . atan2 ( qy - cy , qx - cx ) ;
367+ var dd = a1 * a1 + b1 * b1 ,
368+ cc = a2 * a2 + b2 * b2 ,
369+ tt = a1 * a2 + b1 * b2 ,
370+ k1 = radius * Math . sqrt ( dd ) / mm ,
371+ k2 = radius * Math . sqrt ( cc ) / mm ,
372+ j1 = k1 * tt / dd ,
373+ j2 = k2 * tt / cc ,
374+ cx = k1 * b2 + k2 * b1 ,
375+ cy = k1 * a2 + k2 * a1 ,
376+ px = b1 * ( k2 + j1 ) ,
377+ py = a1 * ( k2 + j1 ) ,
378+ qx = b2 * ( k1 + j2 ) ,
379+ qy = a2 * ( k1 + j2 ) ,
380+ startAngle = Math . atan2 ( py - cy , px - cx ) ,
381+ endAngle = Math . atan2 ( qy - cy , qx - cx ) ;
365382
366383 this . arc ( cx + x1 , cy + y1 , radius , startAngle , endAngle , b1 * a2 > b2 * a1 ) ;
367384 }
@@ -407,8 +424,11 @@ PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, ant
407424 this . moveTo ( startX , startY ) ;
408425 points = this . currentPath . shape . points ;
409426 }
410-
411- if ( startAngle === endAngle ) return this ;
427+
428+ if ( startAngle === endAngle )
429+ {
430+ return this ;
431+ }
412432
413433 if ( ! anticlockwise && endAngle <= startAngle )
414434 {
@@ -420,9 +440,12 @@ PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, ant
420440 }
421441
422442 var sweep = anticlockwise ? ( startAngle - endAngle ) * - 1 : ( endAngle - startAngle ) ;
423- var segs = ( Math . abs ( sweep ) / ( Math . PI * 2 ) ) * 40 ;
443+ var segs = Math . ceil ( Math . abs ( sweep ) / ( Math . PI * 2 ) ) * 40 ;
424444
425- if ( sweep === 0 ) return this ;
445+ if ( sweep === 0 )
446+ {
447+ return this ;
448+ }
426449
427450 var theta = sweep / ( segs * 2 ) ;
428451 var theta2 = theta * 2 ;
@@ -569,9 +592,22 @@ PIXI.Graphics.prototype.drawEllipse = function(x, y, width, height)
569592 */
570593PIXI . Graphics . prototype . drawPolygon = function ( path )
571594{
572- if ( ! ( path instanceof Array ) ) path = Array . prototype . slice . call ( arguments ) ;
595+ // prevents an argument assignment deopt
596+ // see section 3.1: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
597+ var points = path ;
598+
599+ if ( ! Array . isArray ( points ) )
600+ {
601+ // prevents an argument leak deopt
602+ // see section 3.2: https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments
603+ points = new Array ( arguments . length ) ;
573604
574- this . drawShape ( new PIXI . Polygon ( path ) ) ;
605+ for ( var i = 0 ; i < points . length ; ++ i ) {
606+ points [ i ] = arguments [ i ] ;
607+ }
608+ }
609+
610+ this . drawShape ( new Phaser . Polygon ( points ) ) ;
575611
576612 return this ;
577613} ;
@@ -711,9 +747,17 @@ PIXI.Graphics.prototype._renderWebGL = function(renderSession)
711747*/
712748PIXI . Graphics . prototype . _renderCanvas = function ( renderSession )
713749{
714- // if the sprite is not visible or the alpha is 0 then no need to render this element
715- if ( this . visible === false || this . alpha === 0 || this . isMask === true ) return ;
716-
750+ if ( this . isMask === true )
751+ {
752+ return ;
753+ }
754+
755+ // if the tint has changed, set the graphics object to dirty.
756+ if ( this . _prevTint !== this . tint ) {
757+ this . dirty = true ;
758+ this . _prevTint = this . tint ;
759+ }
760+
717761 if ( this . _cacheAsBitmap )
718762 {
719763 if ( this . dirty || this . cachedSpriteDirty )
@@ -780,8 +824,14 @@ PIXI.Graphics.prototype._renderCanvas = function(renderSession)
780824 */
781825PIXI . Graphics . prototype . getBounds = function ( matrix )
782826{
783- // return an empty object if the item is a mask!
784- if ( this . isMask ) return PIXI . EmptyRectangle ;
827+ if ( ! this . _currentBounds )
828+ {
829+
830+ // return an empty object if the item is a mask!
831+ if ( ! this . renderable )
832+ {
833+ return PIXI . EmptyRectangle ;
834+ }
785835
786836 if ( this . dirty )
787837 {
@@ -848,7 +898,44 @@ PIXI.Graphics.prototype.getBounds = function(matrix)
848898 this . _bounds . y = minY ;
849899 this . _bounds . height = maxY - minY ;
850900
851- return this . _bounds ;
901+ this . _currentBounds = this . _bounds ;
902+ }
903+
904+ return this . _currentBounds ;
905+ } ;
906+
907+ /**
908+ * Tests if a point is inside this graphics object
909+ *
910+ * @param point {Point} the point to test
911+ * @return {boolean } the result of the test
912+ */
913+ PIXI . Graphics . prototype . containsPoint = function ( point )
914+ {
915+ this . worldTransform . applyInverse ( point , tempPoint ) ;
916+
917+ var graphicsData = this . graphicsData ;
918+
919+ for ( var i = 0 ; i < graphicsData . length ; i ++ )
920+ {
921+ var data = graphicsData [ i ] ;
922+
923+ if ( ! data . fill )
924+ {
925+ continue ;
926+ }
927+
928+ // only deal with fills..
929+ if ( data . shape )
930+ {
931+ if ( data . shape . contains ( tempPoint . x , tempPoint . y ) )
932+ {
933+ return true ;
934+ }
935+ }
936+ }
937+
938+ return false ;
852939} ;
853940
854941/**
@@ -1112,25 +1199,3 @@ Object.defineProperty(PIXI.Graphics.prototype, "cacheAsBitmap", {
11121199
11131200 }
11141201} ) ;
1115-
1116- /**
1117- * A GraphicsData object.
1118- *
1119- * @class GraphicsData
1120- * @constructor
1121- */
1122- PIXI . GraphicsData = function ( lineWidth , lineColor , lineAlpha , fillColor , fillAlpha , fill , shape )
1123- {
1124- this . lineWidth = lineWidth ;
1125- this . lineColor = lineColor ;
1126- this . lineAlpha = lineAlpha ;
1127- this . _lineTint = lineColor ;
1128-
1129- this . fillColor = fillColor ;
1130- this . fillAlpha = fillAlpha ;
1131- this . _fillTint = fillColor ;
1132- this . fill = fill ;
1133-
1134- this . shape = shape ;
1135- this . type = shape . type ;
1136- } ;
0 commit comments