Skip to content

Commit aec19e0

Browse files
authored
Merge pull request #4174 from outofambit/bugfix/circle-fes-msg
decouple param validation from ellipse and rect drawing
2 parents 74e8d1e + febf122 commit aec19e0

File tree

1 file changed

+60
-50
lines changed

1 file changed

+60
-50
lines changed

Diff for: src/core/shape/2d_primitives.js

+60-50
Original file line numberDiff line numberDiff line change
@@ -243,29 +243,7 @@ p5.prototype.arc = function(x, y, w, h, start, stop, mode, detail) {
243243
*/
244244
p5.prototype.ellipse = function(x, y, w, h, detailX) {
245245
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);
269247
};
270248

271249
/**
@@ -292,10 +270,37 @@ p5.prototype.ellipse = function(x, y, w, h, detailX) {
292270
* white circle with black outline in mid of canvas that is 55x55.
293271
*/
294272
p5.prototype.circle = function() {
273+
p5._validateParameters('circle', arguments);
295274
const args = Array.prototype.slice.call(arguments, 0, 2);
296275
args.push(arguments[2]);
297276
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;
299304
};
300305

301306
/**
@@ -558,31 +563,7 @@ p5.prototype.quad = function(...args) {
558563
*/
559564
p5.prototype.rect = function() {
560565
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);
586567
};
587568

588569
/**
@@ -636,7 +617,36 @@ p5.prototype.rect = function() {
636617
* 55x55 white square with black outline and rounded edges of different radii.
637618
*/
638619
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;
640650
};
641651

642652
/**

0 commit comments

Comments
 (0)