extends SceneTree
## GATE — THROUGH-DEPTH (#120 L2 §13.3, cut_depth.gd).
## T1 a slab y 0..2, drawn on its top (y 2, normal +y): depth 2 + the margin
## T2 a stepped target (a second piece down to y -1): it reaches the deepest piece
## T3 two targets: the deeper one decides
## T4 drawn on a side face (normal +x): depth = the slab's width + margin
## T5 the target wholly on the outer side: 0 (the tool then keeps its set depth)
## T6 a plane floating above the target: down to its bottom
##
## RUN: CI=true HYPERTPS_DAEMON_TCP=127.0.0.1:1 "$GODOT" --headless --path . --script res://scenes/test/gate_cut_through.gd
const CutDepth := preload("res://scenes/maps/cut_depth.gd")
var fails := 0
var checks := 0
func _p(c: bool, m: String, got: Variant = "") -> void:
checks += 1
if not c:
fails += 1
print(" %-62s %s %s" % [m, "OK" if c else "**FAIL**", str(got)])
func _box(a: Vector3, b: Vector3) -> PackedFloat32Array:
return PackedFloat32Array([-1, 0, 0, -a.x, 1, 0, 0, b.x, 0, -1, 0, -a.y, 0, 1, 0, b.y, 0, 0, -1, -a.z, 0, 0, 1, b.z])
func _initialize() -> void:
var slab := _box(Vector3(0, 0, 0), Vector3(4, 2, 4))
var up := Vector3.UP
var d1 := CutDepth.through([slab], Vector3(2, 2, 2), up, 0.25)
_p(is_equal_approx(d1, 2.25), "T1 a slab drawn on its top: 2 + 0.25", d1)
var step := _box(Vector3(0, -1, 0), Vector3(1, 0, 1))
var d2 := CutDepth.through([slab, step], Vector3(2, 2, 2), up, 0.25)
_p(is_equal_approx(d2, 3.25), "T2 a stepped target: down to its deepest piece", d2)
var deep := _box(Vector3(10, -3, 0), Vector3(12, 2, 2))
var d3 := CutDepth.through([slab, deep], Vector3(2, 2, 2), up, 0.25)
_p(is_equal_approx(d3, 5.25), "T3 two targets: the deeper one decides", d3)
var d4 := CutDepth.through([slab], Vector3(4, 1, 2), Vector3.RIGHT, 0.25)
_p(is_equal_approx(d4, 4.25), "T4 drawn on the side face: the width + 0.25", d4)
# The target wholly on the plane's OUTER side (the normal points at it): nothing to cut.
var d5 := CutDepth.through([slab], Vector3(2, -5, 2), up, 0.25)
_p(d5 == 0.0, "T5 the target wholly above the plane: 0", d5)
# A plane floating above the slab still has all of it below: through reaches its bottom.
var d6 := CutDepth.through([slab], Vector3(2, 5, 2), up, 0.25)
_p(is_equal_approx(d6, 5.25), "T6 a plane above the slab: down to its bottom", d6)
print("\nGATE cut_through: %s (%d checks, %d failed)" % ["PASS" if fails == 0 else "FAIL", checks, fails])
quit(0 if fails == 0 else 1)