P5.1: drag → adjacent-swap intent mapping (pure sx)
Add swipe.sx: a pure swipe_intent(layout, start, end) -> ?Swap that turns a touch drag into an optional adjacent-swap intent (A, B). A is the cell under the drag start (via BoardLayout.point_to_cell); B is its orthogonal neighbour along the drag's dominant axis (larger of |dx|,|dy|, ties horizontal). Returns null for sub-threshold drags (a tap, threshold = cell_size * 0.5), starts off the board, or neighbours off the board. No rendering, no model mutation. Lock the logic with tests/swipe_intent.sx (+ expected golden), feeding synthetic down/up positions for right/left/up/down, sub-threshold tap, diagonal→dominant (both axes), edge-outward off-board, and start-off-board. bash tools/run_tests.sh passes (13/13); sx build --target ios-sim main.sx compiles.
This commit is contained in:
1
tests/expected/swipe_intent.exit
Normal file
1
tests/expected/swipe_intent.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
12
tests/expected/swipe_intent.stdout
Normal file
12
tests/expected/swipe_intent.stdout
Normal file
@@ -0,0 +1,12 @@
|
||||
grid origin (100,0) cell 75 threshold 37
|
||||
right: (3,5)->(4,5)
|
||||
left: (3,5)->(2,5)
|
||||
up: (3,5)->(3,4)
|
||||
down: (3,5)->(3,6)
|
||||
short: none
|
||||
diag-horizontal: (3,5)->(4,5)
|
||||
diag-vertical: (3,5)->(3,4)
|
||||
offboard-right: none
|
||||
offboard-up: none
|
||||
start-offboard: none
|
||||
ok: swipe-intent mapping resolves all cases
|
||||
Reference in New Issue
Block a user