diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index a264fb811e..c6b74052bb 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -2934,9 +2934,13 @@ class Vector { return this.sub(surfaceNormalCopy.mult(2 * this.dot(surfaceNormalCopy))); } + _showArrayDeprecationWarning() { + } + /** * Returns the vector's components as an array of numbers. * + * @deprecated * @return {Number[]} array with the vector's components. * @example *
@@ -2952,6 +2956,7 @@ class Vector { *
*/ array() { + this._showArrayDeprecationWarning(); return [this.x || 0, this.y || 0, this.z || 0]; } @@ -3781,6 +3786,7 @@ 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 @@ -3900,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}