Skip to content
Open
Changes from 2 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
10 changes: 10 additions & 0 deletions src/math/p5.Vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2937,6 +2937,7 @@
/**
* 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 +2953,10 @@
* </div>
*/
array() {
p5._friendlyError(

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Framebuffer.js > p5.Framebuffer > formats and channels > framebuffers work with WebGL 1, unsigned-byte rgba float depth antialiased

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ Geometry._addSegment src/webgl/p5.Geometry.js:1564:21 ❯ Geometry._edgesToVertices src/webgl/p5.Geometry.js:1449:14 ❯ RendererGL.box src/webgl/3d_primitives.js:2478:17 ❯ fn.box src/webgl/3d_primitives.js:703:20 ❯ p5.box src/core/friendly_errors/param_validator.js:583:23 ❯ test/unit/webgl/p5.Framebuffer.js:68:18 ❯ Framebuffer.draw src/webgl/p5.Framebuffer.js:1300:5 ❯ test/unit/webgl/p5.Framebuffer.js:64:15

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Framebuffer.js > p5.Framebuffer > formats and channels > framebuffers work with WebGL 1, unsigned-byte rgba unsigned-int depth antialiased

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ Geometry._addSegment src/webgl/p5.Geometry.js:1564:21 ❯ Geometry._edgesToVertices src/webgl/p5.Geometry.js:1449:14 ❯ RendererGL.box src/webgl/3d_primitives.js:2478:17 ❯ fn.box src/webgl/3d_primitives.js:703:20 ❯ p5.box src/core/friendly_errors/param_validator.js:583:23 ❯ test/unit/webgl/p5.Framebuffer.js:68:18 ❯ Framebuffer.draw src/webgl/p5.Framebuffer.js:1300:5 ❯ test/unit/webgl/p5.Framebuffer.js:64:15

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera attributes after resizing > Camera rotation is the same

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ Geometry._addSegment src/webgl/p5.Geometry.js:1564:21 ❯ Geometry._edgesToVertices src/webgl/p5.Geometry.js:1449:14 ❯ RendererGL.rect src/webgl/3d_primitives.js:1907:12 ❯ fn._renderRect src/shape/2d_primitives.js:1369:22 ❯ fn.rect src/shape/2d_primitives.js:1221:17 ❯ p5.rect src/core/friendly_errors/param_validator.js:583:23 ❯ testShape test/unit/webgl/p5.Camera.js:1181:14 ❯ test/unit/webgl/p5.Camera.js:1184:7

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera attributes after resizing > Camera position is the same

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ Geometry._addSegment src/webgl/p5.Geometry.js:1564:21 ❯ Geometry._edgesToVertices src/webgl/p5.Geometry.js:1449:14 ❯ RendererGL.rect src/webgl/3d_primitives.js:1907:12 ❯ fn._renderRect src/shape/2d_primitives.js:1369:22 ❯ fn.rect src/shape/2d_primitives.js:1221:17 ❯ p5.rect src/core/friendly_errors/param_validator.js:583:23 ❯ testShape test/unit/webgl/p5.Camera.js:1150:14 ❯ test/unit/webgl/p5.Camera.js:1153:7

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Vector.js > p5.Vector > array > p5.Vector.prototype.array() [INSTANCE] > should return an with the x y and z components

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ test/unit/math/p5.Vector.js:1583:18

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Vector.js > p5.Vector > array > p5.Vector.prototype.array() [INSTANCE] > should return an array

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ test/unit/math/p5.Vector.js:1579:18

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Matrix.js > p5.Matrix > p5.Matrix3x3 > multiplyVec version 3

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ test/unit/math/p5.Matrix.js:377:31

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Matrix.js > p5.Matrix > p5.Matrix3x3 > column() and row()

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ test/unit/math/p5.Matrix.js:355:22

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Framebuffer.js > p5.Framebuffer > formats and channels > framebuffers work with WebGL 1, unsigned-byte rgba float depth antialiased

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ Geometry._addSegment src/webgl/p5.Geometry.js:1564:21 ❯ Geometry._edgesToVertices src/webgl/p5.Geometry.js:1449:14 ❯ RendererGL.box src/webgl/3d_primitives.js:2478:17 ❯ fn.box src/webgl/3d_primitives.js:703:20 ❯ p5.box src/core/friendly_errors/param_validator.js:583:23 ❯ test/unit/webgl/p5.Framebuffer.js:68:18 ❯ Framebuffer.draw src/webgl/p5.Framebuffer.js:1300:5 ❯ test/unit/webgl/p5.Framebuffer.js:64:15

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Framebuffer.js > p5.Framebuffer > formats and channels > framebuffers work with WebGL 1, unsigned-byte rgba unsigned-int depth antialiased

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ Geometry._addSegment src/webgl/p5.Geometry.js:1564:21 ❯ Geometry._edgesToVertices src/webgl/p5.Geometry.js:1449:14 ❯ RendererGL.box src/webgl/3d_primitives.js:2478:17 ❯ fn.box src/webgl/3d_primitives.js:703:20 ❯ p5.box src/core/friendly_errors/param_validator.js:583:23 ❯ test/unit/webgl/p5.Framebuffer.js:68:18 ❯ Framebuffer.draw src/webgl/p5.Framebuffer.js:1300:5 ❯ test/unit/webgl/p5.Framebuffer.js:64:15

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera attributes after resizing > Camera rotation is the same

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ Geometry._addSegment src/webgl/p5.Geometry.js:1564:21 ❯ Geometry._edgesToVertices src/webgl/p5.Geometry.js:1449:14 ❯ RendererGL.rect src/webgl/3d_primitives.js:1907:12 ❯ fn._renderRect src/shape/2d_primitives.js:1369:22 ❯ fn.rect src/shape/2d_primitives.js:1221:17 ❯ p5.rect src/core/friendly_errors/param_validator.js:583:23 ❯ testShape test/unit/webgl/p5.Camera.js:1181:14 ❯ test/unit/webgl/p5.Camera.js:1184:7

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/webgl/p5.Camera.js > p5.Camera > Camera attributes after resizing > Camera position is the same

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ Geometry._addSegment src/webgl/p5.Geometry.js:1564:21 ❯ Geometry._edgesToVertices src/webgl/p5.Geometry.js:1449:14 ❯ RendererGL.rect src/webgl/3d_primitives.js:1907:12 ❯ fn._renderRect src/shape/2d_primitives.js:1369:22 ❯ fn.rect src/shape/2d_primitives.js:1221:17 ❯ p5.rect src/core/friendly_errors/param_validator.js:583:23 ❯ testShape test/unit/webgl/p5.Camera.js:1150:14 ❯ test/unit/webgl/p5.Camera.js:1153:7

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Vector.js > p5.Vector > array > p5.Vector.prototype.array() [INSTANCE] > should return an with the x y and z components

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ test/unit/math/p5.Vector.js:1583:18

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Vector.js > p5.Vector > array > p5.Vector.prototype.array() [INSTANCE] > should return an array

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ test/unit/math/p5.Vector.js:1579:18

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Matrix.js > p5.Matrix > p5.Matrix3x3 > multiplyVec version 3

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ test/unit/math/p5.Matrix.js:377:31

Check failure on line 2956 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Matrix.js > p5.Matrix > p5.Matrix3x3 > column() and row()

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:2956:5 ❯ test/unit/math/p5.Matrix.js:355:22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently throwing errors in the tests. Inside of classes, we don't have access to a global p5. We do have access to them in the exported addon function body though. In #8176 I dealt with something similar by patching the class in the exported addon function to give it access to these.

Also, once this does work, we probably don't want to flood the user's console with logs if they're using this a bunch every frame. We should maybe track whether or not we've logged this warning yet, and don't log it a second time.

Copy link
Contributor Author

@hxrshxz hxrshxz Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help sharing this pattern made the fix super easy

'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];
}

Expand Down Expand Up @@ -3781,11 +3786,16 @@
* 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(

Check failure on line 3795 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Vector.js > p5.Vector > array > p5.Vector.array() [CLASS] > should return an with the x y and z components

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:3795:5 ❯ test/unit/math/p5.Vector.js:1593:30

Check failure on line 3795 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Vector.js > p5.Vector > array > p5.Vector.array() [CLASS] > should return an array

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:3795:5 ❯ test/unit/math/p5.Vector.js:1589:30

Check failure on line 3795 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Vector.js > p5.Vector > array > p5.Vector.array() [CLASS] > should return an with the x y and z components

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:3795:5 ❯ test/unit/math/p5.Vector.js:1593:30

Check failure on line 3795 in src/math/p5.Vector.js

View workflow job for this annotation

GitHub Actions / test

test/unit/math/p5.Vector.js > p5.Vector > array > p5.Vector.array() [CLASS] > should return an array

ReferenceError: p5 is not defined ❯ Vector.array src/math/p5.Vector.js:3795:5 ❯ test/unit/math/p5.Vector.js:1589:30
'array() is deprecated and will be removed in a future version of p5.js.',
'p5.Vector.array'
);
return v.array();
}

Expand Down
Loading