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
17 changes: 17 additions & 0 deletions src/math/p5.Vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <div class = "norender">
Expand All @@ -2952,6 +2956,7 @@ class Vector {
* </div>
*/
array() {
this._showArrayDeprecationWarning();
return [this.x || 0, this.y || 0, this.z || 0];
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Loading