Vector lerp() function now takes in generalized dimensions#8994
Vector lerp() function now takes in generalized dimensions#8994mawerb wants to merge 11 commits into
Conversation
Continuous ReleaseCDN linkPublished PackagesCommit hash: a53af53 Previous deploymentsThis is an automated message. |
| if (!this.friendlyErrorsDisabled()) { | ||
| this._friendlyError( | ||
| 'Requires valid arguments', | ||
| 'p5.Vector' | ||
| ); | ||
| } | ||
| return this; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Nice catch, made the change! Thanks for reviewing my pr :)
perminder-17
left a comment
There was a problem hiding this comment.
Everything else looks good so far!
| * // 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()); |
There was a problem hiding this comment.
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?
Resolves #8927
Changes:
lerp()to take in generalized dimensions allowing for function to be called on vectors with more than 3 dimensions and mismatched._validatedVectorOperationdecorator to be able to take in trailingArgs in order to fit the case oflerp()where it follows the pattern of validating parameters its taking with ...args like themult(),add(),sub()functions but requiring the extra argumentamtlerp()works as intended on mismatched dimensions and vectors with dimensions > 3Screenshots of the change:

the 1 failed test was present before changes were made (it's the typography test)
PR Checklist
npm run lintpasses