def lines.on.box

gralha-coverage@0.1.0.1 · cover.bend:1186

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

1186# Zero-length lines (a path's move and close) are ignored; the four real ones must lie on the box.
1187def lines.on.box(xs: List<&2, CovLine>, +x0: F32, +y0: F32, +x1: F32, +y1: F32, +count: U32) -> Bool:
1188  match xs:
1189    case Nil{}: U32.is_eq(count, 4)
1190    case Con{CovLine{ax, ay, bx, by}, rest}:
1191      +axx = ax
1192      +ayy = ay
1193      +bxx = bx
1194      +byy = by
1195      +empty = F32.is_eq(axx, bxx) && F32.is_eq(ayy, byy)
1196      (empty || line.on.box(axx, ayy, bxx, byy, x0, y0, x1, y1)) && lines.on.box(rest, x0, y0, x1, y1, U.choose(U32, empty, count, (count + 1 : U32)))

Uses (12)

Used by (1)