extends RefCounted
## THROUGH-DEPTH (#120 L2 §13.3; BoxCutter's lazorcut): how deep a cutter drawn on a plane
## must go to pass right through its targets.
##
## The farthest any target piece reaches below the plane (its corners projected on −n),
## plus `margin` (the tool passes one grid step), so the far face is cut cleanly rather
## than left as a skin. The maximum over the WHOLE target is safe: extra depth only cuts
## where the cutter overlaps the target, so a deep part elsewhere costs nothing.
##
## Measured ONCE, at commit, and stored as a number (not re-measured in the fold, which
## would make it depend on the targets' state in a new way).
## `pieces` = plane sets (PackedFloat32Array, n·x <= d); `origin` / `normal` = the drawn
## plane, its normal pointing OUT of the targets. 0 when nothing lies below the plane.
static func through(pieces: Array, origin: Vector3, normal: Vector3, margin: float) -> float:
var down := -normal.normalized()
var deepest := 0.0
for pl: Variant in pieces:
for c: Vector3 in FaceKit.corners(pl as PackedFloat32Array):
deepest = maxf(deepest, down.dot(c - origin))
return deepest + margin if deepest > 1.0e-4 else 0.0