Skip to content

Vector lerp() function now takes in generalized dimensions#8994

Open
mawerb wants to merge 12 commits into
processing:mainfrom
mawerb:vector-lerp-generalize-dimensions
Open

Vector lerp() function now takes in generalized dimensions#8994
mawerb wants to merge 12 commits into
processing:mainfrom
mawerb:vector-lerp-generalize-dimensions

Conversation

@mawerb

@mawerb mawerb commented Jul 20, 2026

Copy link
Copy Markdown

Resolves #8927

Changes:

  • Refactored lerp() to take in generalized dimensions allowing for function to be called on vectors with more than 3 dimensions and mismatched.
  • Refactored _validatedVectorOperation decorator to be able to take in trailingArgs in order to fit the case of lerp() where it follows the pattern of validating parameters its taking with ...args like the mult(), add(), sub() functions but requiring the extra argument amt
  • Added test for prioritizing smaller dimensions for lerp()
  • Refactored tests dependent on passing of 4 arguments to fit the new structure of taking in a vector, array, or number list
  • Added tests mentioned in issue [p5.js 2.0+ Bug Report]: Vector.lerp() is hard coded to use three dimensions #8927 and extra to ensure lerp() works as intended on mismatched dimensions and vectors with dimensions > 3

Screenshots of the change:
Screenshot 2026-07-20 at 3 57 17 PM

the 1 failed test was present before changes were made (it's the typography test)

PR Checklist

@p5-bot

p5-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: ec21120

Previous deployments

a53af53


This is an automated message.

@perminder-17 perminder-17 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good!

Comment thread src/math/patch-vector.js Outdated

@perminder-17 perminder-17 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Everything else looks good so far!

Comment thread src/math/p5.Vector.js Outdated
Comment on lines +2373 to +2382
* // META:norender
* function setup() {
* // Create a p5.Vector object.
* let v = createVector(1, 1, 1);
*
* // Interpolate with an array.
* v.lerp([3, 3, 3], 0.5);
*
* // Prints "p5.Vector Object : [2, 2, 2]" to the console.
* print(v.toString());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One thought: if someone reads these examples, they have to open the console to see the output. Since multiple examples use the console, the messages can get mixed up. What do you think about using the text() function instead, so the output is shown directly on the canvas?

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, agreed, switched the lerp examples to show the result on the canvas with text() so readers don’t need the console.

@mawerb
mawerb force-pushed the vector-lerp-generalize-dimensions branch from 627e97a to ec21120 Compare July 22, 2026 15:47
@ksen0

ksen0 commented Jul 22, 2026

Copy link
Copy Markdown
Member

This is looking really good, thanks both!

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]: Vector.lerp() is hard coded to use three dimensions

3 participants