def transfer.apply

gralha-svg-render@0.1.0.1 · svg.bend:4514

import gralha-svg-render@0.1.0.1/svg.bend as Svg
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U

4514def transfer.apply(+t: Transfer, +x: F32) -> F32:
4515  Transfer{kind, vs, count, a, b, c} = t
4516  +last = U.choose(U32, U32.is_eq(count, 0), 0, (count - 1 : U32))
4517  +position = (U.clamp(x, 0.0, 1.0) * U32.to_f32(last) : F32)
4518  +index = F32.to_u32(F32.floor(position))
4519  +left = U.nth(vs, U32.to_nat(index), x)
4520  U.branch(F32, U32.is_eq(kind, 1) && U32.is_gt(count, 0), _ => (left + (U.nth(vs, U32.to_nat(U32.inc(index)), left) - left) * (position - U32.to_f32(index)) : F32),
4521    _ => U.branch(F32, U32.is_eq(kind, 2) && U32.is_gt(count, 0), _ => U.nth(vs, U32.to_nat(F32.to_u32(U.min(U32.to_f32(last), F32.floor((U.clamp(x, 0.0, 1.0) * U32.to_f32(count) : F32))))), x),
4522      _ => U.branch(F32, U32.is_eq(kind, 3), _ => (a * x + b : F32), _ => U.branch(F32, U32.is_eq(kind, 4), _ => (a * F32.pow(U.max(x, 0.0), b) + c : F32), _ => x))))

Uses (22)

Used by (1)