From 1d5af24de19f9075c42eac0a3ef067529cf39ee6 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 08:54:50 -0400 Subject: [PATCH 01/16] Vector perf tests --- src/math/math.js | 10 ++++++++- src/math/p5.Vector.js | 50 +++++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/math/math.js b/src/math/math.js index 5a0c452c4b..0c0d15c870 100644 --- a/src/math/math.js +++ b/src/math/math.js @@ -92,7 +92,15 @@ function math(p5, fn) { * } */ fn.createVector = function (...args) { - return new p5.Vector(...args); + if (this._boundFromRadians) { + this._boundFromRadians = this._fromRadians.bind(this); + this._boundToRadians = this._toRadians.bind(this); + } + if (this instanceof p5) { + return new p5.Vector(this._boundFromRadians, this._boundToRadians, ...args); + } else { + return new p5.Vector(...args); + } }; /** diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 0bc152162b..17ae3162f3 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -5,6 +5,7 @@ import * as constants from '../core/constants'; /** + * @private * This function is used by binary vector operations to prioritize shorter vectors, * and to emit a warning when lengths do not match. */ @@ -12,6 +13,16 @@ const prioritizeSmallerDimension = function(currentVectorDimension, args) { return Math.min(currentVectorDimension, args.length); }; +/** + * @private + * In-place, shrinks an array to a dimension. + */ +const shrinkToDimension = function(arr, dim) { + while (arr.length > dim) { + arr.pop(); + } +} + class Vector { /** @@ -41,6 +52,15 @@ class Vector { */ values = []; + /** + * @private + * Check for disabled friendly errors. + * This is overridden in the addon function to check the p5 instance. + */ + static friendlyErrorsDisabled() { + return true; + } + // This is how it comes in with createVector() // This check if the first argument is a function constructor(...args) { @@ -59,11 +79,16 @@ class Vector { } this.values = []; - if(Array.isArray(args) && !args.every(v => typeof v === 'number' && Number.isFinite(v))){ - this._friendlyError( - 'Arguments contain non-finite numbers', - 'p5.Vector' - ); + if (!Vector.friendlyErrorsDisabled() && Array.isArray(args)) { + for (let i = 0; i < args.length; i++) { + const v = args[i]; + if (typeof v !== 'number' || !Number.isFinite(v)) { + this._friendlyError( + 'Arguments contain non-finite numbers', + 'p5.Vector' + ); + } + } } else { this.values = args; } @@ -759,11 +784,11 @@ class Vector { */ sub(...args) { const minDimension = prioritizeSmallerDimension(this.dimensions, args); + shrinkToDimension(this.values, minDimension); - this.values = this.values.reduce((acc, v, i) => { - if(i < minDimension) acc[i] = this.values[i] - args[i]; - return acc; - }, new Array(minDimension)); + for (let i = 0; i < this.values.length; i++) { + this.values[i] -= args[i]; + } return this; } @@ -1372,7 +1397,7 @@ class Vector { * The cross product is a vector that points straight out of the plane created * by two vectors. The cross product's magnitude is the area of the parallelogram * formed by the original two vectors. - * + * * The cross product is defined on 3-dimensional vectors, and will use the `x`, `y`, * and `z` components. This method should only be used with 3D vectors. * @@ -1986,7 +2011,7 @@ class Vector { if (this.dimensions < 2 || ( this._values instanceof Array && this._values.slice(2).some(v => v !== 0)) ) { - p5._friendlyError( + p5._friendlyError( 'p5.Vector.setHeading() only supports 2D vectors (z === 0). ' + 'For 3D or higher-dimensional vectors, use rotate() or another ' + 'appropriate method instead.', @@ -3617,6 +3642,9 @@ function vector(p5, fn) { p5.Vector = Vector; Vector.prototype._friendlyError = p5._friendlyError; + Vector.prototype.friendlyErrorsDisabled = function() { + return p5.disableFriendlyErrors; + }; /** * The x component of the vector From 4d7abf53026d215a665e1b33a32b857da062b4fe Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 09:08:52 -0400 Subject: [PATCH 02/16] Turn magSq into a loop too --- src/math/math.js | 2 +- src/math/p5.Vector.js | 10 ++++++---- src/math/patch-vector.js | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/math/math.js b/src/math/math.js index 0c0d15c870..2e4184962c 100644 --- a/src/math/math.js +++ b/src/math/math.js @@ -92,7 +92,7 @@ function math(p5, fn) { * } */ fn.createVector = function (...args) { - if (this._boundFromRadians) { + if (!this._boundFromRadians) { this._boundFromRadians = this._fromRadians.bind(this); this._boundToRadians = this._toRadians.bind(this); } diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 17ae3162f3..0dc0f9c1e4 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -1280,10 +1280,12 @@ class Vector { * } */ magSq() { - return this.values.reduce( - (sum, component) => sum + component * component, - 0 - ); + let sum = 0; + for (let i = 0; i < this.values.length; i++) { + const component = this.values[i]; + sum += component * component; + } + return sum; } /** diff --git a/src/math/patch-vector.js b/src/math/patch-vector.js index d615027d07..8bc549be98 100644 --- a/src/math/patch-vector.js +++ b/src/math/patch-vector.js @@ -43,13 +43,20 @@ export function _validatedVectorOperation(expectsSoloNumberArgument){ args = new Array(3).fill(args[0]); } - if(Array.isArray(args) && !args.every(v => typeof v === 'number' && Number.isFinite(v))){ - this._friendlyError( - 'Arguments contain non-finite numbers', - target.name - ); - return this; - }; + if (!Vector.friendlyErrorsDisabled() && Array.isArray(args)) { + for (let i = 0; i < args.length; i++) { + const v = args[i]; + if (typeof v !== 'number' || !Number.isFinite(v)) { + this._friendlyError( + 'Arguments contain non-finite numbers', + 'p5.Vector' + ); + } + return this; + } + } else { + this.values = args; + } return target.call(this, ...args); }; From e7e5dde1e8c7f3fa409d67125e802bfa4b194d94 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 09:12:40 -0400 Subject: [PATCH 03/16] Remove copy-and-pasted branch --- src/math/patch-vector.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/math/patch-vector.js b/src/math/patch-vector.js index 8bc549be98..1aa65d0705 100644 --- a/src/math/patch-vector.js +++ b/src/math/patch-vector.js @@ -54,8 +54,6 @@ export function _validatedVectorOperation(expectsSoloNumberArgument){ } return this; } - } else { - this.values = args; } return target.call(this, ...args); From e04141b17e03002c3c217e6c42e0a7eee2c427fb Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 09:20:16 -0400 Subject: [PATCH 04/16] Avoid a few new arrays --- src/math/p5.Vector.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 0dc0f9c1e4..593bfd114f 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -73,12 +73,11 @@ class Vector { if (typeof args[0] === 'function') { this.isPInst = true; - this._fromRadians = args[0]; - this._toRadians = args[1]; - args = args.slice(2); + this._fromRadians = args.shift(); + this._toRadians = args.shift(); } - this.values = []; + this.values = args; if (!Vector.friendlyErrorsDisabled() && Array.isArray(args)) { for (let i = 0; i < args.length; i++) { const v = args[i]; @@ -88,9 +87,9 @@ class Vector { 'p5.Vector' ); } + this.values = []; + break; } - } else { - this.values = args; } // This property is here where duck typing (checking if obj.isVector) needs From 0d04fbb54b1e2257c721a870e9f8016d80f486ab Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 09:41:03 -0400 Subject: [PATCH 05/16] Attempt alternate dist() implementation --- src/math/p5.Vector.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 593bfd114f..9397c0d690 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -1547,7 +1547,12 @@ class Vector { * } */ dist(v) { - return v.copy().sub(this).mag(); + const minDimension = prioritizeSmallerDimension(this.dimensions, v.values); + const components = this.values.slice(0, minDimension); + for (let i = 0; i < minDimension; i++) { + components[i] -= v.values[i]; + } + return Math.hypot(...components); } /** From 0bd50d2b7dbf10a25c19e52bd357c2d4417978c9 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 09:48:30 -0400 Subject: [PATCH 06/16] Attempt to short circuit complex code when FES disabled --- src/core/friendly_errors/param_validator.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/friendly_errors/param_validator.js b/src/core/friendly_errors/param_validator.js index ed822db3cf..6277304168 100644 --- a/src/core/friendly_errors/param_validator.js +++ b/src/core/friendly_errors/param_validator.js @@ -606,6 +606,9 @@ function validateParams(p5, fn, lifecycles) { function(target, { kind, name }){ if(kind === 'method'){ return function(...args){ + if (p5.disableFriendlyErrors) { + return target.apply(this, args); + } const wasInternalCall = this._isUserCall; this._isUserCall = true; try { From a84c47918b9d6af581a0d5b5f2218fb0be987c12 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 09:52:36 -0400 Subject: [PATCH 07/16] Attempt a dist() without a new array --- src/math/p5.Vector.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 9397c0d690..67aff10978 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -1548,11 +1548,12 @@ class Vector { */ dist(v) { const minDimension = prioritizeSmallerDimension(this.dimensions, v.values); - const components = this.values.slice(0, minDimension); + let sum = 0; for (let i = 0; i < minDimension; i++) { - components[i] -= v.values[i]; + const component = this.values[i] - v.values[i]; + sum += component * component; } - return Math.hypot(...components); + return Math.sqrt(sum); } /** From ebff602aabf22a322f82f317292a4cd311d798f4 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 10:03:52 -0400 Subject: [PATCH 08/16] Remove intermediate arrays in more methods --- src/math/p5.Vector.js | 108 ++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 66 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 67aff10978..4f295bc1f2 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -527,11 +527,11 @@ class Vector { */ add(...args) { const minDimension = prioritizeSmallerDimension(this.dimensions, args); + shrinkToDimension(this.values, minDimension); - this.values = this.values.reduce((acc, v, i) => { - if(i < minDimension) acc[i] = this.values[i] + Number(args[i]); - return acc; - }, new Array(minDimension)); + for (let i = 0; i < this.values.length; i++) { + this.values[i] += args[i]; + } return this; } @@ -651,10 +651,11 @@ class Vector { */ rem(...args) { const minDimension = prioritizeSmallerDimension(this.dimensions, args); + shrinkToDimension(this.values, minDimension); - this.values = Array.from({ length: minDimension }, (_, i) => { - return (args[i] > 0) ? this.values[i] % args[i] : this.values[i]; - }); + for (let i = 0; i < this.values.length; i++) { + this.values[i] = this.values[i] % args[i]; + } return this; } @@ -971,50 +972,12 @@ class Vector { */ mult(...args) { const minDimension = prioritizeSmallerDimension(this.dimensions, args); + shrinkToDimension(this.values, minDimension); + + for (let i = 0; i < this.values.length; i++) { + this.values[i] *= args[i]; + } - this.values = this.values.reduce((acc, v, i) => { - if(i < minDimension) acc[i] = this.values[i] * args[i]; - return acc; - }, new Array(minDimension)); - - // if (args.length === 1 && args[0] instanceof Vector) { - // const v = args[0]; - // const maxLen = Math.min(this.values.length, v.values.length); - // for (let i = 0; i < maxLen; i++) { - // if (Number.isFinite(v.values[i]) && typeof v.values[i] === 'number') { - // if(!this.values[i]) this.values[i] = 0; - // this.values[i] *= v.values[i]; - // } else { - // console.warn( - // 'p5.Vector.prototype.mult:', - // 'v contains components that are either undefined or not finite numbers' - // ); - // return this; - // } - // } - // } else if (args.length === 1 && Array.isArray(args[0])) { - // const arr = args[0]; - // const maxLen = Math.min(this.values.length, arr.length); - // for (let i = 0; i < maxLen; i++) { - // if (Number.isFinite(arr[i]) && typeof arr[i] === 'number') { - // this.values[i] *= arr[i]; - // } else { - // console.warn( - // 'p5.Vector.prototype.mult:', - // 'arr contains elements that are either undefined or not finite numbers' - // ); - // return this; - // } - // } - // } else if ( - // args.length === 1 && - // typeof args[0] === 'number' && - // Number.isFinite(args[0]) - // ) { - // for (let i = 0; i < this.values.length; i++) { - // this.values[i] *= args[0]; - // } - // } return this; } @@ -1198,19 +1161,23 @@ class Vector { */ div(...args) { const minDimension = prioritizeSmallerDimension(this.dimensions, args); + shrinkToDimension(this.values, minDimension); - if(!args.every(v => typeof v === 'number' && v !== 0)){ - console.warn( - 'p5.Vector.prototype.div', - 'Arguments contain components that are 0' - ); - return this; - }; + if (!this.friendlyErrorsDisabled()) { + for (let i = 0; i < this.values.length; i++) { + if (typeof args[i] !== 'number' || args[i] === 0) { + console.warn( + 'p5.Vector.prototype.div', + 'Arguments contain components that are 0' + ); + return this; + } + } + } - this.values = this.values.reduce((acc, v, i) => { - if(i < minDimension) acc[i] = this.values[i] / args[i]; - return acc; - }, new Array(minDimension)); + for (let i = 0; i < this.values.length; i++) { + this.values[i] *= args[i]; + } return this; } @@ -1247,7 +1214,12 @@ class Vector { * } */ mag() { - return Math.sqrt(this.magSq()); + let sum = 0; + for (let i = 0; i < this.values.length; i++) { + const component = this.values[i]; + sum += component * component; + } + return Math.sqrt(sum); } /** @@ -1384,12 +1356,16 @@ class Vector { * @return {Number} */ dot(...args) { + let vals = args; if (args[0] instanceof Vector) { - return this.dot(...args[0].values); + vals = args[0].values; } - return this.values.reduce((sum, component, index) => { - return sum + component * (args[index] || 0); - }, 0); + const minDimension = prioritizeSmallerDimension(this.dimensions, args); + let sum = 0; + for (let i = 0; i < minDimension; i++) { + sum += this.values[i] * vals[i]; + } + return sum; } /** From 6fe93d7c94f016ac5894d166e63c6198d61efe91 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 10:15:22 -0400 Subject: [PATCH 09/16] Attempt always checking infinite/non-number values --- src/math/p5.Vector.js | 18 +++++++++++------- src/math/patch-vector.js | 14 ++++++++------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 4f295bc1f2..497386d21a 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -78,18 +78,22 @@ class Vector { } this.values = args; - if (!Vector.friendlyErrorsDisabled() && Array.isArray(args)) { + if (Array.isArray(args)) { for (let i = 0; i < args.length; i++) { const v = args[i]; if (typeof v !== 'number' || !Number.isFinite(v)) { - this._friendlyError( - 'Arguments contain non-finite numbers', - 'p5.Vector' - ); + if (!Vector.friendlyErrorsDisabled()) { + this._friendlyError( + 'Arguments contain non-finite numbers', + 'p5.Vector' + ); + } + this.values = []; + break; } - this.values = []; - break; } + } else { + this.values = []; } // This property is here where duck typing (checking if obj.isVector) needs diff --git a/src/math/patch-vector.js b/src/math/patch-vector.js index 1aa65d0705..621a79c813 100644 --- a/src/math/patch-vector.js +++ b/src/math/patch-vector.js @@ -43,16 +43,18 @@ export function _validatedVectorOperation(expectsSoloNumberArgument){ args = new Array(3).fill(args[0]); } - if (!Vector.friendlyErrorsDisabled() && Array.isArray(args)) { + if (Array.isArray(args)) { for (let i = 0; i < args.length; i++) { const v = args[i]; if (typeof v !== 'number' || !Number.isFinite(v)) { - this._friendlyError( - 'Arguments contain non-finite numbers', - 'p5.Vector' - ); + if (!Vector.friendlyErrorsDisabled()) { + this._friendlyError( + 'Arguments contain non-finite numbers', + 'p5.Vector' + ); + return this; + } } - return this; } } From a29ab484e1569f23fb133a46c9639f7fadb0301c Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 10:16:08 -0400 Subject: [PATCH 10/16] Also for div() --- src/math/p5.Vector.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 497386d21a..f188d1e3f3 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -1167,15 +1167,15 @@ class Vector { const minDimension = prioritizeSmallerDimension(this.dimensions, args); shrinkToDimension(this.values, minDimension); - if (!this.friendlyErrorsDisabled()) { - for (let i = 0; i < this.values.length; i++) { - if (typeof args[i] !== 'number' || args[i] === 0) { + for (let i = 0; i < this.values.length; i++) { + if (typeof args[i] !== 'number' || args[i] === 0) { + if (!this.friendlyErrorsDisabled()) { console.warn( 'p5.Vector.prototype.div', 'Arguments contain components that are 0' ); - return this; } + return this; } } From 0993f932346c9d95bdaba0755e215397fc3a1ef9 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 10:22:39 -0400 Subject: [PATCH 11/16] Update location of binding cache --- src/math/math.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/math/math.js b/src/math/math.js index 2e4184962c..71a6848e87 100644 --- a/src/math/math.js +++ b/src/math/math.js @@ -92,11 +92,11 @@ function math(p5, fn) { * } */ fn.createVector = function (...args) { - if (!this._boundFromRadians) { - this._boundFromRadians = this._fromRadians.bind(this); - this._boundToRadians = this._toRadians.bind(this); - } if (this instanceof p5) { + if (!this._boundFromRadians) { + this._boundFromRadians = this._fromRadians.bind(this); + this._boundToRadians = this._toRadians.bind(this); + } return new p5.Vector(this._boundFromRadians, this._boundToRadians, ...args); } else { return new p5.Vector(...args); From 4a6945b07e0c9963f0f283ee786b7adca1f360d6 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 10:38:58 -0400 Subject: [PATCH 12/16] Update how rem works to match --- src/math/p5.Vector.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index f188d1e3f3..1c912d4c93 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -643,7 +643,7 @@ class Vector { * let v2 = createVector(2, 3, 4); * * // Divide without modifying the original vectors. - * let v3 = p5.Vector.rem(v1, v2); + * let v3 = p5.Vector.rem(v1, v2); * * // Prints 'p5.Vector Object : [1, 1, 1]'. * print(v3.toString()); @@ -655,10 +655,24 @@ class Vector { */ rem(...args) { const minDimension = prioritizeSmallerDimension(this.dimensions, args); - shrinkToDimension(this.values, minDimension); + for (let i = 0; i < minDimension; i++) { + if (typeof args[i] !== 'number' || args[i] === 0) { + if (!this.friendlyErrorsDisabled()) { + console.warn( + 'p5.Vector.prototype.div', + 'Arguments contain components that are 0' + ); + } + return this; + } + } + + shrinkToDimension(this.values, minDimension); for (let i = 0; i < this.values.length; i++) { - this.values[i] = this.values[i] % args[i]; + if (args[i] > 0) { + this.values[i] = this.values[i] % args[i]; + } } return this; @@ -1165,9 +1179,8 @@ class Vector { */ div(...args) { const minDimension = prioritizeSmallerDimension(this.dimensions, args); - shrinkToDimension(this.values, minDimension); - for (let i = 0; i < this.values.length; i++) { + for (let i = 0; i < minDimension; i++) { if (typeof args[i] !== 'number' || args[i] === 0) { if (!this.friendlyErrorsDisabled()) { console.warn( @@ -1179,6 +1192,7 @@ class Vector { } } + shrinkToDimension(this.values, minDimension); for (let i = 0; i < this.values.length; i++) { this.values[i] *= args[i]; } From 606771a9f06948ca8e6bf80f1564fb638ad92ce8 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 10:42:25 -0400 Subject: [PATCH 13/16] dot() bug --- src/math/p5.Vector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 1c912d4c93..08cc101b60 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -1378,7 +1378,7 @@ class Vector { if (args[0] instanceof Vector) { vals = args[0].values; } - const minDimension = prioritizeSmallerDimension(this.dimensions, args); + const minDimension = prioritizeSmallerDimension(this.dimensions, vals); let sum = 0; for (let i = 0; i < minDimension; i++) { sum += this.values[i] * vals[i]; From 2f674197a2a5cb76950124b32a5919a0eac11952 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 10:50:44 -0400 Subject: [PATCH 14/16] Fix div --- src/math/p5.Vector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 08cc101b60..2f758ea9c3 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -1194,7 +1194,7 @@ class Vector { shrinkToDimension(this.values, minDimension); for (let i = 0; i < this.values.length; i++) { - this.values[i] *= args[i]; + this.values[i] /= args[i]; } return this; From f46887f4063dde471d2f84ec481388754ab5b645 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 10:56:20 -0400 Subject: [PATCH 15/16] Move early return out of friendly errors check --- src/math/patch-vector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/patch-vector.js b/src/math/patch-vector.js index 621a79c813..7b4aab4b5a 100644 --- a/src/math/patch-vector.js +++ b/src/math/patch-vector.js @@ -52,8 +52,8 @@ export function _validatedVectorOperation(expectsSoloNumberArgument){ 'Arguments contain non-finite numbers', 'p5.Vector' ); - return this; } + return this; } } } From 434d1c238f1e1a7f33909f9b15420490d3d025ce Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Tue, 19 May 2026 11:50:11 -0400 Subject: [PATCH 16/16] Handle rem() like the old code --- src/math/p5.Vector.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index 2f758ea9c3..33eddd1952 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -656,18 +656,6 @@ class Vector { rem(...args) { const minDimension = prioritizeSmallerDimension(this.dimensions, args); - for (let i = 0; i < minDimension; i++) { - if (typeof args[i] !== 'number' || args[i] === 0) { - if (!this.friendlyErrorsDisabled()) { - console.warn( - 'p5.Vector.prototype.div', - 'Arguments contain components that are 0' - ); - } - return this; - } - } - shrinkToDimension(this.values, minDimension); for (let i = 0; i < this.values.length; i++) { if (args[i] > 0) {