Skip to content

Commit fa6c545

Browse files
authored
Merge pull request #8203 from perminder-17/createVector
Stabilize behavior of createVector() with zero arguments
2 parents c988e29 + 7c7ce52 commit fa6c545

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/core/friendly_errors/fes_core.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ function fesCore(p5, fn){
227227
* @param {Number|String} [color] CSS color code
228228
*/
229229
p5._friendlyError = function(message, func, color) {
230+
if (p5.disableFriendlyErrors) return;
230231
p5._report(message, func, color);
231232
};
232233

src/math/math.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function math(p5, fn) {
2323
* This allows for flexibility in representing vectors in higher-dimensional
2424
* spaces.
2525
*
26+
* Calling `createVector()` **with no arguments** is **deprecated** and will emit
27+
* a friendly warning. Use `createVector(0)`, `createVector(0, 0)`, or
28+
* `createVector(0, 0, 0)` instead.
29+
*
2630
* <a href="#/p5.Vector">p5.Vector</a> objects are often used to program
2731
* motion because they simplify the math. For example, a moving ball has a
2832
* position and a velocity. Position describes where the ball is in space. The
@@ -96,6 +100,11 @@ function math(p5, fn) {
96100
* </div>
97101
*/
98102
fn.createVector = function (x, y, z) {
103+
if (arguments.length === 0) {
104+
p5._friendlyError(
105+
'In 1.x, createVector() was a shortcut for createVector(0, 0, 0). In 2.x, p5.js has vectors of any dimension, so you must provide your desired number of zeros. Use createVector(0, 0) for a 2D vector and createVector(0, 0, 0) for a 3D vector.'
106+
);
107+
}
99108
if (this instanceof p5) {
100109
return new p5.Vector(
101110
this._fromRadians.bind(this),

0 commit comments

Comments
 (0)