WP-091: Hotspot Magnet directional algorithm — rules, reachability and test cases

Status: ✅ Done (2026-11-28). All 16 exit criteria are met (§Close); Jeff decided its proposals H17–H24 on 2026-11-28. Findings landed in the plan’s:

Companion EC: EC-013. Pre-flight required: No. A design packet. It reads the fork’s source and published references, and writes only:

It changes nothing under engines/terraglyph/**, docs/formats/** or tools/**, and classifies no title’s generation. Targets generation(s): none for the core, which carries no generation; the room layouts it tests against are Gen 1 (Showdown, Phantom). Estimated effort: about one working day (6–8 hours) across the EC’s steps. Actual: one session, 2026-11-28. Two web reads of the prior art ran in parallel, and a local scratch check tested the rules (Notes).


Goal

Design the navigation core: the pure function that picks the next target. Its inputs are the targets, the current selection, the cursor’s position, a direction, and whether the press is a repeat.

The output is the plan’s §5, with rules precise enough that packet 4 can write the C++ by hand without choosing anything:

It also gives:

Background

Scope

In scope

All reading is at a pinned fork commit, recorded in EC-013 Step 0. The default is origin/scooby-engine at its tip on the execution date.

  1. Re-pin and drift.
    • Record the pinned commit in plan §3.8 and the Part II status line.
    • List every file changed since 0d5a69c7694f, and record each change that alters a finding or a citation.
    • Give every room class added since then its own §6.8 row, citing a new evidence row (E45 onward) at the new pin: Wizard’s Rule, KST and any later one. E35 and E36 stay as they are. For Wizard’s Rule, the row says whether the bottles are an eligible kind or need the class’s target hook.
  2. Prior art (plan Appendix E, first filled here). Read Android’s focus search, the CSS Spatial Navigation draft and Lab’s cycle. Record for each:
    • what it filters on;
    • how it scores;
    • what it does with nothing in a direction;
    • whether it claims reachability.

    External sources go in Appendix E, not in the fork evidence register.

  3. The origin of a press (§5.1, §5.5). Say which point a press measures from in each of these cases, and which side decides each, the provider or the core:
    • with a selection: that target’s point;
    • with a selection but the cursor elsewhere: after a mouse move on Windows, a trip into cursor mode, or a point re-searched after its sprite moved. Either drop the selection or measure from the target;
    • with none: the cursor’s position;
    • with none, the cursor over a target: the core can’t tell (it needs a hit test). Recommended: the provider passes that target as current;
    • after a room change, a close-up, a scene, a dialog or the main menu. Settle the §5.6 / §4.4 contradiction, and make §5.5 and §5.6 agree with the result.

    Any change to what the provider passes is raised as a row, not made to the contract.

  4. The candidate filter (§5.1). Say which targets lie “in” a direction from the origin: a half-plane, a cone of a stated angle, or another rule. State the boundary cases (on the axis, on the cone’s edge) exactly, with the screen’s y axis pointing down.
  5. Scoring and tie-breaking (§5.2).
    • Give the score as a formula over the origin and the candidate’s point: alignment, distance and their weights.
    • Use integer arithmetic only (squared distances, dot and cross products). Otherwise near-ties could break differently on x86 and ARM, and the 4 px grid makes exact ties common.
    • Say whether HotspotInfo::type (exit or object) changes anything.
    • Give a tie-break that is total and independent of list order, for example by point (y, then x).
  6. Nothing in the direction, and wrap (§5.3, §5.4).
    • Say what a press with no candidate does: stay, wrap to the far side, or a deterministic fallback.
    • Say whether a repeat does the same.
    • Name the default, and whether it’s fixed or configurable.
  7. The reachability guarantee (§5.8). One of these is required:
    • an argument that items 3–6, applied to any set of distinct on-screen points with presses only, always give a strongly connected graph;
    • a deterministic alternative that makes it so, added and argued;
    • a plain statement that points alone can’t guarantee it, with H2’s condition (b) raised as a register row.

    In every case, also state:

    • reachability over the directions a room leaves to the core, so a room class that takes some (H11) is covered;
    • that no selection is never a trap. The no-selection rule must be total, so that any press with a non-empty list selects something. Then every target is reachable from any cursor position;
    • that a repeat never needs to differ for reachability to hold;
    • the shape of the worst case: the most presses between two targets for the list sizes Gen 1 has.
  8. Repeat policy (§6.3).
    • Give the adapter’s repeat delay and interval in ticks, or “never”. Say how a repeat differs from a press, if it does.
    • Say why, for a child on a remote with no hardware repeat.
    • Say how the policy handles a press reported twice (E33).
    • Replace §6.3’s “a start while the direction is already held” sentence, so §6.3 agrees with §4.3.
  9. Special cases (§5.3). Give a rule or a worked answer for each:
    • overlapping and nested sprites (distinct points, close together);
    • a large object represented by one point;
    • closely spaced targets;
    • one target, and none;
    • targets in a row or a column (the menus);
    • targets at equal distance;
    • equal points. Recommended: packet 5’s provider guarantees distinct points, for example by merging a class target with the room target of the same sprite (ButtonRoom’s buttons are room sprites). Raised as a row rather than handled in the core;
    • targets outside the view. Answered by a cross-reference: §4.5 drops them.
  10. Performance (§5.7).
    • State the core’s cost per press in the number of targets.
    • State the largest list Gen 1 can give, from the self-test’s room sprite counts or probe_art.py’s placement counts.
    • Confirm the core does no per-frame work.
  11. Navigation examples (plan Appendix C). Write a set of named synthetic layouts. Each is a list of points (and types where it matters), with every (origin, direction, repeat) case worth testing and its expected result.
    • Layouts to include:
      • the diagonal of three;
      • an isolated target;
      • a dense cluster;
      • a row, a column and a grid;
      • a wide gap;
      • the screen’s edges;
      • no selection, from several cursor positions;
      • at least one layout shaped like a real Gen 1 room: the main menu, and the open toolbar’s row with room objects above it.
    • Coverage: together the cases cover each rule of items 3–9.
    • Form: written so packet 4 can transcribe them one-to-one into CxxTest cases. Expected results are worked by hand from the rules.
  12. Where the core’s tests run. Recommend one of:
    • CxxTest cases under test/engines/terraglyph/. This adds a block to the shared test/module.mk, against §7.1’s default. Weigh linking only the core’s object file against all of libterraglyph.a;
    • the engine’s self-test;
    • both.

    Say what the choice means for H4’s later move of the core to engines/.

  13. The per-room reachability check (§5.8, §12.7). Design the check that packet 5 runs on the listing hook’s output for every room of both titles:
    • The graph it builds: each target × each direction the room leaves to the core (the class’s hook asked per room and direction), from presses only.
    • The connectivity test.
    • Order independence: the graph is built under two list orders (as given, and reversed), and the two must be the same.
    • States checked: each room as it starts, and again with the toolbar open (a UI state, not play progress), or a reason why not.
    • No selection: a smoke check from a grid of cursor positions. The guarantee itself is item 7’s argument.
    • On failure it reports: the room, the stranded targets, and the presses that reach them or don’t.
    • Where it runs: the debug channel and level.
    • Option off: state that with Hotspot Assist off the core and the listing hook never run and input is today’s (§6.6, H16), and name the §12.4 regression test that shows it.

    Say what it can’t cover (states reached by play, a graph changing between presses), and point those at the live tests (§12.2).

  14. Decision register (plan §10.4). Add a row, H17 onward, for each choice this design makes that H1–H16 don’t cover. That includes at least items 3 (who decides the hovered target), 4, 5, 6, 8, 9 (equal points) and 12. Each row has alternatives, a recommendation and its evidence. Status is proposed; Jeff decides each. The plan marks each such choice “proposed (Hn)” where it’s stated.

Out of scope

Dependencies

Investigation plan

EC-013 runs these steps in order:

  1. Pin and drift, including the new room classes’ §6.8 rows.
  2. The prior art.
  3. The rules, in order: origin, filter, score and tie, nothing in the direction and wrap, repeats, special cases.
  4. The reachability argument. It may send the work back to the filter or the fallback.
  5. The examples, worked by hand.
  6. The per-room check, and where the tests run.
  7. The register rows.
  8. The write-up and close.

Output specification

All output goes into the plan page, plus the dashboard note at close:

Exit criteria

  1. The pinned commit is recorded in §3.8 and the Part II status line, and every file changed since 0d5a69c7694f is checked. Each room class added since then has a §6.8 row citing an E45+ row, and Wizard’s Rule’s says whether its bottles need the class hook.
  2. The prior art (Android’s focus search, CSS Spatial Navigation, Lab) is cited in Appendix E, with what each does about filtering, scoring, an empty direction and reachability.
  3. §5 states the origin of a press in each of item 3’s cases, says who decides each, and makes §5.5, §5.6 and §4.4 agree.
  4. The candidate filter is exact, boundaries included, with y pointing down.
  5. The score is an integer formula, and the tie-break is total and independent of list order.
  6. A press with no candidate has one stated result, for a press and for a repeat, with the default named and whether it’s configurable.
  7. §5.8 holds one of item 7’s three outcomes, with the graph built from presses only, over the directions a room leaves to the core. It shows that no selection is never a trap, that repeats needn’t differ, and the worst-case press count. Menu buttons and room-specific targets are included (H11, H13).
  8. The repeat delay and interval (in ticks, or “never”) are stated, with how a repeat differs from a press and how a double-reported press is handled. §6.3 agrees with §4.3.
  9. Each special case of item 9 has a rule or a worked answer.
  10. §5.7 states the cost per press, the largest Gen 1 list it was checked against, and that the core does no per-frame work.
  11. Appendix C covers every layout item 11 names, and every rule of items 3–9 is covered by at least one case. Each case has an expected result worked by hand, in a form packet 4 can transcribe one-to-one.
  12. Where the core’s tests run is recommended, with the cost of the shared test/module.mk change weighed and what it means for H4.
  13. The per-room check is designed: the graph over the room’s directions, the connectivity test, the two-order comparison, the toolbar-open state, the no-selection smoke check, the failure report, the channel and level, and the option-off statement. What it can’t cover is stated.
  14. Every “proposed (Hn)” in the plan has a matching §10.4 row, and every H17+ row is cited from §5, §6.3, §6.8 or §12.2. None is marked settled.
  15. git diff --name-only main lists only the plan page, this WP, EC-013, WORK_INDEX.md and dashboard.json. The fork has no new branch or commit from this WP.
  16. The wiki’s strict build passes (hugo --config ewiki/hugo.toml --minify --panicOnWarning).

Deliverables

Notes

Close (2026-11-28)

# Exit criterion Met Evidence
1 Pin, drift, new room classes in §6.8 ✅ Plan §3.8: fork 1539a7b59cf3, twelve merges since 0d5a69c7694f, every changed file checked. One new class (Wizard’s Rule, E45) and one class newly reading the pointer (KST, E46), both in §6.8. Wizard’s Rule’s bottles are plain sprites and need the class hook (§4.6)
2 Prior art in Appendix E ✅ Appendix E: Android’s FocusFinder, the CSS Spatial Navigation draft, and Lab’s FOCUS (E48), each on filtering, scoring, an empty direction and reachability. CSS’s distance function isn’t cited, because §8 couldn’t be read verbatim
3 Origin of a press; §5.5, §5.6 and §4.4 agree ✅ Plan §5.5 table (who decides each case: the provider) and §5.6 rewritten to drop the selection as §4.4 does, with hover restoring it (H17)
4 Exact filter ✅ Plan §5.1 steps 2–3: strict half-plane, minor ≤ major is tier 1, y down
5 Integer score, order-free tie-break ✅ Plan §5.1 steps 4–5 and §5.2 (fits 32 bits up to 16384 px) (H18)
6 No candidate ✅ Plan §5.4: stay, for a press and a repeat; fixed, not a setting (H19)
7 Reachability ✅ Plan §5.8. The second outcome: 5.1’s rules alone can strand a target (Appendix C, C9), so a reading-order fallback is added and argued. It works over presses, over the room’s directions (H24), from no selection (§5.5’s total rule), and with repeats unchanged. Worst case n − 1 presses, ⌊n/2⌋ in the fallback (H20). It covers menu buttons and room targets, since they’re targets like any other
8 Repeats and double reports ✅ Plan §6.3: no repeats in Phase 1, a later repeat handled as a press, and an 80 ms (3-tick) debounce. The §4.3 contradiction is gone (H21)
9 Special cases ✅ Plan §5.3 table, every case of item 9 (equal points: H22)
10 Performance ✅ Plan §5.7: O(n) per choice and O(4n²) for the guarantee; about 54 targets, an estimate from the placement counts rather than a bound (E50); no per-frame work
11 Appendix C ✅ Appendix C: C1–C15 cover every layout item 11 names, with a rule-to-case table. Expected results were worked by hand, and the scratch check agreed on all 258 cells (Notes)
12 Where tests run ✅ Plan §5.8: the self-test in Phase 1, CxxTest with the move to engines/. The test/module.mk cost (E47) and H4 are weighed (H23)
13 Per-room check ✅ Plan §5.8: states (as started, toolbar open), graph, connectivity, isGeometricConnected(), two orders, no-selection smoke check, report, channel and level, option off, not covered
14 Register ✅ Plan §10.4 H17–H24, all proposed. Checked by script: each is cited from §5, §6.3 or §12.2, and no citation lacks a row
15 Only the five files; no fork branch ✅ git diff --name-only main: the plan page, this WP, EC-013, WORK_INDEX.md, dashboard.json. The fork was read with git show and git grep only
16 Strict build ✅ hugo --config ewiki/hugo.toml --minify --panicOnWarning, no warnings, and every in-page anchor of the plan resolves

Departures from the output spec:

The scratch check (local only, never committed):

Corrected on the way:

Cold review. A second, independent read rebuilt the rules from the text and recomputed Appendix C. It agreed on every cell and found the proof sound. Its fixes went in before close:

For the next packets: