diff --git a/src/core/shape/2d_primitives.js b/src/core/shape/2d_primitives.js index e637fc3f29..6cd1d15a75 100644 --- a/src/core/shape/2d_primitives.js +++ b/src/core/shape/2d_primitives.js @@ -244,28 +244,7 @@ p5.prototype.arc = function(x, y, w, h, start, stop, mode, detail) { p5.prototype.ellipse = function(x, y, w, h, detailX) { p5._validateParameters('ellipse', arguments); - // if the current stroke and fill settings wouldn't result in something - // visible, exit immediately - if (!this._renderer._doStroke && !this._renderer._doFill) { - return this; - } - - // p5 supports negative width and heights for rects - if (w < 0) { - w = Math.abs(w); - } - - if (typeof h === 'undefined') { - // Duplicate 3rd argument if only 3 given. - h = w; - } else if (h < 0) { - h = Math.abs(h); - } - - const vals = canvas.modeAdjust(x, y, w, h, this._renderer._ellipseMode); - this._renderer.ellipse([vals.x, vals.y, vals.w, vals.h, detailX]); - - return this; + return this._renderEllipse(...arguments); }; /** @@ -292,10 +271,37 @@ p5.prototype.ellipse = function(x, y, w, h, detailX) { * white circle with black outline in mid of canvas that is 55x55. */ p5.prototype.circle = function() { + p5._validateParameters('circle', arguments); const args = Array.prototype.slice.call(arguments, 0, 2); args.push(arguments[2]); args.push(arguments[2]); - return this.ellipse(...args); + return this._renderEllipse(...args); +}; + +// internal method for drawing ellipses (without parameter validation) +p5.prototype._renderEllipse = function(x, y, w, h, detailX) { + // if the current stroke and fill settings wouldn't result in something + // visible, exit immediately + if (!this._renderer._doStroke && !this._renderer._doFill) { + return this; + } + + // p5 supports negative width and heights for rects + if (w < 0) { + w = Math.abs(w); + } + + if (typeof h === 'undefined') { + // Duplicate 3rd argument if only 3 given. + h = w; + } else if (h < 0) { + h = Math.abs(h); + } + + const vals = canvas.modeAdjust(x, y, w, h, this._renderer._ellipseMode); + this._renderer.ellipse([vals.x, vals.y, vals.w, vals.h, detailX]); + + return this; }; /**