Cover.runs.over: def of gralha-coverage@0.1.0.1 Import: import gralha-coverage@0.1.0.1/cover.bend as Cover Lines 111-124 of gralha-coverage@0.1.0.1/cover.bend: https://jend.leeeet.dev/read.txt?path=gralha-coverage@0.1.0.1/cover.bend&start_line=111&end_line=124 import Base import gralha-text-scan@0.1.0.1/scan.bend as U # The mask's coverage over the grid rectangle [x0, x1) by [y0, y1) when it is # uniform (2 means "unvisited", so an empty rectangle reads as uniform 0), else -1. # The uniform value of runs over the columns [x0, x1): a run covering them # all gives its value, none touching them gives 0, anything else -1. def runs.over(rs: List<&2, Run>, +x0: U32, +x1: U32, +acc: F32) -> F32: match rs: case Nil{}: U.choose(F32, F32.is_gt(acc, 1.5), 0.0, acc) case Con{Run{a, b, v}, rest}: +aa = a +bb = b +vv = v +overlaps = U32.is_lt(aa, x1) && U32.is_lt(x0, bb) +covers = U32.is_le(aa, x0) && U32.is_ge(bb, x1) 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): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.not https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.is_gt https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.neg https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_ge https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_le https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.is_lt https://jend.leeeet.dev/definition.txt?path=gralha-coverage@0.1.0.1/cover.bend&name=Run https://jend.leeeet.dev/definition.txt?path=gralha-text-scan@0.1.0.1/scan.bend&name=choose