You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[p5.js 2.0+ Bug Report]: Vector.lerp() is hard coded to use three dimensions #8927
Note the result only works for the first three dimensions
Snippet:
functionsetup(){letv1=createVector(0,1,0,1);letv2=createVector(1,0,1,0);v1.lerp(v2,0.5);// v1 should be vector[0.5, 0.5, 0.5, 0.5], but is actually vector[0.5, 0.5, 0.5, 1]print(v1.toString());}
Discussion
lerp() currently computes x, y, and z individually. To extend to vectors of any dimension, other vector methods can be used, like p5.Vector.add(v1, p5.Vector.sub(v2, v1).mult(c)). Of course, this needs to be adapted to both the instance and static methods.
Hi everyone, this is reserved for the CodeDay microinternship. If it is not completed by them, then it can be opened to volunteers. But for now, please do not make PRs or volunteer - thanks for understanding!
The solution should generalize lerp() to N dimensions:
add unit tests checking behavior for beyond 3d dimensionalities, as well as for operations between vectors of mismatched dimensions
when performing binary operation on vectors of different dimensions, use smallest vector priority: check the implementation of add, sub, div, mult, rem and their behavior on mismatched sized vectors
The dot method may be a better pattern to follow for this than add, sub, etc. But it is a bit tricky since the last parameter is the interpolation amount, not part of the second vector.
The add, sub, div, mult, and rem methods also allow an array parameter. To understand how this works requires knowing that a decorator _validatedVectorOperation is applied to them in patch-vector.js. This is not obvious from the code in p5.Vector.js.
Hi @mawerb, thanks for raising this PR! However, since this issue is currently reserved for the CodeDay microinternship. If it isn't completed by them, we can definitely revisit and review your code then. Thanks so much for your understanding and for your contribution!
Activity
ksen0 commentedon Jun 17, 2026
Hi everyone, this is reserved for the CodeDay microinternship. If it is not completed by them, then it can be opened to volunteers. But for now, please do not make PRs or volunteer - thanks for understanding!
The solution should generalize
lerp()to N dimensions:sidwellr commentedon Jun 24, 2026
The solution should also update the documentation to match the new behavior.
Also, lerp needs to allow the second vector to be specified using a list of numbers. For example, the following code should print "vector[2,2]":
The dot method may be a better pattern to follow for this than add, sub, etc. But it is a bit tricky since the last parameter is the interpolation amount, not part of the second vector.
The add, sub, div, mult, and rem methods also allow an array parameter. To understand how this works requires knowing that a decorator
_validatedVectorOperationis applied to them in patch-vector.js. This is not obvious from the code in p5.Vector.js.perminder-17 commentedon Jul 20, 2026
Hi @mawerb, thanks for raising this PR! However, since this issue is currently reserved for the CodeDay microinternship. If it isn't completed by them, we can definitely revisit and review your code then. Thanks so much for your understanding and for your contribution!
mawerb commentedon Jul 20, 2026
Hi, @perminder-17. I am a student under the CodeDay SOSE microinternship. I am part of the team that was assigned to the issue!
perminder-17 commentedon Jul 20, 2026
Thanks for letting me know, I'll review the PR then. :")