Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src/core/shape/2d_primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,42 @@ p5.prototype._normalizeArcAngles = (
p5.prototype.arc = function(x, y, w, h, start, stop, mode, detail) {
p5._validateParameters('arc', arguments);

// Validate that numeric parameters are finite numbers
if (!Number.isFinite(x)) {
console.warn('arc(): x parameter should be a finite number. Received: ' + x);
return this;
}
if (!Number.isFinite(y)) {
console.warn('arc(): y parameter should be a finite number. Received: ' + y);
return this;
}
if (!Number.isFinite(w)) {
console.warn('arc(): w parameter should be a finite number. Received: ' + w);
return this;
}
if (!Number.isFinite(h)) {
console.warn('arc(): h parameter should be a finite number. Received: ' + h);
return this;
}
if (!Number.isFinite(start)) {
console.warn('arc(): start angle should be a finite number. Received: ' + start);
return this;
}
if (!Number.isFinite(stop)) {
console.warn('arc(): stop angle should be a finite number. Received: ' + stop);
return this;
}

// Validate that width and height are positive
if (w <= 0) {
console.warn('arc(): width (w) should be a positive number. Received: ' + w);
return this;
}
if (h <= 0) {
console.warn('arc(): height (h) should be a positive number. Received: ' + h);
return this;
}

// if the current stroke and fill settings wouldn't result in something
// visible, exit immediately
if (!this._renderer._doStroke && !this._renderer._doFill) {
Expand All @@ -335,7 +371,7 @@ p5.prototype.arc = function(x, y, w, h, start, stop, mode, detail) {
if (angles.correspondToSamePoint) {
// If the arc starts and ends at (near enough) the same place, we choose to
// draw an ellipse instead. This is preferable to faking an ellipse (by
// making stop ever-so-slightly less than start + TWO_PI) because the ends
// making stop ever so-slightly less than start + TWO_PI) because the ends
// join up to each other rather than at a vertex at the centre (leaving
// an unwanted spike in the stroke/fill).
this._renderer.ellipse([vals.x, vals.y, vals.w, vals.h, detail]);
Expand Down Expand Up @@ -367,7 +403,6 @@ p5.prototype.arc = function(x, y, w, h, start, stop, mode, detail) {

return this;
};

/**
* Draws an ellipse (oval).
*
Expand Down