@@ -287,10 +287,10 @@ class Renderer2D extends Renderer {
287287 this . clipPath . closePath ( ) ;
288288 } else {
289289 if ( this . states . fillColor ) {
290- this . drawingContext . fill ( visitor . path ) ;
290+ this . drawingContext . fill ( visitor . fillPath || visitor . path ) ;
291291 }
292292 if ( this . states . strokeColor ) {
293- this . drawingContext . stroke ( visitor . path ) ;
293+ this . drawingContext . stroke ( visitor . strokePath || visitor . path ) ;
294294 }
295295 }
296296 }
@@ -672,106 +672,35 @@ class Renderer2D extends Renderer {
672672 * start <= stop < start + TWO_PI
673673 */
674674 arc ( x , y , w , h , start , stop , mode ) {
675- const ctx = this . drawingContext ;
676- const rx = w / 2.0 ;
677- const ry = h / 2.0 ;
678- const epsilon = 0.00001 ; // Smallest visible angle on displays up to 4K.
679- let arcToDraw = 0 ;
680- const curves = [ ] ;
681-
682- const centerX = x + w / 2 ,
683- centerY = y + h / 2 ,
684- radiusX = w / 2 ,
685- radiusY = h / 2 ;
686- if ( this . _clipping ) {
687- const tempPath = new Path2D ( ) ;
688- tempPath . ellipse ( centerX , centerY , radiusX , radiusY , 0 , start , stop ) ;
689- const currentTransform = this . drawingContext . getTransform ( ) ;
690- const clipBaseTransform = this . _clipBaseTransform . inverse ( ) ;
691- const relativeTransform = clipBaseTransform . multiply ( currentTransform ) ;
692- this . clipPath . addPath ( tempPath , relativeTransform ) ;
693- return this ;
694- }
695- // Determines whether to add a line to the center, which should be done
696- // when the mode is PIE or default; as well as when the start and end
697- // angles do not form a full circle.
698- const createPieSlice = ! (
699- mode === constants . CHORD ||
700- mode === constants . OPEN ||
701- ( stop - start ) % constants . TWO_PI === 0
675+ const shape = new p5 . Shape ( { position : new p5 . Vector ( 0 , 0 ) } ) ;
676+ shape . beginShape ( ) ;
677+ shape . arcPrimitive (
678+ x ,
679+ y ,
680+ w ,
681+ h ,
682+ start ,
683+ stop ,
684+ mode
702685 ) ;
703-
704- // Fill curves
705- if ( this . states . fillColor ) {
706- ctx . beginPath ( ) ;
707- ctx . ellipse ( centerX , centerY , radiusX , radiusY , 0 , start , stop ) ;
708- if ( createPieSlice ) ctx . lineTo ( centerX , centerY ) ;
709- ctx . closePath ( ) ;
710- ctx . fill ( ) ;
711- }
712-
713- // Stroke curves
714- if ( this . states . strokeColor ) {
715- ctx . beginPath ( ) ;
716- ctx . ellipse ( centerX , centerY , radiusX , radiusY , 0 , start , stop ) ;
717-
718- if ( mode === constants . PIE && createPieSlice ) {
719- // In PIE mode, stroke is added to the center and back to path,
720- // unless the pie forms a complete ellipse (see: createPieSlice)
721- ctx . lineTo ( centerX , centerY ) ;
722- }
723-
724- if ( mode === constants . PIE || mode === constants . CHORD ) {
725- // Stroke connects back to path begin for both PIE and CHORD
726- ctx . closePath ( ) ;
727- }
728- ctx . stroke ( ) ;
729- }
686+ shape . endShape ( ) ;
687+ this . drawShape ( shape ) ;
730688
731689 return this ;
732690
733691 }
734692
735693 ellipse ( args ) {
736- const ctx = this . drawingContext ;
737- const doFill = ! ! this . states . fillColor ,
738- doStroke = this . states . strokeColor ;
739694 const x = parseFloat ( args [ 0 ] ) ,
740695 y = parseFloat ( args [ 1 ] ) ,
741696 w = parseFloat ( args [ 2 ] ) ,
742697 h = parseFloat ( args [ 3 ] ) ;
743- if ( doFill && ! doStroke ) {
744- if ( this . _getFill ( ) === styleEmpty ) {
745- return this ;
746- }
747- } else if ( ! doFill && doStroke ) {
748- if ( this . _getStroke ( ) === styleEmpty ) {
749- return this ;
750- }
751- }
752- const centerX = x + w / 2 ,
753- centerY = y + h / 2 ,
754- radiusX = w / 2 ,
755- radiusY = h / 2 ;
756- if ( this . _clipping ) {
757- const tempPath = new Path2D ( ) ;
758- tempPath . ellipse ( centerX , centerY , radiusX , radiusY , 0 , 0 , 2 * Math . PI ) ;
759- const currentTransform = this . drawingContext . getTransform ( ) ;
760- const clipBaseTransform = this . _clipBaseTransform . inverse ( ) ;
761- const relativeTransform = clipBaseTransform . multiply ( currentTransform ) ;
762- this . clipPath . addPath ( tempPath , relativeTransform ) ;
763- return this ;
764- }
765- ctx . beginPath ( ) ;
766- ctx . ellipse ( centerX , centerY , radiusX , radiusY , 0 , 0 , 2 * Math . PI ) ;
767- ctx . closePath ( ) ;
768- if ( doFill ) {
769- ctx . fill ( ) ;
770- }
771- if ( doStroke ) {
772- ctx . stroke ( ) ;
773- }
774698
699+ const shape = new p5 . Shape ( { position : new p5 . Vector ( 0 , 0 ) } ) ;
700+ shape . beginShape ( ) ;
701+ shape . ellipsePrimitive ( x , y , w , h ) ;
702+ shape . endShape ( ) ;
703+ this . drawShape ( shape ) ;
775704 return this ;
776705 }
777706
0 commit comments