From 6a5d0aa8de1e51d248a26f0d9258bae3a142d48b Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 23 Oct 2025 00:30:49 +0530 Subject: [PATCH 1/3] 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/3] 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} From 69879a4995088a1c0441f83a28520782fd4b8952 Mon Sep 17 00:00:00 2001 From: Harsh Date: Tue, 16 Dec 2025 16:56:19 +0530 Subject: [PATCH 3/3] fixes --- src/math/p5.Vector.js | 9 ++++----- test/unit/math/p5.Vector.js | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index c6b74052bb..d7f880dd77 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -2934,13 +2934,12 @@ class Vector { return this.sub(surfaceNormalCopy.mult(2 * this.dot(surfaceNormalCopy))); } - _showArrayDeprecationWarning() { - } + /** - * Returns the vector's components as an array of numbers. + * Returns the vector's first three components as an array of three numbers. * - * @deprecated + * @deprecated array() will be removed in a future version of p5.js; use the more flexible v.values instead of v.array() * @return {Number[]} array with the vector's components. * @example *
@@ -3910,7 +3909,7 @@ function vector(p5, fn) { Vector.prototype._showArrayDeprecationWarning = function() { if (p5._friendlyError && !arrayDeprecationWarningShown) { p5._friendlyError( - 'array() is deprecated and will be removed in a future version of p5.js.', + 'array() is deprecated and will be removed in a future version of p5.js; use the more flexible v.values instead of v.array()', 'p5.Vector.array' ); arrayDeprecationWarningShown = true; diff --git a/test/unit/math/p5.Vector.js b/test/unit/math/p5.Vector.js index 4028ee2dba..d24f8d7c94 100644 --- a/test/unit/math/p5.Vector.js +++ b/test/unit/math/p5.Vector.js @@ -5,7 +5,8 @@ suite('p5.Vector', function () { var v; const mockP5 = { - _validateParameters: vi.fn() + _validateParameters: vi.fn(), + _friendlyError: vi.fn() }; const mockP5Prototype = {}; @@ -2072,5 +2073,22 @@ suite('p5.Vector', function () { -4.10759023698152e-16, -2.23606797749979, 2 ]); }); + suite('deprecation warnings', function () { + test('array() should trigger deprecation warning', function () { + v = new mockP5.Vector(1, 2, 3); + v.array(); + expect(mockP5._friendlyError).toHaveBeenCalledWith( + 'array() is deprecated and will be removed in a future version of p5.js; use the more flexible v.values instead of v.array()', + 'p5.Vector.array' + ); + }); + + test('static array() should delegate to instance array()', function () { + v = new mockP5.Vector(1, 2, 3); + const spy = vi.spyOn(v, 'array'); + mockP5.Vector.array(v); + expect(spy).toHaveBeenCalled(); + }); + }); }); });