def natural_sweep

bend-visgraph@2.0.0.0 · visgraph.bend:697

import bend-visgraph@2.0.0.0/visgraph.bend as Visgraph
import Base

697# The sweep of point a over the points right of it: ts2vg's inner loop. A
698# point b the sweep sees replaces the smallest top and adds its edge at the
699# next step, when `up` says so, so a step after an unseen point calls no
700# def that recurses.
701def natural_sweep(pts: Pts, up: Bool, +dir: Direction, +k: Weight, +lo: F32, +hi: F32, +ia: U32, +xa: F32, +ya: F32, +scale_a: F32, +ts: Tops, low: Low, +ib: U32, +xb: F32, +yb: F32, +sb: F32, es: Edges) -> Edges:
702  match pts up:
703    case PNil{} False{}:
704      es
705    case PNil{} True{}:
706      natural_edge(dir, k, lo, hi, ia, ib, xa, xb, ya, yb, sb, scale_a, ts, es)
707    case PCon{+ic, +xc, +yc, next} False{}:
708      Low{+lk, +lv} = low
709      +s = F32.div(F32.sub(yc, ya), F32.sub(xc, xa))
710      natural_sweep(next, clears(F32.is_gt(s, lv), s, lv, scale_a, xc, yc), dir, k, lo, hi, ia, xa, ya, scale_a, ts, Low{lk, lv}, ic, xc, yc, s, es)
711    case PCon{+ic, +xc, +yc, next} True{}:
712      Low{+lk, lv} = low
713      +after = set_at(lk, ts, sb)
714      +now = lowest(after)
715      +s = F32.div(F32.sub(yc, ya), F32.sub(xc, xa))
716      natural_sweep(next, clears(F32.is_gt(s, Low.v(now)), s, Low.v(now), scale_a, xc, yc), dir, k, lo, hi, ia, xa, ya, scale_a, after, now, ic, xc, yc, s, natural_edge(dir, k, lo, hi, ia, ib, xa, xb, ya, yb, sb, scale_a, ts, es))

Uses (17)

Used by (1)