lerp
Linearly interpolates between two given values. In particular, we define lerp somewhat recursively. If we are interpolating between two numbers, then the interpolated value is calculated as (1-t) * a + t * b
. Otherwise, suppose we are interpolating between two vectors. Then, the resultant value is defined to be the recurisively lerped value of each of the individual entries. In particular, both vectors must be of the same length. Then, suppose both a and b are functors. We say two functors match if they were spawned by the same function (in practice, if you give two functors who were spawned by different functions but whose argument labels are all identical, lerp will still probably succeed, but for simplicity we present it as the preceeding definition). If a and b match acording to our definition, then we are able to lerp between a and b by lerping on the individual subfields. Finally, suppose that a is a functor wrapping a vector and b is a vector (or vice versa), then we will interpolate as if we had two vectors. Likewise if we have a functor wrapping a number and the other field being a number. If none of the following criteria are met, then an error will be thrown. In particular, if at any point lerp encounters a map, two vectors of differing lengths, or a character (typically from a string), then an error will be thrown.
Interpolation is one of the cornerstones of Monocurl, and to master Monocurl is to master interpolation. While you might not use this function directly, you might use the Lerp animation a lot, and the semantics of that animation are precisely the same as this function. Therefore, it is important to know the semantics of how lerp behaves.
An important consideration is that when interpolating between two functors, lerp will skip any values that are equal (in fact, when lerping anything it will skip it if they're equal, but the biggest conseuquence is when we are lerping functors). This might not appear to be a big deal, but it is actually important because now we can lerp between two functors that have a string as one of their arguments, so long as that particular argument is equal for both functors. Had we done a naive interpolation on the equal values, we would receive an error because we wouldn't be able to lerp between the strings, even though they aer equal. Thus, you are free to lerp functors that have arguments that are not lerpable, so long as they are equal in both functors.
a | the starting value to interpolate |
b | the ending value to interpolate |
t | the amount we should bias towards b in the interpolation. Expected to be in the closed interval [0,1] (though as of this writing, this is not actually enforced and one is free to go outside this interval, in which case extrapolation is done) |
the interpolated value according to the above procedure
func lerp(a, b, t)