Enhanced lerp() to allow list/range u values to return lists of results.

This commit is contained in:
Revar Desmera 2019-11-18 21:11:38 -08:00
parent bb92d788ef
commit 9f92fe8775
3 changed files with 6 additions and 3 deletions

View file

@ -319,9 +319,10 @@ function segs(r) =
// Arguments:
// a = First value.
// b = Second value.
// u = The proportion from `a` to `b` to calculate. Valid range is 0.0 to 1.0, inclusive.
// u = The proportion from `a` to `b` to calculate. Valid range is 0.0 to 1.0, inclusive. If given as a list or range of values, returns a list of results.
function lerp(a,b,u) =
(1-u)*a + u*b;
is_num(u)? (1-u)*a + u*b :
[for (v = u) lerp(a,b,v)];
// Function: hypot()

View file

@ -219,6 +219,8 @@ module test_lerp() {
assert(lerp(-20,20,0.5) == 0);
assert(lerp(-20,20,0.75) == 10);
assert(lerp(-20,20,1) == 20);
assert(lerp(-20,20,[0,0.25,0.5,0.75,1]) == [-20,-10,0,10,20]);
assert(lerp(-20,20,[0:0.25:1]) == [-20,-10,0,10,20]);
assert(lerp([10,10],[30,-10],0.5) == [20,0]);
}
test_lerp();

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,42];
BOSL_VERSION = [2,0,43];
// Section: BOSL Library Version Functions