mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Enhanced lerp() to allow list/range u values to return lists of results.
This commit is contained in:
parent
bb92d788ef
commit
9f92fe8775
3 changed files with 6 additions and 3 deletions
|
@ -319,9 +319,10 @@ function segs(r) =
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// a = First value.
|
// a = First value.
|
||||||
// b = Second 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) =
|
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()
|
// Function: hypot()
|
||||||
|
|
|
@ -219,6 +219,8 @@ module test_lerp() {
|
||||||
assert(lerp(-20,20,0.5) == 0);
|
assert(lerp(-20,20,0.5) == 0);
|
||||||
assert(lerp(-20,20,0.75) == 10);
|
assert(lerp(-20,20,0.75) == 10);
|
||||||
assert(lerp(-20,20,1) == 20);
|
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]);
|
assert(lerp([10,10],[30,-10],0.5) == [20,0]);
|
||||||
}
|
}
|
||||||
test_lerp();
|
test_lerp();
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,42];
|
BOSL_VERSION = [2,0,43];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
Loading…
Reference in a new issue