From 6a5d0aa8de1e51d248a26f0d9258bae3a142d48b Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 23 Oct 2025 00:30:49 +0530 Subject: [PATCH 1/2] Mark array() method as deprecated with warning message --- src/math/p5.Vector.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index a9e76f0075..1c706fc447 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -2939,6 +2939,7 @@ class Vector { /** * Returns the vector's components as an array of numbers. * + * @deprecated * @return {Number[]} array with the vector's components. * @example *
@@ -2954,6 +2955,10 @@ class Vector { *
*/ array() { + p5._friendlyError( + 'array() is deprecated and will be removed in a future version of p5.js.', + 'p5.Vector.array' + ); return [this.x || 0, this.y || 0, this.z || 0]; } @@ -3784,11 +3789,16 @@ class Vector { * method to copy into your own vector. */ /** + * @deprecated * @static * @param {p5.Vector} v the vector to convert to an array * @return {Number[]} an Array with the 3 values */ static array(v) { + p5._friendlyError( + 'array() is deprecated and will be removed in a future version of p5.js.', + 'p5.Vector.array' + ); return v.array(); } From 54eb074aeaa1c5c7992f0e49c8df4c66d92d8576 Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 23 Oct 2025 04:21:37 +0530 Subject: [PATCH 2/2] add suggested changes --- src/math/p5.Vector.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index f9a3d4ab3c..3557b0f1d6 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -2934,6 +2934,9 @@ class Vector { return this.sub(surfaceNormalCopy.mult(2 * this.dot(surfaceNormalCopy))); } + _showArrayDeprecationWarning() { + } + /** * Returns the vector's components as an array of numbers. * @@ -2953,10 +2956,7 @@ class Vector { * */ array() { - p5._friendlyError( - 'array() is deprecated and will be removed in a future version of p5.js.', - 'p5.Vector.array' - ); + this._showArrayDeprecationWarning(); return [this.x || 0, this.y || 0, this.z || 0]; } @@ -3792,10 +3792,6 @@ class Vector { * @return {Number[]} an Array with the 3 values */ static array(v) { - p5._friendlyError( - 'array() is deprecated and will be removed in a future version of p5.js.', - 'p5.Vector.array' - ); return v.array(); } @@ -3910,6 +3906,17 @@ function vector(p5, fn) { */ p5.Vector = Vector; + let arrayDeprecationWarningShown = false; + Vector.prototype._showArrayDeprecationWarning = function() { + if (p5._friendlyError && !arrayDeprecationWarningShown) { + p5._friendlyError( + 'array() is deprecated and will be removed in a future version of p5.js.', + 'p5.Vector.array' + ); + arrayDeprecationWarningShown = true; + } + }; + /** * The x component of the vector * @type {Number}