def piece.cuts

gralha-coverage@0.1.0.1 · cover.bend:661

import gralha-coverage@0.1.0.1/cover.bend as Cover
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U

661def piece.cuts(done: Bool, n: Nat, +xa: F32, +ya: F32, +xb: F32, +yb: F32, +dir: F32, +slope: F32, +w: U32, b: (Array<F32> & Array<U32>) & (U32 & U32)) -> (Array<F32> & Array<U32>) & (U32 & U32):
662  match done:
663    case True{}: b
664    case False{}:
665      match n:
666        case 0n: b
667        case 1n+d:
668          +ahead = F32.is_le(xa, xb)
669          +i = U.choose(F32, ahead, F32.floor(xa), (F32.ceil(xa) - 1.0 : F32))
670          +right = (i + 1.0 : F32)
671          +bound = U.choose(F32, ahead, right, i)
672          +full = U.choose(Bool, ahead, F32.is_le(xb, bound), F32.is_ge(xb, bound))
673          +xc = U.choose(F32, full, xb, bound)
674          +yc = U.choose(F32, full, yb, U.choose(F32, F32.is_lt(F32.abs(slope), 0.000001), yb, (ya + (xc - xa) / slope : F32)))
675          +dy = (yc - ya : F32)
676          piece.cuts(full, d, xc, yc, xb, yb, dir, slope, w,
677            buf.put.if(F32.is_eq(dy, 0.0), b, F32.to_u32(U.max(i, 0.0)), (dir * dy * (right - (xa + xc) * 0.5) : F32), (dir * dy : F32), w))

Uses (21)

Used by (1)