@@ -221,6 +221,7 @@ PIXI.Graphics.prototype.lineTo = function(x, y)
221221 * Calculate the points for a quadratic bezier curve.
222222 * Based on : https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c
223223 *
224+ * @method quadraticCurveTo
224225 * @param {number } cpX Control point x
225226 * @param {number } cpY Control point y
226227 * @param {number } toX Destination point x
@@ -229,13 +230,15 @@ PIXI.Graphics.prototype.lineTo = function(x, y)
229230 */
230231PIXI . Graphics . prototype . quadraticCurveTo = function ( cpX , cpY , toX , toY )
231232{
232- // this.currentPath.points.push(toX, toY)
233- //return;
233+ if ( this . currentPath . points . length === 0 ) this . moveTo ( 0 , 0 ) ;
234+
234235 var xa ,
235236 ya ,
236237 n = 20 ,
237238 points = this . currentPath . points ;
239+ if ( points . length === 0 ) this . moveTo ( 0 , 0 ) ;
238240
241+
239242 var fromX = points [ points . length - 2 ] ;
240243 var fromY = points [ points . length - 1 ] ;
241244
@@ -260,6 +263,7 @@ PIXI.Graphics.prototype.quadraticCurveTo = function(cpX, cpY, toX, toY)
260263/**
261264 * Calculate the points for a bezier curve.
262265 *
266+ * @method bezierCurveTo
263267 * @param {number } cpX Control point x
264268 * @param {number } cpY Control point y
265269 * @param {number } cpX2 Second Control point x
@@ -270,6 +274,8 @@ PIXI.Graphics.prototype.quadraticCurveTo = function(cpX, cpY, toX, toY)
270274 */
271275PIXI . Graphics . prototype . bezierCurveTo = function ( cpX , cpY , cpX2 , cpY2 , toX , toY )
272276{
277+ if ( this . currentPath . points . length === 0 ) this . moveTo ( 0 , 0 ) ;
278+
273279 var n = 20 ,
274280 dt ,
275281 dt2 ,
@@ -305,17 +311,24 @@ PIXI.Graphics.prototype.bezierCurveTo = function(cpX, cpY, cpX2, cpY2, toX, toY)
305311} ;
306312
307313/*
308- * arcTo()
309- *
314+ * the arcTo() method creates an arc/curve between two tangents on the canvas.
315+ *
310316 * "borrowed" from https://code.google.com/p/fxcanvas/ - thanks google!
317+ *
318+ * @method arcTo
319+ * @param {number } x1 The x-coordinate of the beginning of the arc
320+ * @param {number } y1 The y-coordinate of the beginning of the arc
321+ * @param {number } x2 The x-coordinate of the end of the arc
322+ * @param {number } y2 The y-coordinate of the end of the arc
323+ * @param {number } radius The radius of the arc
324+ * @return {PIXI.Graphics }
311325 */
312326PIXI . Graphics . prototype . arcTo = function ( x1 , y1 , x2 , y2 , radius )
313327{
314328 // check that path contains subpaths
315- //if (path.commands. length == 0)
316- // moveTo(x1, y1);
329+ if ( this . currentPath . points . length === 0 ) this . moveTo ( x1 , y1 ) ;
330+
317331 var points = this . currentPath . points ;
318-
319332 var fromX = points [ points . length - 2 ] ;
320333 var fromY = points [ points . length - 1 ] ;
321334
@@ -358,24 +371,30 @@ PIXI.Graphics.prototype.arcTo = function(x1, y1, x2, y2, radius)
358371 return this ;
359372} ;
360373
361- /*
362- * Arc init! TODO add docs
374+ /**
375+ * The arc() method creates an arc/curve (used to create circles, or parts of circles).
376+ *
377+ * @method arc
378+ * @param {number } cx The x-coordinate of the center of the circle
379+ * @param {number } cy The y-coordinate of the center of the circle
380+ * @param {number } radius The radius of the circle
381+ * @param {number } startAngle The starting angle, in radians (0 is at the 3 o'clock position of the arc's circle)
382+ * @param {number } endAngle The ending angle, in radians
383+ * @param {number } anticlockwise Optional. Specifies whether the drawing should be counterclockwise or clockwise. False is default, and indicates clockwise, while true indicates counter-clockwise.
384+ * @return {PIXI.Graphics }
363385 */
364386PIXI . Graphics . prototype . arc = function ( cx , cy , radius , startAngle , endAngle , anticlockwise )
365387{
366388 var startX = cx + Math . cos ( startAngle ) * radius ;
367389 var startY = cy + Math . sin ( startAngle ) * radius ;
368-
369- // check that path contains subpaths
370- // if (path.commands.length == 0)
371- // this.moveTo(startX, startY);
372- // else
373- var points = this . currentPath . points ;
374390
375- var fromX = points [ points . length - 2 ] ;
376- var fromY = points [ points . length - 1 ] ;
391+ var points = this . currentPath . points ;
377392
378- if ( fromX !== startX || fromY !== startY ) points . push ( startX , startY ) ;
393+ if ( points . length !== 0 && points [ points . length - 2 ] !== startX || points [ points . length - 1 ] !== startY )
394+ {
395+ this . moveTo ( startX , startY ) ;
396+ points = this . currentPath . points ;
397+ }
379398
380399 if ( startAngle === endAngle ) return this ;
381400
@@ -399,12 +418,15 @@ PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, ant
399418 var cTheta = Math . cos ( theta ) ;
400419 var sTheta = Math . sin ( theta ) ;
401420
402- var remainder = ( segs % 1 ) / segs ;
421+ var segMinus = segs - 1 ;
403422
404- for ( var i = 0 ; i <= segs ; i ++ )
423+ var remainder = ( segMinus % 1 ) / segMinus ;
424+
425+ for ( var i = 0 ; i <= segMinus ; i ++ )
405426 {
406427 var real = i + remainder * i ;
407428
429+
408430 var angle = ( ( theta ) + startAngle + ( theta2 * real ) ) ;
409431
410432 var c = Math . cos ( angle ) ;
0 commit comments