Skip to content

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

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

Vector lerp() function now takes in generalized dimensions#8994
mawerb wants to merge 8 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: a53af53

Previous deployments

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
Comment on lines +58 to +64
if (!this.friendlyErrorsDisabled()) {
this._friendlyError(
'Requires valid arguments',
'p5.Vector'
);
}
return this;

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.

I think this code is repeated six times in this function. Can we create a helper function that takes the message as an argument? Then we can replace these repeated lines with a single helper call. That way we can reduce the code?

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

2 participants