@@ -705,96 +705,32 @@ class Renderer2D extends Renderer {
705705 }
706706
707707 line ( x1 , y1 , x2 , y2 ) {
708- const ctx = this . drawingContext ;
709- if ( ! this . states . strokeColor ) {
710- return this ;
711- } else if ( this . _getStroke ( ) === styleEmpty ) {
712- return this ;
713- }
714- if ( this . _clipping ) {
715- const tempPath = new Path2D ( ) ;
716- tempPath . moveTo ( x1 , y1 ) ;
717- tempPath . lineTo ( x2 , y2 ) ;
718- const currentTransform = this . drawingContext . getTransform ( ) ;
719- const clipBaseTransform = this . _clipBaseTransform . inverse ( ) ;
720- const relativeTransform = clipBaseTransform . multiply ( currentTransform ) ;
721- this . clipPath . addPath ( tempPath , relativeTransform ) ;
722- return this ;
723- }
724- ctx . beginPath ( ) ;
725- ctx . moveTo ( x1 , y1 ) ;
726- ctx . lineTo ( x2 , y2 ) ;
727- ctx . stroke ( ) ;
708+ const shape = new p5 . Shape ( { position : new p5 . Vector ( 0 , 0 ) } ) ;
709+ shape . beginShape ( ) ;
710+ shape . line ( x1 , y1 , x2 , y2 ) ;
711+ shape . endShape ( ) ;
712+ this . drawShape ( shape ) ;
728713
729714 return this ;
730715 }
731716
732717 point ( x , y ) {
733- const ctx = this . drawingContext ;
734- if ( ! this . states . strokeColor ) {
735- return this ;
736- } else if ( this . _getStroke ( ) === styleEmpty ) {
737- return this ;
738- }
739- const s = this . _getStroke ( ) ;
740- const f = this . _getFill ( ) ;
741- if ( this . _clipping ) {
742- const tempPath = new Path2D ( ) ;
743- const drawingContextWidth = this . drawingContext . lineWidth ;
744- tempPath . arc ( x , y , drawingContextWidth / 2 , 0 , constants . TWO_PI ) ;
745- const currentTransform = this . drawingContext . getTransform ( ) ;
746- const clipBaseTransform = this . _clipBaseTransform . inverse ( ) ;
747- const relativeTransform = clipBaseTransform . multiply ( currentTransform ) ;
748- this . clipPath . addPath ( tempPath , relativeTransform ) ;
749- return this ;
750- }
751- this . _setFill ( s ) ;
752- ctx . beginPath ( ) ;
753- ctx . arc ( x , y , ctx . lineWidth / 2 , 0 , constants . TWO_PI , false ) ;
754- ctx . fill ( ) ;
755- this . _setFill ( f ) ;
718+ const shape = new p5 . Shape ( { position : new p5 . Vector ( 0 , 0 ) } ) ;
719+ shape . beginShape ( ) ;
720+ shape . point ( x , y ) ;
721+ shape . endShape ( ) ;
722+ this . drawShape ( shape ) ;
756723
757724 return this ;
758725 }
759726
760727 quad ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) {
761- const ctx = this . drawingContext ;
762- const doFill = ! ! this . states . fillColor ,
763- doStroke = this . states . strokeColor ;
764- if ( doFill && ! doStroke ) {
765- if ( this . _getFill ( ) === styleEmpty ) {
766- return this ;
767- }
768- } else if ( ! doFill && doStroke ) {
769- if ( this . _getStroke ( ) === styleEmpty ) {
770- return this ;
771- }
772- }
773- if ( this . _clipping ) {
774- const tempPath = new Path2D ( ) ;
775- tempPath . moveTo ( x1 , y1 ) ;
776- tempPath . lineTo ( x2 , y2 ) ;
777- tempPath . lineTo ( x3 , y3 ) ;
778- tempPath . lineTo ( x4 , y4 ) ;
779- tempPath . closePath ( ) ;
780- const currentTransform = this . drawingContext . getTransform ( ) ;
781- const clipBaseTransform = this . _clipBaseTransform . inverse ( ) ;
782- const relativeTransform = clipBaseTransform . multiply ( currentTransform ) ;
783- this . clipPath . addPath ( tempPath , relativeTransform ) ;
784- return this ;
785- }
786- ctx . beginPath ( ) ;
787- ctx . moveTo ( x1 , y1 ) ;
788- ctx . lineTo ( x2 , y2 ) ;
789- ctx . lineTo ( x3 , y3 ) ;
790- ctx . lineTo ( x4 , y4 ) ;
791- ctx . closePath ( ) ;
792- if ( doFill ) {
793- ctx . fill ( ) ;
794- }
795- if ( doStroke ) {
796- ctx . stroke ( ) ;
797- }
728+ const shape = new p5 . Shape ( { position : new p5 . Vector ( 0 , 0 ) } ) ;
729+ shape . beginShape ( ) ;
730+ shape . quad ( x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4 ) ;
731+ shape . endShape ( ) ;
732+ this . drawShape ( shape ) ;
733+
798734 return this ;
799735 }
800736
@@ -807,134 +743,29 @@ class Renderer2D extends Renderer {
807743 let tr = args [ 5 ] ;
808744 let br = args [ 6 ] ;
809745 let bl = args [ 7 ] ;
810- const ctx = this . drawingContext ;
811- const doFill = ! ! this . states . fillColor ,
812- doStroke = this . states . strokeColor ;
813- if ( doFill && ! doStroke ) {
814- if ( this . _getFill ( ) === styleEmpty ) {
815- return this ;
816- }
817- } else if ( ! doFill && doStroke ) {
818- if ( this . _getStroke ( ) === styleEmpty ) {
819- return this ;
820- }
821- }
822- if ( this . _clipping ) {
823- const tempPath = new Path2D ( ) ;
824- if ( typeof tl === 'undefined' ) {
825- tempPath . rect ( x , y , w , h ) ;
826- } else {
827- tempPath . roundRect ( x , y , w , h , [ tl , tr , br , bl ] ) ;
828- }
829- const currentTransform = this . drawingContext . getTransform ( ) ;
830- const clipBaseTransform = this . _clipBaseTransform . inverse ( ) ;
831- const relativeTransform = clipBaseTransform . multiply ( currentTransform ) ;
832- this . clipPath . addPath ( tempPath , relativeTransform ) ;
833- return this ;
834- }
835- ctx . beginPath ( ) ;
836- if ( typeof tl === 'undefined' ) {
837- // No rounded corners
838- ctx . rect ( x , y , w , h ) ;
839- } else {
840- // At least one rounded corner
841- // Set defaults when not specified
842- if ( typeof tr === 'undefined' ) {
843- tr = tl ;
844- }
845- if ( typeof br === 'undefined' ) {
846- br = tr ;
847- }
848- if ( typeof bl === 'undefined' ) {
849- bl = br ;
850- }
851746
852- // corner rounding must always be positive
853- const absW = Math . abs ( w ) ;
854- const absH = Math . abs ( h ) ;
855- const hw = absW / 2 ;
856- const hh = absH / 2 ;
857-
858- // Clip radii
859- if ( absW < 2 * tl ) {
860- tl = hw ;
861- }
862- if ( absH < 2 * tl ) {
863- tl = hh ;
864- }
865- if ( absW < 2 * tr ) {
866- tr = hw ;
867- }
868- if ( absH < 2 * tr ) {
869- tr = hh ;
870- }
871- if ( absW < 2 * br ) {
872- br = hw ;
873- }
874- if ( absH < 2 * br ) {
875- br = hh ;
876- }
877- if ( absW < 2 * bl ) {
878- bl = hw ;
879- }
880- if ( absH < 2 * bl ) {
881- bl = hh ;
882- }
747+ const shape = new p5 . Shape ( { position : new p5 . Vector ( 0 , 0 ) } ) ;
748+ shape . beginShape ( ) ;
749+ shape . rectPrimitive ( x , y , w , h , tl , tr , br , bl ) ;
750+ shape . endShape ( ) ;
751+ this . drawShape ( shape ) ;
883752
884- ctx . roundRect ( x , y , w , h , [ tl , tr , br , bl ] ) ;
885- }
886- if ( doFill ) {
887- ctx . fill ( ) ;
888- }
889- if ( doStroke ) {
890- ctx . stroke ( ) ;
891- }
892753 return this ;
893754 }
894755
895-
896756 triangle ( args ) {
897- const ctx = this . drawingContext ;
898- const doFill = ! ! this . states . fillColor ,
899- doStroke = this . states . strokeColor ;
900757 const x1 = args [ 0 ] ,
901758 y1 = args [ 1 ] ;
902759 const x2 = args [ 2 ] ,
903760 y2 = args [ 3 ] ;
904761 const x3 = args [ 4 ] ,
905762 y3 = args [ 5 ] ;
906- if ( doFill && ! doStroke ) {
907- if ( this . _getFill ( ) === styleEmpty ) {
908- return this ;
909- }
910- } else if ( ! doFill && doStroke ) {
911- if ( this . _getStroke ( ) === styleEmpty ) {
912- return this ;
913- }
914- }
915- if ( this . _clipping ) {
916- const tempPath = new Path2D ( ) ;
917- tempPath . moveTo ( x1 , y1 ) ;
918- tempPath . lineTo ( x2 , y2 ) ;
919- tempPath . lineTo ( x3 , y3 ) ;
920- tempPath . closePath ( ) ;
921- const currentTransform = this . drawingContext . getTransform ( ) ;
922- const clipBaseTransform = this . _clipBaseTransform . inverse ( ) ;
923- const relativeTransform = clipBaseTransform . multiply ( currentTransform ) ;
924- this . clipPath . addPath ( tempPath , relativeTransform ) ;
925- return this ;
926- }
927- ctx . beginPath ( ) ;
928- ctx . moveTo ( x1 , y1 ) ;
929- ctx . lineTo ( x2 , y2 ) ;
930- ctx . lineTo ( x3 , y3 ) ;
931- ctx . closePath ( ) ;
932- if ( doFill ) {
933- ctx . fill ( ) ;
934- }
935- if ( doStroke ) {
936- ctx . stroke ( ) ;
937- }
763+
764+ const shape = new p5 . Shape ( { position : new p5 . Vector ( 0 , 0 ) } ) ;
765+ shape . beginShape ( ) ;
766+ shape . triangle ( x1 , y1 , x2 , y2 , x3 , y3 ) ;
767+ shape . endShape ( ) ;
768+ this . drawShape ( shape ) ;
938769
939770 return this ;
940771 }
0 commit comments