diff --git a/basis/math/vectors/vectors-tests.factor b/basis/math/vectors/vectors-tests.factor index b4b12d619b..968af6a3aa 100644 --- a/basis/math/vectors/vectors-tests.factor +++ b/basis/math/vectors/vectors-tests.factor @@ -14,3 +14,5 @@ USING: math.vectors tools.test ; [ { 1.75 1.75 } ] [ { 1.0 2.5 } { 2.5 1.0 } 0.5 vnlerp ] unit-test [ { 1.75 2.125 } ] [ { 1.0 2.5 } { 2.5 1.0 } { 0.5 0.25 } vlerp ] unit-test + +[ 1.125 ] [ 0.0 1.0 2.0 4.0 { 0.5 0.25 } bilerp ] unit-test diff --git a/basis/math/vectors/vectors.factor b/basis/math/vectors/vectors.factor index eb203a5f12..17f6c39f04 100644 --- a/basis/math/vectors/vectors.factor +++ b/basis/math/vectors/vectors.factor @@ -41,6 +41,10 @@ IN: math.vectors : set-axis ( u v axis -- w ) [ [ zero? 2over ? ] dip swap nth ] map-index 2nip ; +: bilerp ( aa ba ab bb {t,u} -- a_tu ) + [ first lerp ] [ second lerp ] bi-curry + [ 2bi@ ] [ call ] bi* ; + : vlerp ( a b t -- a_t ) [ lerp ] 3map ; diff --git a/extra/terrain/terrain.factor b/extra/terrain/terrain.factor index 083b162c01..d58aa4ec30 100644 --- a/extra/terrain/terrain.factor +++ b/extra/terrain/terrain.factor @@ -155,7 +155,7 @@ TUPLE: terrain-world < world pixel dim pixel-indices :> indices indices [ pixels nth COMPONENT-SCALE v. 255.0 / ] map - first4 [ pixel-mantissa first lerp ] 2bi@ pixel-mantissa second lerp ; + first4 pixel-mantissa bilerp ; : collide ( segment location -- location' ) [ [ first ] [ third ] bi 2array terrain-height-at PLAYER-HEIGHT + ]