def runs.over

gralha-coverage@0.1.0.1 · cover.bend:111

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

111# The mask's coverage over the grid rectangle [x0, x1) by [y0, y1) when it is
112# uniform (2 means "unvisited", so an empty rectangle reads as uniform 0), else -1.
113# The uniform value of runs over the columns [x0, x1): a run covering them
114# all gives its value, none touching them gives 0, anything else -1.
115def runs.over(rs: List<&2, Run>, +x0: U32, +x1: U32, +acc: F32) -> F32:
116  match rs:
117    case Nil{}: U.choose(F32, F32.is_gt(acc, 1.5), 0.0, acc)
118    case Con{Run{a, b, v}, rest}:
119      +aa = a
120      +bb = b
121      +vv = v
122      +overlaps = U32.is_lt(aa, x1) && U32.is_lt(x0, bb)
123      +covers = U32.is_le(aa, x0) && U32.is_ge(bb, x1)
124      runs.over(rest, x0, x1, U.choose(F32, Bool.not(overlaps), acc, U.choose(F32, covers && F32.is_gt(acc, 1.5), vv, F32.neg(1.0))))

Uses (12)

Used by (1)