Skip to content

Fix/issue 8924 - #9009

Open
solowiz398 wants to merge 5 commits into
processing:mainfrom
solowiz398:fix/issue-8924
Open

Fix/issue 8924#9009
solowiz398 wants to merge 5 commits into
processing:mainfrom
solowiz398:fix/issue-8924

Conversation

@solowiz398

Copy link
Copy Markdown

Resolves #8924

PROBLEM DESCRIPTION

The setter method of 'x' for a 1 dimension vector does not reflect any changes to its value.

Vector dimensions are stored in an array, the set method of x checks to see if the length of the array is greater than 1. The condition passes for a 2d vector but fails for a 1d vector

SOLUTION

Updated the setter method for 'x' to check to see if the length of the array is greater than 0. This condition passes for both a 1d vector and n amount of vector

HOW TO TEST

1. Verify the fix on this branch

npm test -- test/unit/math/p5.Vector.js

Ensure the following unit test passes:

'should show a value change for x with toString() for 1d Vector'

Changes:

  • Fixed setter method for x in p5.Vector.js to allow setting values for 1d vector length > 0
  • Added a unit test to verify value change for 'x'

Screenshots of the change:
Non visual code and unit test

PR Checklist

@solowiz398
solowiz398 marked this pull request as ready for review July 23, 2026 19:31
@p5-bot

p5-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: 4e2435f

Previous deployments

This is an automated message.

@ksen0 ksen0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One minor thing, otherwise thanks, happy to include this in the next patch!

Comment thread test/unit/math/p5.Vector.js Outdated
v = new Vector(1);
v.x = 2;
let output = v.toString();
assert.equal(output, 'vector[2]');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Please update to match the style of other tests using expect to be (and removing the assert dep, I don't think it would be needed?)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks @ksen0 I just made the changes. Let me know if there's anything else

Replaced assert.equal with expect in p5.Vector tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: p5.Vector.x set doesn't work on 1D vector

2 participants