@@ -243,29 +243,7 @@ p5.prototype.arc = function(x, y, w, h, start, stop, mode, detail) {
243
243
*/
244
244
p5 . prototype . ellipse = function ( x , y , w , h , detailX ) {
245
245
p5 . _validateParameters ( 'ellipse' , arguments ) ;
246
-
247
- // if the current stroke and fill settings wouldn't result in something
248
- // visible, exit immediately
249
- if ( ! this . _renderer . _doStroke && ! this . _renderer . _doFill ) {
250
- return this ;
251
- }
252
-
253
- // p5 supports negative width and heights for rects
254
- if ( w < 0 ) {
255
- w = Math . abs ( w ) ;
256
- }
257
-
258
- if ( typeof h === 'undefined' ) {
259
- // Duplicate 3rd argument if only 3 given.
260
- h = w ;
261
- } else if ( h < 0 ) {
262
- h = Math . abs ( h ) ;
263
- }
264
-
265
- const vals = canvas . modeAdjust ( x , y , w , h , this . _renderer . _ellipseMode ) ;
266
- this . _renderer . ellipse ( [ vals . x , vals . y , vals . w , vals . h , detailX ] ) ;
267
-
268
- return this ;
246
+ return this . _renderEllipse . apply ( this , arguments ) ;
269
247
} ;
270
248
271
249
/**
@@ -292,10 +270,37 @@ p5.prototype.ellipse = function(x, y, w, h, detailX) {
292
270
* white circle with black outline in mid of canvas that is 55x55.
293
271
*/
294
272
p5 . prototype . circle = function ( ) {
273
+ p5 . _validateParameters ( 'circle' , arguments ) ;
295
274
const args = Array . prototype . slice . call ( arguments , 0 , 2 ) ;
296
275
args . push ( arguments [ 2 ] ) ;
297
276
args . push ( arguments [ 2 ] ) ;
298
- return this . ellipse ( ...args ) ;
277
+ return this . _renderEllipse . apply ( this , args ) ;
278
+ } ;
279
+
280
+ // internal method for drawing ellipses (without parameter validation)
281
+ p5 . prototype . _renderEllipse = function ( x , y , w , h , detailX ) {
282
+ // if the current stroke and fill settings wouldn't result in something
283
+ // visible, exit immediately
284
+ if ( ! this . _renderer . _doStroke && ! this . _renderer . _doFill ) {
285
+ return this ;
286
+ }
287
+
288
+ // p5 supports negative width and heights for rects
289
+ if ( w < 0 ) {
290
+ w = Math . abs ( w ) ;
291
+ }
292
+
293
+ if ( typeof h === 'undefined' ) {
294
+ // Duplicate 3rd argument if only 3 given.
295
+ h = w ;
296
+ } else if ( h < 0 ) {
297
+ h = Math . abs ( h ) ;
298
+ }
299
+
300
+ const vals = canvas . modeAdjust ( x , y , w , h , this . _renderer . _ellipseMode ) ;
301
+ this . _renderer . ellipse ( [ vals . x , vals . y , vals . w , vals . h , detailX ] ) ;
302
+
303
+ return this ;
299
304
} ;
300
305
301
306
/**
@@ -558,31 +563,7 @@ p5.prototype.quad = function(...args) {
558
563
*/
559
564
p5 . prototype . rect = function ( ) {
560
565
p5 . _validateParameters ( 'rect' , arguments ) ;
561
-
562
- if ( this . _renderer . _doStroke || this . _renderer . _doFill ) {
563
- // duplicate width for height if only one value given
564
- if ( arguments . length === 3 ) {
565
- arguments [ 3 ] = arguments [ 2 ] ;
566
- }
567
-
568
- const vals = canvas . modeAdjust (
569
- arguments [ 0 ] ,
570
- arguments [ 1 ] ,
571
- arguments [ 2 ] ,
572
- arguments [ 3 ] ,
573
- this . _renderer . _rectMode
574
- ) ;
575
-
576
- const args = [ vals . x , vals . y , vals . w , vals . h ] ;
577
- // append the additional arguments (either cornder radii, or
578
- // segment details) to the argument list
579
- for ( let i = 4 ; i < arguments . length ; i ++ ) {
580
- args [ i ] = arguments [ i ] ;
581
- }
582
- this . _renderer . rect ( args ) ;
583
- }
584
-
585
- return this ;
566
+ return this . _renderRect . apply ( this , arguments ) ;
586
567
} ;
587
568
588
569
/**
@@ -636,7 +617,36 @@ p5.prototype.rect = function() {
636
617
* 55x55 white square with black outline and rounded edges of different radii.
637
618
*/
638
619
p5 . prototype . square = function ( x , y , s , tl , tr , br , bl ) {
639
- return this . rect ( x , y , s , s , tl , tr , br , bl ) ;
620
+ p5 . _validateParameters ( 'square' , arguments ) ;
621
+ return this . _renderRect . apply ( this , arguments ) ;
622
+ } ;
623
+
624
+ // internal method to have renderer draw a rectangle
625
+ p5 . prototype . _renderRect = function ( ) {
626
+ if ( this . _renderer . _doStroke || this . _renderer . _doFill ) {
627
+ // duplicate width for height if only one value given
628
+ if ( arguments . length === 3 ) {
629
+ arguments [ 3 ] = arguments [ 2 ] ;
630
+ }
631
+
632
+ const vals = canvas . modeAdjust (
633
+ arguments [ 0 ] ,
634
+ arguments [ 1 ] ,
635
+ arguments [ 2 ] ,
636
+ arguments [ 3 ] ,
637
+ this . _renderer . _rectMode
638
+ ) ;
639
+
640
+ const args = [ vals . x , vals . y , vals . w , vals . h ] ;
641
+ // append the additional arguments (either cornder radii, or
642
+ // segment details) to the argument list
643
+ for ( let i = 4 ; i < arguments . length ; i ++ ) {
644
+ args [ i ] = arguments [ i ] ;
645
+ }
646
+ this . _renderer . rect ( args ) ;
647
+ }
648
+
649
+ return this ;
640
650
} ;
641
651
642
652
/**
0 commit comments