p5 2.2.3 → 2.3.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accessibility/color_namer.js +9 -11
- package/dist/accessibility/describe.js +0 -1
- package/dist/accessibility/gridOutput.js +0 -1
- package/dist/accessibility/index.js +9 -10
- package/dist/accessibility/outputs.js +0 -1
- package/dist/accessibility/textOutput.js +0 -1
- package/dist/app.js +11 -10
- package/dist/app.node.js +122 -0
- package/dist/color/color_conversion.js +9 -11
- package/dist/color/creating_reading.js +1 -1
- package/dist/color/index.js +2 -2
- package/dist/color/p5.Color.js +1 -1
- package/dist/color/setting.js +25 -12
- package/dist/{constants-BdTiYOQI.js → constants-0wkVUfqa.js} +2 -2
- package/dist/core/States.js +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +28 -29
- package/dist/core/filterShaders.js +1 -1
- package/dist/core/friendly_errors/fes_core.js +9 -8
- package/dist/core/friendly_errors/file_errors.js +1 -2
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +737 -640
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/friendly_errors/stacktrace.js +0 -1
- package/dist/core/helpers.js +3 -4
- package/dist/core/init.js +24 -21
- package/dist/core/internationalization.js +1 -1
- package/dist/core/legacy.js +9 -11
- package/dist/core/main.js +9 -10
- package/dist/core/p5.Graphics.js +5 -5
- package/dist/core/p5.Renderer.js +3 -3
- package/dist/core/p5.Renderer2D.js +9 -10
- package/dist/core/p5.Renderer3D.js +5 -5
- package/dist/core/rendering.js +5 -5
- package/dist/core/structure.js +0 -1
- package/dist/core/transform.js +7 -16
- package/dist/{creating_reading-C7hu6sg1.js → creating_reading-DLkHH80h.js} +11 -8
- package/dist/data/local_storage.js +0 -1
- package/dist/dom/dom.js +2 -3
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +2 -2
- package/dist/dom/p5.MediaElement.js +2 -2
- package/dist/events/acceleration.js +5 -3
- package/dist/events/keyboard.js +0 -1
- package/dist/events/pointer.js +0 -2
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +19 -12
- package/dist/image/image.js +5 -5
- package/dist/image/index.js +5 -5
- package/dist/image/loading_displaying.js +5 -5
- package/dist/image/p5.Image.js +3 -3
- package/dist/image/pixels.js +0 -1
- package/dist/io/files.js +5 -5
- package/dist/io/index.js +5 -5
- package/dist/io/p5.Table.js +0 -1
- package/dist/io/p5.TableRow.js +0 -1
- package/dist/io/p5.XML.js +0 -1
- package/dist/{ir_builders-Cd6rU9Vm.js → ir_builders-C2ebb6Lu.js} +234 -1
- package/dist/{main-H_nu4eDs.js → main-D2kqeMXM.js} +107 -136
- package/dist/math/Matrices/Matrix.js +1 -1
- package/dist/math/Matrices/MatrixNumjs.js +1 -1
- package/dist/math/calculation.js +0 -1
- package/dist/math/index.js +3 -1
- package/dist/math/math.js +3 -17
- package/dist/math/noise.js +0 -1
- package/dist/math/p5.Matrix.js +1 -2
- package/dist/math/p5.Vector.js +237 -279
- package/dist/math/patch-vector.js +75 -0
- package/dist/math/random.js +0 -1
- package/dist/math/trigonometry.js +3 -4
- package/dist/{p5.Renderer-BmD2P6Wv.js → p5.Renderer-CQI8PO1F.js} +31 -24
- package/dist/{rendering-CC8JNTwG.js → rendering-ltTIxpF2.js} +732 -44
- package/dist/shape/2d_primitives.js +1 -4
- package/dist/shape/attributes.js +43 -8
- package/dist/shape/curves.js +0 -1
- package/dist/shape/custom_shapes.js +260 -5
- package/dist/shape/index.js +2 -2
- package/dist/shape/vertex.js +0 -2
- package/dist/strands/ir_builders.js +1 -1
- package/dist/strands/ir_types.js +5 -1
- package/dist/strands/p5.strands.js +286 -31
- package/dist/strands/strands_api.js +179 -8
- package/dist/strands/strands_codegen.js +26 -8
- package/dist/strands/strands_conditionals.js +1 -1
- package/dist/strands/strands_for.js +1 -1
- package/dist/strands/strands_node.js +1 -1
- package/dist/strands/strands_ternary.js +56 -0
- package/dist/strands/strands_transpiler.js +416 -251
- package/dist/strands_glslBackend-i-ReKgZo.js +423 -0
- package/dist/type/index.js +3 -3
- package/dist/type/lib/Typr.js +1 -1
- package/dist/type/p5.Font.js +3 -3
- package/dist/type/textCore.js +31 -24
- package/dist/utilities/conversion.js +0 -1
- package/dist/utilities/time_date.js +0 -1
- package/dist/utilities/utility_functions.js +0 -1
- package/dist/webgl/3d_primitives.js +5 -5
- package/dist/webgl/GeometryBuilder.js +1 -1
- package/dist/webgl/ShapeBuilder.js +26 -1
- package/dist/webgl/enums.js +1 -1
- package/dist/webgl/index.js +8 -9
- package/dist/webgl/interaction.js +8 -4
- package/dist/webgl/light.js +5 -5
- package/dist/webgl/loading.js +60 -21
- package/dist/webgl/material.js +5 -5
- package/dist/webgl/p5.Camera.js +5 -5
- package/dist/webgl/p5.Framebuffer.js +5 -5
- package/dist/webgl/p5.Geometry.js +3 -5
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +17 -21
- package/dist/webgl/p5.Shader.js +129 -36
- package/dist/webgl/p5.Texture.js +5 -5
- package/dist/webgl/strands_glslBackend.js +5 -386
- package/dist/webgl/text.js +5 -5
- package/dist/webgl/utils.js +5 -5
- package/dist/webgl2Compatibility-DA7DLMuq.js +7 -0
- package/dist/webgpu/index.js +7 -3
- package/dist/webgpu/p5.RendererWebGPU.js +1146 -180
- package/dist/webgpu/shaders/color.js +1 -1
- package/dist/webgpu/shaders/compute.js +32 -0
- package/dist/webgpu/shaders/functions/randomComputeWGSL.js +31 -0
- package/dist/webgpu/shaders/functions/randomVertWGSL.js +30 -0
- package/dist/webgpu/shaders/functions/randomWGSL.js +30 -0
- package/dist/webgpu/shaders/line.js +1 -1
- package/dist/webgpu/shaders/material.js +3 -3
- package/dist/webgpu/strands_wgslBackend.js +137 -15
- package/lib/p5.esm.js +4092 -1950
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +4092 -1950
- package/lib/p5.min.js +1 -1
- package/lib/p5.webgpu.esm.js +1748 -306
- package/lib/p5.webgpu.js +1747 -305
- package/lib/p5.webgpu.min.js +1 -1
- package/package.json +6 -1
- package/types/global.d.ts +4182 -2441
- package/types/p5.d.ts +2776 -1675
- package/dist/noise3DGLSL-Bwrdi4gi.js +0 -9
package/dist/math/p5.Vector.js
CHANGED
|
@@ -1,90 +1,93 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as TWO_PI } from '../constants-0wkVUfqa.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @module Math
|
|
5
|
-
* @requires constants
|
|
6
5
|
*/
|
|
7
6
|
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.y = this.y % yComponent;
|
|
16
|
-
}
|
|
17
|
-
return this;
|
|
8
|
+
/**
|
|
9
|
+
* This function is used by binary vector operations to prioritize shorter vectors,
|
|
10
|
+
* and to emit a warning when lengths do not match.
|
|
11
|
+
*/
|
|
12
|
+
const prioritizeSmallerDimension = function(currentVectorDimension, args) {
|
|
13
|
+
return Math.min(currentVectorDimension, args.length);
|
|
18
14
|
};
|
|
19
15
|
|
|
20
|
-
const calculateRemainder3D = function (xComponent, yComponent, zComponent) {
|
|
21
|
-
if (xComponent !== 0) {
|
|
22
|
-
this.x = this.x % xComponent;
|
|
23
|
-
}
|
|
24
|
-
if (yComponent !== 0) {
|
|
25
|
-
this.y = this.y % yComponent;
|
|
26
|
-
}
|
|
27
|
-
if (zComponent !== 0) {
|
|
28
|
-
this.z = this.z % zComponent;
|
|
29
|
-
}
|
|
30
|
-
return this;
|
|
31
|
-
};
|
|
32
16
|
|
|
33
17
|
class Vector {
|
|
18
|
+
/**
|
|
19
|
+
* The values of an N-dimensional vector.
|
|
20
|
+
*
|
|
21
|
+
* This array of numbers that represents the vector.
|
|
22
|
+
* Each number in the array corresponds to a different component of the vector,
|
|
23
|
+
* like its position in different directions (e.g., x, y, z).
|
|
24
|
+
*
|
|
25
|
+
* You can update the values of the entire vector to a new set of values.
|
|
26
|
+
* You need to provide an array of numbers, where each number represents a component
|
|
27
|
+
* of the vector (e.g., x, y, z). The length of the array will become the number of
|
|
28
|
+
* dimensions of the vector.
|
|
29
|
+
*
|
|
30
|
+
* You can add (`add()`), multiply (`mult()`), divide (`div()`), and subtract (`sub()`)
|
|
31
|
+
* vectors from each other, and calculate remainder (`rem()`). Only use these functions
|
|
32
|
+
* on vectors when they are the same size: both 2-dimensional, or both 3-dimensional.
|
|
33
|
+
* When an operation uses two vectors of different sizes, the smaller dimension will be
|
|
34
|
+
* used, any additional values of the longer vector will be ignored.
|
|
35
|
+
*
|
|
36
|
+
* You can multiply, divide, or calculate remainder of a vector with a single number. Then,
|
|
37
|
+
* the same operation will be done on each element of the vector.
|
|
38
|
+
*
|
|
39
|
+
* @type {Array<number>} The array of values representing the vector.
|
|
40
|
+
* @throws Will throw an error if provided no arguments, or if the arguments
|
|
41
|
+
* are not all finity numbers
|
|
42
|
+
*/
|
|
43
|
+
values = [];
|
|
44
|
+
|
|
34
45
|
// This is how it comes in with createVector()
|
|
35
46
|
// This check if the first argument is a function
|
|
36
47
|
constructor(...args) {
|
|
37
|
-
|
|
48
|
+
|
|
49
|
+
if (args.length === 0) {
|
|
50
|
+
this._friendlyError(
|
|
51
|
+
'Requires valid arguments.', 'p5.Vector'
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
if (typeof args[0] === 'function') {
|
|
39
56
|
this.isPInst = true;
|
|
40
57
|
this._fromRadians = args[0];
|
|
41
58
|
this._toRadians = args[1];
|
|
42
|
-
|
|
59
|
+
args = args.slice(2);
|
|
43
60
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.
|
|
61
|
+
|
|
62
|
+
this.values = [];
|
|
63
|
+
if(Array.isArray(args) && !args.every(v => typeof v === 'number' && Number.isFinite(v))){
|
|
64
|
+
this._friendlyError(
|
|
65
|
+
'Arguments contain non-finite numbers',
|
|
66
|
+
'p5.Vector'
|
|
67
|
+
);
|
|
48
68
|
} else {
|
|
49
|
-
this.
|
|
50
|
-
this._values = values;
|
|
69
|
+
this.values = args;
|
|
51
70
|
}
|
|
52
|
-
}
|
|
53
71
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*
|
|
61
|
-
* @returns {Array<number>} The array of values representing the vector.
|
|
62
|
-
*/
|
|
63
|
-
get values() {
|
|
64
|
-
return this._values;
|
|
72
|
+
// This property is here where duck typing (checking if obj.isVector) needs
|
|
73
|
+
// to be used over more standard type checking (obj instanceof Vector). This
|
|
74
|
+
// needs to happen where we are building multiple files, such as in p5.webgpu.js,
|
|
75
|
+
// where if we `import { Vector }` directly, it will be a separate copy of the
|
|
76
|
+
// Vector class from the one imported in the main p5.js bundle.
|
|
77
|
+
this.isVector = true;
|
|
65
78
|
}
|
|
66
79
|
|
|
80
|
+
// This will get overwritten when exported as part of p5.
|
|
81
|
+
_friendlyError(_e) {}
|
|
82
|
+
|
|
83
|
+
|
|
67
84
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* This method allows you to update the entire vector with a new set of values.
|
|
71
|
-
* You need to provide an array of numbers, where each number represents a component
|
|
72
|
-
* of the vector (e.g., x, y, z). The length of the array should match the number of
|
|
73
|
-
* dimensions of the vector. If the array is shorter, the missing components will be
|
|
74
|
-
* set to 0. If the array is longer, the extra values will be ignored.
|
|
75
|
-
*
|
|
76
|
-
* @param {Array<number>} newValues - An array of numbers representing the new values for the vector.
|
|
85
|
+
* Gets how many dimensions the vector has.
|
|
77
86
|
*
|
|
87
|
+
* @returns {Number} The number of dimensions. Can be 1, 2, or 3.
|
|
78
88
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (dimensions === 0) {
|
|
82
|
-
this.dimensions = 2;
|
|
83
|
-
this._values = [0, 0, 0];
|
|
84
|
-
} else {
|
|
85
|
-
this.dimensions = dimensions;
|
|
86
|
-
this._values = newValues.slice();
|
|
87
|
-
}
|
|
89
|
+
get dimensions(){
|
|
90
|
+
return this.values.length;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
/**
|
|
@@ -97,7 +100,7 @@ class Vector {
|
|
|
97
100
|
* @returns {Number} The x component of the vector. Returns 0 if the value is not defined.
|
|
98
101
|
*/
|
|
99
102
|
get x() {
|
|
100
|
-
return this.
|
|
103
|
+
return this.values[0] || 0;
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
/**
|
|
@@ -118,10 +121,10 @@ class Vector {
|
|
|
118
121
|
* get a value from a position that doesn't exist in the vector.
|
|
119
122
|
*/
|
|
120
123
|
getValue(index) {
|
|
121
|
-
if (index < this.
|
|
122
|
-
return this.
|
|
124
|
+
if (index < this.values.length) {
|
|
125
|
+
return this.values[index];
|
|
123
126
|
} else {
|
|
124
|
-
|
|
127
|
+
this._friendlyError(
|
|
125
128
|
'The index parameter is trying to set a value outside the bounds of the vector',
|
|
126
129
|
'p5.Vector.setValue'
|
|
127
130
|
);
|
|
@@ -143,10 +146,10 @@ class Vector {
|
|
|
143
146
|
* @throws Will throw an error if the index is outside the bounds of the vector, meaning if you try to set a value at a position that doesn't exist in the vector.
|
|
144
147
|
*/
|
|
145
148
|
setValue(index, value) {
|
|
146
|
-
if (index < this.
|
|
147
|
-
this.
|
|
149
|
+
if (index < this.values.length) {
|
|
150
|
+
this.values[index] = value;
|
|
148
151
|
} else {
|
|
149
|
-
|
|
152
|
+
this._friendlyError(
|
|
150
153
|
'The index parameter is trying to set a value outside the bounds of the vector',
|
|
151
154
|
'p5.Vector.setValue'
|
|
152
155
|
);
|
|
@@ -163,7 +166,7 @@ class Vector {
|
|
|
163
166
|
* @returns {Number} The y component of the vector. Returns 0 if the value is not defined.
|
|
164
167
|
*/
|
|
165
168
|
get y() {
|
|
166
|
-
return this.
|
|
169
|
+
return this.values[1] || 0;
|
|
167
170
|
}
|
|
168
171
|
|
|
169
172
|
/**
|
|
@@ -176,7 +179,7 @@ class Vector {
|
|
|
176
179
|
* @returns {Number} The z component of the vector. Returns 0 if the value is not defined.
|
|
177
180
|
*/
|
|
178
181
|
get z() {
|
|
179
|
-
return this.
|
|
182
|
+
return this.values[2] || 0;
|
|
180
183
|
}
|
|
181
184
|
|
|
182
185
|
/**
|
|
@@ -189,7 +192,7 @@ class Vector {
|
|
|
189
192
|
* @returns {Number} The w component of the vector. Returns 0 if the value is not defined.
|
|
190
193
|
*/
|
|
191
194
|
get w() {
|
|
192
|
-
return this.
|
|
195
|
+
return this.values[3] || 0;
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
/**
|
|
@@ -202,8 +205,8 @@ class Vector {
|
|
|
202
205
|
* @param {Number} xVal - The new value for the x component.
|
|
203
206
|
*/
|
|
204
207
|
set x(xVal) {
|
|
205
|
-
if (this.
|
|
206
|
-
this.
|
|
208
|
+
if (this.values.length > 1) {
|
|
209
|
+
this.values[0] = xVal;
|
|
207
210
|
}
|
|
208
211
|
}
|
|
209
212
|
|
|
@@ -217,8 +220,8 @@ class Vector {
|
|
|
217
220
|
* @param {Number} yVal - The new value for the y component.
|
|
218
221
|
*/
|
|
219
222
|
set y(yVal) {
|
|
220
|
-
if (this.
|
|
221
|
-
this.
|
|
223
|
+
if (this.values.length > 1) {
|
|
224
|
+
this.values[1] = yVal;
|
|
222
225
|
}
|
|
223
226
|
}
|
|
224
227
|
|
|
@@ -232,8 +235,8 @@ class Vector {
|
|
|
232
235
|
* @param {Number} zVal - The new value for the z component.
|
|
233
236
|
*/
|
|
234
237
|
set z(zVal) {
|
|
235
|
-
if (this.
|
|
236
|
-
this.
|
|
238
|
+
if (this.values.length > 2) {
|
|
239
|
+
this.values[2] = zVal;
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
|
|
@@ -247,8 +250,8 @@ class Vector {
|
|
|
247
250
|
* @param {Number} wVal - The new value for the w component.
|
|
248
251
|
*/
|
|
249
252
|
set w(wVal) {
|
|
250
|
-
if (this.
|
|
251
|
-
this.
|
|
253
|
+
if (this.values.length > 3) {
|
|
254
|
+
this.values[3] = wVal;
|
|
252
255
|
}
|
|
253
256
|
}
|
|
254
257
|
|
|
@@ -270,7 +273,7 @@ class Vector {
|
|
|
270
273
|
* }
|
|
271
274
|
*/
|
|
272
275
|
toString() {
|
|
273
|
-
return `vector[${this.
|
|
276
|
+
return `vector[${this.values.join(', ')}]`;
|
|
274
277
|
}
|
|
275
278
|
|
|
276
279
|
/**
|
|
@@ -328,13 +331,12 @@ class Vector {
|
|
|
328
331
|
*/
|
|
329
332
|
set(...args) {
|
|
330
333
|
if (args[0] instanceof Vector) {
|
|
331
|
-
this.
|
|
334
|
+
this.values = args[0].values.slice();
|
|
332
335
|
} else if (Array.isArray(args[0])) {
|
|
333
|
-
this.
|
|
336
|
+
this.values = args[0].map(arg => arg || 0);
|
|
334
337
|
} else {
|
|
335
|
-
this.
|
|
338
|
+
this.values = args.map(arg => arg || 0);
|
|
336
339
|
}
|
|
337
|
-
this.dimensions = this._values.length;
|
|
338
340
|
return this;
|
|
339
341
|
}
|
|
340
342
|
|
|
@@ -364,12 +366,14 @@ class Vector {
|
|
|
364
366
|
*/
|
|
365
367
|
copy() {
|
|
366
368
|
if (this.isPInst) {
|
|
367
|
-
return new Vector(this._fromRadians, this._toRadians, ...this.
|
|
369
|
+
return new Vector(this._fromRadians, this._toRadians, ...this.values);
|
|
368
370
|
} else {
|
|
369
|
-
return new Vector(...this.
|
|
371
|
+
return new Vector(...this.values);
|
|
370
372
|
}
|
|
371
373
|
}
|
|
372
374
|
|
|
375
|
+
|
|
376
|
+
|
|
373
377
|
/**
|
|
374
378
|
* Adds to a vector's components.
|
|
375
379
|
*
|
|
@@ -377,8 +381,12 @@ class Vector {
|
|
|
377
381
|
* another <a href="#/p5.Vector">p5.Vector</a> object, as in `v.add(v2)`, or
|
|
378
382
|
* an array of numbers, as in `v.add([1, 2, 3])`.
|
|
379
383
|
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
384
|
+
* Add vectors only when they are the same size: both 2-dimensional, or
|
|
385
|
+
* both 3-dimensional. When two vectors of different sizes are added, the
|
|
386
|
+
* smaller dimension will be used, any additional values of the longer
|
|
387
|
+
* vector will be ignored.
|
|
388
|
+
* For example, adding `[1, 2, 3]` and `[4, 5]` will result in `[5, 7]`.
|
|
389
|
+
*
|
|
382
390
|
* Calling `add()` with no arguments, as in `v.add()`, has no effect.
|
|
383
391
|
*
|
|
384
392
|
* This method supports N-dimensional vectors.
|
|
@@ -495,17 +503,18 @@ class Vector {
|
|
|
495
503
|
* @chainable
|
|
496
504
|
*/
|
|
497
505
|
add(...args) {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
});
|
|
506
|
+
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
507
|
+
|
|
508
|
+
this.values = this.values.reduce((acc, v, i) => {
|
|
509
|
+
if(i < minDimension) acc[i] = this.values[i] + Number(args[i]);
|
|
510
|
+
return acc;
|
|
511
|
+
}, new Array(minDimension));
|
|
512
|
+
|
|
506
513
|
return this;
|
|
507
514
|
}
|
|
508
515
|
|
|
516
|
+
|
|
517
|
+
|
|
509
518
|
/**
|
|
510
519
|
* Performs modulo (remainder) division with a vector's `x`, `y`, and `z`
|
|
511
520
|
* components.
|
|
@@ -515,10 +524,14 @@ class Vector {
|
|
|
515
524
|
* an array of numbers, as in `v.rem([1, 2, 3])`.
|
|
516
525
|
*
|
|
517
526
|
* If only one value is provided, as in `v.rem(2)`, then all the components
|
|
518
|
-
* will be set to their values modulo 2.
|
|
519
|
-
* `v.rem(2, 3)`, then `v.z` won't change. Calling `rem()` with no
|
|
527
|
+
* will be set to their values modulo 2. Calling `rem()` with no
|
|
520
528
|
* arguments, as in `v.rem()`, has no effect.
|
|
521
529
|
*
|
|
530
|
+
* Modulo vectors only when they are the same size: both 2D, or both 3D.
|
|
531
|
+
* When two vectors of different sizes are used, the smaller dimension will be
|
|
532
|
+
* used, any additional values of the longer vector will be ignored.
|
|
533
|
+
* For example, taking `[3, 6, 9]` modulo `[2, 4]` will result in `[1, 2]`.
|
|
534
|
+
*
|
|
522
535
|
* The static version of `rem()`, as in `p5.Vector.rem(v2, v1)`, returns a
|
|
523
536
|
* new <a href="#/p5.Vector">p5.Vector</a> object and doesn't change the
|
|
524
537
|
* originals.
|
|
@@ -613,59 +626,14 @@ class Vector {
|
|
|
613
626
|
* @param {p5.Vector | Number[]} value divisor vector.
|
|
614
627
|
* @chainable
|
|
615
628
|
*/
|
|
616
|
-
rem(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
xComponent,
|
|
625
|
-
yComponent,
|
|
626
|
-
zComponent
|
|
627
|
-
);
|
|
628
|
-
}
|
|
629
|
-
} else if (Array.isArray(x)) {
|
|
630
|
-
if (x.every(element => Number.isFinite(element))) {
|
|
631
|
-
if (x.length === 2) {
|
|
632
|
-
return calculateRemainder2D.call(this, x[0], x[1]);
|
|
633
|
-
}
|
|
634
|
-
if (x.length === 3) {
|
|
635
|
-
return calculateRemainder3D.call(this, x[0], x[1], x[2]);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
} else if (arguments.length === 1) {
|
|
639
|
-
if (Number.isFinite(arguments[0]) && arguments[0] !== 0) {
|
|
640
|
-
this.x = this.x % arguments[0];
|
|
641
|
-
this.y = this.y % arguments[0];
|
|
642
|
-
this.z = this.z % arguments[0];
|
|
643
|
-
return this;
|
|
644
|
-
}
|
|
645
|
-
} else if (arguments.length === 2) {
|
|
646
|
-
const vectorComponents = [...arguments];
|
|
647
|
-
if (vectorComponents.every(element => Number.isFinite(element))) {
|
|
648
|
-
if (vectorComponents.length === 2) {
|
|
649
|
-
return calculateRemainder2D.call(
|
|
650
|
-
this,
|
|
651
|
-
vectorComponents[0],
|
|
652
|
-
vectorComponents[1]
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
} else if (arguments.length === 3) {
|
|
657
|
-
const vectorComponents = [...arguments];
|
|
658
|
-
if (vectorComponents.every(element => Number.isFinite(element))) {
|
|
659
|
-
if (vectorComponents.length === 3) {
|
|
660
|
-
return calculateRemainder3D.call(
|
|
661
|
-
this,
|
|
662
|
-
vectorComponents[0],
|
|
663
|
-
vectorComponents[1],
|
|
664
|
-
vectorComponents[2]
|
|
665
|
-
);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
629
|
+
rem(...args) {
|
|
630
|
+
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
631
|
+
|
|
632
|
+
this.values = Array.from({ length: minDimension }, (_, i) => {
|
|
633
|
+
return (args[i] > 0) ? this.values[i] % args[i] : this.values[i];
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
return this;
|
|
669
637
|
}
|
|
670
638
|
|
|
671
639
|
/**
|
|
@@ -675,10 +643,13 @@ class Vector {
|
|
|
675
643
|
* <a href="#/p5.Vector">p5.Vector</a> object, as in `v.sub(v2)`, or an array
|
|
676
644
|
* of numbers, as in `v.sub([1, 2, 3])`.
|
|
677
645
|
*
|
|
678
|
-
* If a value isn't provided for a component, it won't change. For
|
|
679
|
-
* example, `v.sub(4, 5)` subtracts 4 from `v.x`, 5 from `v.y`, and 0 from `v.z`.
|
|
680
646
|
* Calling `sub()` with no arguments, as in `v.sub()`, has no effect.
|
|
681
647
|
*
|
|
648
|
+
* Subtract vectors only when they are the same size: both 2D, or both 3D.
|
|
649
|
+
* When two vectors of different sizes are used, the smaller dimension will be
|
|
650
|
+
* used, any additional values of the longer vector will be ignored.
|
|
651
|
+
* For example, subtracting `[1, 2]` from `[3, 5, 7]` will result in `[2, 3]`.
|
|
652
|
+
*
|
|
682
653
|
* The static version of `sub()`, as in `p5.Vector.sub(v2, v1)`, returns a new
|
|
683
654
|
* <a href="#/p5.Vector">p5.Vector</a> object and doesn't change the
|
|
684
655
|
* originals.
|
|
@@ -788,19 +759,13 @@ class Vector {
|
|
|
788
759
|
* @chainable
|
|
789
760
|
*/
|
|
790
761
|
sub(...args) {
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
});
|
|
799
|
-
} else {
|
|
800
|
-
args.forEach((value, index) => {
|
|
801
|
-
this._values[index] -= value || 0;
|
|
802
|
-
});
|
|
803
|
-
}
|
|
762
|
+
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
763
|
+
|
|
764
|
+
this.values = this.values.reduce((acc, v, i) => {
|
|
765
|
+
if(i < minDimension) acc[i] = this.values[i] - args[i];
|
|
766
|
+
return acc;
|
|
767
|
+
}, new Array(minDimension));
|
|
768
|
+
|
|
804
769
|
return this;
|
|
805
770
|
}
|
|
806
771
|
|
|
@@ -812,11 +777,14 @@ class Vector {
|
|
|
812
777
|
* of numbers, as in `v.mult([1, 2, 3])`.
|
|
813
778
|
*
|
|
814
779
|
* If only one value is provided, as in `v.mult(2)`, then all the components
|
|
815
|
-
* will be multiplied by 2.
|
|
816
|
-
* won't change. For example, `v.mult(4, 5)` multiplies `v.x` by, `v.y` by 5,
|
|
817
|
-
* and `v.z` by 1. Calling `mult()` with no arguments, as in `v.mult()`, has
|
|
780
|
+
* will be multiplied by 2. Calling `mult()` with no arguments, as in `v.mult()`, has
|
|
818
781
|
* no effect.
|
|
819
782
|
*
|
|
783
|
+
* Multiply vectors only when they are the same size: both 2D, or both 3D.
|
|
784
|
+
* When two vectors of different sizes are multiplied, the smaller dimension will be
|
|
785
|
+
* used, any additional values of the longer vector will be ignored.
|
|
786
|
+
* For example, multiplying `[1, 2, 3]` by `[4, 5]` will result in `[4, 10]`.
|
|
787
|
+
*
|
|
820
788
|
* The static version of `mult()`, as in `p5.Vector.mult(v, 2)`, returns a new
|
|
821
789
|
* <a href="#/p5.Vector">p5.Vector</a> object and doesn't change the
|
|
822
790
|
* originals.
|
|
@@ -979,43 +947,51 @@ class Vector {
|
|
|
979
947
|
* @chainable
|
|
980
948
|
*/
|
|
981
949
|
mult(...args) {
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
} else
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
} else
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
)
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
}
|
|
950
|
+
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
951
|
+
|
|
952
|
+
this.values = this.values.reduce((acc, v, i) => {
|
|
953
|
+
if(i < minDimension) acc[i] = this.values[i] * args[i];
|
|
954
|
+
return acc;
|
|
955
|
+
}, new Array(minDimension));
|
|
956
|
+
|
|
957
|
+
// if (args.length === 1 && args[0] instanceof Vector) {
|
|
958
|
+
// const v = args[0];
|
|
959
|
+
// const maxLen = Math.min(this.values.length, v.values.length);
|
|
960
|
+
// for (let i = 0; i < maxLen; i++) {
|
|
961
|
+
// if (Number.isFinite(v.values[i]) && typeof v.values[i] === 'number') {
|
|
962
|
+
// if(!this.values[i]) this.values[i] = 0;
|
|
963
|
+
// this.values[i] *= v.values[i];
|
|
964
|
+
// } else {
|
|
965
|
+
// console.warn(
|
|
966
|
+
// 'p5.Vector.prototype.mult:',
|
|
967
|
+
// 'v contains components that are either undefined or not finite numbers'
|
|
968
|
+
// );
|
|
969
|
+
// return this;
|
|
970
|
+
// }
|
|
971
|
+
// }
|
|
972
|
+
// } else if (args.length === 1 && Array.isArray(args[0])) {
|
|
973
|
+
// const arr = args[0];
|
|
974
|
+
// const maxLen = Math.min(this.values.length, arr.length);
|
|
975
|
+
// for (let i = 0; i < maxLen; i++) {
|
|
976
|
+
// if (Number.isFinite(arr[i]) && typeof arr[i] === 'number') {
|
|
977
|
+
// this.values[i] *= arr[i];
|
|
978
|
+
// } else {
|
|
979
|
+
// console.warn(
|
|
980
|
+
// 'p5.Vector.prototype.mult:',
|
|
981
|
+
// 'arr contains elements that are either undefined or not finite numbers'
|
|
982
|
+
// );
|
|
983
|
+
// return this;
|
|
984
|
+
// }
|
|
985
|
+
// }
|
|
986
|
+
// } else if (
|
|
987
|
+
// args.length === 1 &&
|
|
988
|
+
// typeof args[0] === 'number' &&
|
|
989
|
+
// Number.isFinite(args[0])
|
|
990
|
+
// ) {
|
|
991
|
+
// for (let i = 0; i < this.values.length; i++) {
|
|
992
|
+
// this.values[i] *= args[0];
|
|
993
|
+
// }
|
|
994
|
+
// }
|
|
1019
995
|
return this;
|
|
1020
996
|
}
|
|
1021
997
|
|
|
@@ -1027,11 +1003,14 @@ class Vector {
|
|
|
1027
1003
|
* of numbers, as in `v.div([1, 2, 3])`.
|
|
1028
1004
|
*
|
|
1029
1005
|
* If only one value is provided, as in `v.div(2)`, then all the components
|
|
1030
|
-
* will be divided by 2.
|
|
1031
|
-
* won't change. For example, `v.div(4, 5)` divides `v.x` by, `v.y` by 5,
|
|
1032
|
-
* and `v.z` by 1. Calling `div()` with no arguments, as in `v.div()`, has
|
|
1006
|
+
* will be divided by 2. Calling `div()` with no arguments, as in `v.div()`, has
|
|
1033
1007
|
* no effect.
|
|
1034
1008
|
*
|
|
1009
|
+
* Divide vectors only when they are the same size: both 2D, or both 3D.
|
|
1010
|
+
* When two vectors of different sizes are divided, the smaller dimension will be
|
|
1011
|
+
* used, any additional values of the longer vector will be ignored.
|
|
1012
|
+
* For example, dividing `[8, 12, 21]` by `[2, 3]` will result in `[4, 4]`.
|
|
1013
|
+
*
|
|
1035
1014
|
* The static version of `div()`, as in `p5.Vector.div(v, 2)`, returns a new
|
|
1036
1015
|
* <a href="#/p5.Vector">p5.Vector</a> object and doesn't change the
|
|
1037
1016
|
* originals.
|
|
@@ -1195,57 +1174,19 @@ class Vector {
|
|
|
1195
1174
|
* @chainable
|
|
1196
1175
|
*/
|
|
1197
1176
|
div(...args) {
|
|
1198
|
-
|
|
1199
|
-
if (args.length === 1 && args[0] instanceof Vector) {
|
|
1200
|
-
const v = args[0];
|
|
1201
|
-
if (
|
|
1202
|
-
v._values.every(
|
|
1203
|
-
val => Number.isFinite(val) && typeof val === 'number'
|
|
1204
|
-
)
|
|
1205
|
-
) {
|
|
1206
|
-
if (v._values.some(val => val === 0)) {
|
|
1207
|
-
console.warn('p5.Vector.prototype.div:', 'divide by 0');
|
|
1208
|
-
return this;
|
|
1209
|
-
}
|
|
1210
|
-
this._values = this._values.map((val, i) => val / v._values[i]);
|
|
1211
|
-
} else {
|
|
1212
|
-
console.warn(
|
|
1213
|
-
'p5.Vector.prototype.div:',
|
|
1214
|
-
'vector contains components that are either undefined or not finite numbers'
|
|
1215
|
-
);
|
|
1216
|
-
}
|
|
1217
|
-
return this;
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
if (args.length === 1 && Array.isArray(args[0])) {
|
|
1221
|
-
const arr = args[0];
|
|
1222
|
-
if (arr.every(val => Number.isFinite(val) && typeof val === 'number')) {
|
|
1223
|
-
if (arr.some(val => val === 0)) {
|
|
1224
|
-
console.warn('p5.Vector.prototype.div:', 'divide by 0');
|
|
1225
|
-
return this;
|
|
1226
|
-
}
|
|
1227
|
-
this._values = this._values.map((val, i) => val / arr[i]);
|
|
1228
|
-
} else {
|
|
1229
|
-
console.warn(
|
|
1230
|
-
'p5.Vector.prototype.div:',
|
|
1231
|
-
'array contains components that are either undefined or not finite numbers'
|
|
1232
|
-
);
|
|
1233
|
-
}
|
|
1234
|
-
return this;
|
|
1235
|
-
}
|
|
1177
|
+
const minDimension = prioritizeSmallerDimension(this.dimensions, args);
|
|
1236
1178
|
|
|
1237
|
-
if
|
|
1238
|
-
if (args.some(val => val === 0)) {
|
|
1239
|
-
console.warn('p5.Vector.prototype.div:', 'divide by 0');
|
|
1240
|
-
return this;
|
|
1241
|
-
}
|
|
1242
|
-
this._values = this._values.map((val, i) => val / args[0]);
|
|
1243
|
-
} else {
|
|
1179
|
+
if(!args.every(v => typeof v === 'number' && v !== 0)){
|
|
1244
1180
|
console.warn(
|
|
1245
|
-
'p5.Vector.prototype.div
|
|
1246
|
-
'
|
|
1181
|
+
'p5.Vector.prototype.div',
|
|
1182
|
+
'Arguments contain components that are 0'
|
|
1247
1183
|
);
|
|
1184
|
+
return this;
|
|
1248
1185
|
}
|
|
1186
|
+
this.values = this.values.reduce((acc, v, i) => {
|
|
1187
|
+
if(i < minDimension) acc[i] = this.values[i] / args[i];
|
|
1188
|
+
return acc;
|
|
1189
|
+
}, new Array(minDimension));
|
|
1249
1190
|
|
|
1250
1191
|
return this;
|
|
1251
1192
|
}
|
|
@@ -1298,7 +1239,8 @@ class Vector {
|
|
|
1298
1239
|
* // Create a p5.Vector object.
|
|
1299
1240
|
* let p = createVector(30, 40);
|
|
1300
1241
|
*
|
|
1301
|
-
* // Draw a line from
|
|
1242
|
+
* // Draw a line from th
|
|
1243
|
+
* e origin.
|
|
1302
1244
|
* line(0, 0, p.x, p.y);
|
|
1303
1245
|
*
|
|
1304
1246
|
* // Style the text.
|
|
@@ -1313,7 +1255,7 @@ class Vector {
|
|
|
1313
1255
|
* }
|
|
1314
1256
|
*/
|
|
1315
1257
|
magSq() {
|
|
1316
|
-
return this.
|
|
1258
|
+
return this.values.reduce(
|
|
1317
1259
|
(sum, component) => sum + component * component,
|
|
1318
1260
|
0
|
|
1319
1261
|
);
|
|
@@ -1417,9 +1359,9 @@ class Vector {
|
|
|
1417
1359
|
*/
|
|
1418
1360
|
dot(...args) {
|
|
1419
1361
|
if (args[0] instanceof Vector) {
|
|
1420
|
-
return this.dot(...args[0].
|
|
1362
|
+
return this.dot(...args[0].values);
|
|
1421
1363
|
}
|
|
1422
|
-
return this.
|
|
1364
|
+
return this.values.reduce((sum, component, index) => {
|
|
1423
1365
|
return sum + component * (args[index] || 0);
|
|
1424
1366
|
}, 0);
|
|
1425
1367
|
}
|
|
@@ -1430,6 +1372,9 @@ class Vector {
|
|
|
1430
1372
|
* The cross product is a vector that points straight out of the plane created
|
|
1431
1373
|
* by two vectors. The cross product's magnitude is the area of the parallelogram
|
|
1432
1374
|
* formed by the original two vectors.
|
|
1375
|
+
*
|
|
1376
|
+
* The cross product is defined on 3-dimensional vectors, and will use the `x`, `y`,
|
|
1377
|
+
* and `z` components. This method should only be used with 3D vectors.
|
|
1433
1378
|
*
|
|
1434
1379
|
* The static version of `cross()`, as in `p5.Vector.cross(v1, v2)`, is the same
|
|
1435
1380
|
* as calling `v1.cross(v2)`.
|
|
@@ -2038,8 +1983,18 @@ class Vector {
|
|
|
2038
1983
|
* }
|
|
2039
1984
|
*/
|
|
2040
1985
|
setHeading(a) {
|
|
2041
|
-
if (this.
|
|
2042
|
-
|
|
1986
|
+
if (this.dimensions < 2 || (
|
|
1987
|
+
this._values instanceof Array && this._values.slice(2).some(v => v !== 0))
|
|
1988
|
+
) {
|
|
1989
|
+
p5._friendlyError(
|
|
1990
|
+
'p5.Vector.setHeading() only supports 2D vectors (z === 0). ' +
|
|
1991
|
+
'For 3D or higher-dimensional vectors, use rotate() or another ' +
|
|
1992
|
+
'appropriate method instead.',
|
|
1993
|
+
'p5.Vector.setHeading'
|
|
1994
|
+
);
|
|
1995
|
+
return this;
|
|
1996
|
+
}
|
|
1997
|
+
const m = this.mag();
|
|
2043
1998
|
this.x = m * Math.cos(a);
|
|
2044
1999
|
this.y = m * Math.sin(a);
|
|
2045
2000
|
return this;
|
|
@@ -2738,6 +2693,7 @@ class Vector {
|
|
|
2738
2693
|
* Returns the vector's components as an array of numbers.
|
|
2739
2694
|
*
|
|
2740
2695
|
* @return {Number[]} array with the vector's components.
|
|
2696
|
+
* @deprecated To retrieve vector components, use `v.values`
|
|
2741
2697
|
* @example
|
|
2742
2698
|
* // META:norender
|
|
2743
2699
|
* function setup() {
|
|
@@ -2824,15 +2780,15 @@ class Vector {
|
|
|
2824
2780
|
equals(...args) {
|
|
2825
2781
|
let values;
|
|
2826
2782
|
if (args[0] instanceof Vector) {
|
|
2827
|
-
values = args[0].
|
|
2783
|
+
values = args[0].values;
|
|
2828
2784
|
} else if (Array.isArray(args[0])) {
|
|
2829
2785
|
values = args[0];
|
|
2830
2786
|
} else {
|
|
2831
2787
|
values = args;
|
|
2832
2788
|
}
|
|
2833
2789
|
|
|
2834
|
-
for (let i = 0; i < this.
|
|
2835
|
-
if (this.
|
|
2790
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
2791
|
+
if (this.values[i] !== (values[i] || 0)) {
|
|
2836
2792
|
return false;
|
|
2837
2793
|
}
|
|
2838
2794
|
}
|
|
@@ -2852,8 +2808,8 @@ class Vector {
|
|
|
2852
2808
|
* @chainable
|
|
2853
2809
|
*/
|
|
2854
2810
|
clampToZero() {
|
|
2855
|
-
for (let i = 0; i < this.
|
|
2856
|
-
this.
|
|
2811
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
2812
|
+
this.values[i] = this._clampToZero(this.values[i]);
|
|
2857
2813
|
}
|
|
2858
2814
|
return this;
|
|
2859
2815
|
}
|
|
@@ -3110,7 +3066,7 @@ class Vector {
|
|
|
3110
3066
|
if (!target) {
|
|
3111
3067
|
target = v1.copy();
|
|
3112
3068
|
if (arguments.length === 3) {
|
|
3113
|
-
|
|
3069
|
+
this._friendlyError(
|
|
3114
3070
|
'The target parameter is undefined, it should be of type p5.Vector',
|
|
3115
3071
|
'p5.Vector.add'
|
|
3116
3072
|
);
|
|
@@ -3157,7 +3113,7 @@ class Vector {
|
|
|
3157
3113
|
if (!target) {
|
|
3158
3114
|
target = v1.copy();
|
|
3159
3115
|
if (arguments.length === 3) {
|
|
3160
|
-
|
|
3116
|
+
this._friendlyError(
|
|
3161
3117
|
'The target parameter is undefined, it should be of type p5.Vector',
|
|
3162
3118
|
'p5.Vector.sub'
|
|
3163
3119
|
);
|
|
@@ -3201,7 +3157,7 @@ class Vector {
|
|
|
3201
3157
|
if (!target) {
|
|
3202
3158
|
target = v.copy();
|
|
3203
3159
|
if (arguments.length === 3) {
|
|
3204
|
-
|
|
3160
|
+
this._friendlyError(
|
|
3205
3161
|
'The target parameter is undefined, it should be of type p5.Vector',
|
|
3206
3162
|
'p5.Vector.mult'
|
|
3207
3163
|
);
|
|
@@ -3227,7 +3183,7 @@ class Vector {
|
|
|
3227
3183
|
target = v.copy();
|
|
3228
3184
|
} else {
|
|
3229
3185
|
if (!(target instanceof Vector)) {
|
|
3230
|
-
|
|
3186
|
+
this._friendlyError(
|
|
3231
3187
|
'The target parameter should be of type p5.Vector',
|
|
3232
3188
|
'p5.Vector.rotate'
|
|
3233
3189
|
);
|
|
@@ -3271,7 +3227,7 @@ class Vector {
|
|
|
3271
3227
|
target = v.copy();
|
|
3272
3228
|
|
|
3273
3229
|
if (arguments.length === 3) {
|
|
3274
|
-
|
|
3230
|
+
this._friendlyError(
|
|
3275
3231
|
'The target parameter is undefined, it should be of type p5.Vector',
|
|
3276
3232
|
'p5.Vector.div'
|
|
3277
3233
|
);
|
|
@@ -3339,7 +3295,7 @@ class Vector {
|
|
|
3339
3295
|
if (!target) {
|
|
3340
3296
|
target = v1.copy();
|
|
3341
3297
|
if (arguments.length === 4) {
|
|
3342
|
-
|
|
3298
|
+
this._friendlyError(
|
|
3343
3299
|
'The target parameter is undefined, it should be of type p5.Vector',
|
|
3344
3300
|
'p5.Vector.lerp'
|
|
3345
3301
|
);
|
|
@@ -3369,7 +3325,7 @@ class Vector {
|
|
|
3369
3325
|
if (!target) {
|
|
3370
3326
|
target = v1.copy();
|
|
3371
3327
|
if (arguments.length === 4) {
|
|
3372
|
-
|
|
3328
|
+
this._friendlyError(
|
|
3373
3329
|
'The target parameter is undefined, it should be of type p5.Vector',
|
|
3374
3330
|
'p5.Vector.slerp'
|
|
3375
3331
|
);
|
|
@@ -3423,7 +3379,7 @@ class Vector {
|
|
|
3423
3379
|
target = v.copy();
|
|
3424
3380
|
} else {
|
|
3425
3381
|
if (!(target instanceof Vector)) {
|
|
3426
|
-
|
|
3382
|
+
this._friendlyError(
|
|
3427
3383
|
'The target parameter should be of type p5.Vector',
|
|
3428
3384
|
'p5.Vector.normalize'
|
|
3429
3385
|
);
|
|
@@ -3449,7 +3405,7 @@ class Vector {
|
|
|
3449
3405
|
target = v.copy();
|
|
3450
3406
|
} else {
|
|
3451
3407
|
if (!(target instanceof Vector)) {
|
|
3452
|
-
|
|
3408
|
+
this._friendlyError(
|
|
3453
3409
|
'The target parameter should be of type p5.Vector',
|
|
3454
3410
|
'p5.Vector.limit'
|
|
3455
3411
|
);
|
|
@@ -3475,7 +3431,7 @@ class Vector {
|
|
|
3475
3431
|
target = v.copy();
|
|
3476
3432
|
} else {
|
|
3477
3433
|
if (!(target instanceof Vector)) {
|
|
3478
|
-
|
|
3434
|
+
this._friendlyError(
|
|
3479
3435
|
'The target parameter should be of type p5.Vector',
|
|
3480
3436
|
'p5.Vector.setMag'
|
|
3481
3437
|
);
|
|
@@ -3531,7 +3487,7 @@ class Vector {
|
|
|
3531
3487
|
target = incidentVector.copy();
|
|
3532
3488
|
} else {
|
|
3533
3489
|
if (!(target instanceof Vector)) {
|
|
3534
|
-
|
|
3490
|
+
this._friendlyError(
|
|
3535
3491
|
'The target parameter should be of type p5.Vector',
|
|
3536
3492
|
'p5.Vector.reflect'
|
|
3537
3493
|
);
|
|
@@ -3572,7 +3528,7 @@ class Vector {
|
|
|
3572
3528
|
} else if (v1 instanceof Array) {
|
|
3573
3529
|
v = new Vector().set(v1);
|
|
3574
3530
|
} else {
|
|
3575
|
-
|
|
3531
|
+
this._friendlyError(
|
|
3576
3532
|
'The v1 parameter should be of type Array or p5.Vector',
|
|
3577
3533
|
'p5.Vector.equals'
|
|
3578
3534
|
);
|
|
@@ -3660,6 +3616,8 @@ function vector(p5, fn) {
|
|
|
3660
3616
|
*/
|
|
3661
3617
|
p5.Vector = Vector;
|
|
3662
3618
|
|
|
3619
|
+
Vector.prototype._friendlyError = p5._friendlyError;
|
|
3620
|
+
|
|
3663
3621
|
/**
|
|
3664
3622
|
* The x component of the vector
|
|
3665
3623
|
* @type {Number}
|