Skip to content

Recompute the path instantly while dragging start/target#26

Open
Stephan-342B wants to merge 3 commits into
mainfrom
feature/instant-path-on-drag
Open

Recompute the path instantly while dragging start/target#26
Stephan-342B wants to merge 3 commits into
mainfrom
feature/instant-path-on-drag

Conversation

@Stephan-342B

Copy link
Copy Markdown
Owner

Feature

Matches the original: once a pathfinding run has finished, dragging the start or target node recomputes the visited cells + shortest path live as the node moves over the grid (and on drop). No re-clicking Visualize needed.

Behaviour

  • Only active after a run has completed (pathDisplayed, the original's algoDone). Cleared by any Clear action or maze generation.
  • The recompute is instant — no step-by-step search animation and no travelling arrow (those would be unusable while dragging). The search runs synchronously and cells are painted straight to their final colours (visited → cyan, path → yellow).
  • Works continuously on every cell the node passes over (throttled to actual cell changes), and finalizes on drop. An invalid drop (onto another node) snaps back and repaints for the real position.

How

  • GridService: pathDisplayed flag + recomputeInstant(start, target) — reruns A* with the dragged endpoint overridden and paints instantly.
  • GridStepRenderer: new arrowless mode — final-state colours only, no arrow, CURRENTVISITED, special nodes left untouched.
  • GridSnapshot.of(grid, start, target): snapshot with explicit endpoints (preview before the move commits).
  • NodeAnimations.visitedInstant: cyan fill, no pulse.
  • CellEventHandler: DRAG_OVER preview callback + drop finalize callback.
  • MainWindowController: suppresses reveal animations during the instant repaint; wires preview + finalize.

Testing

  • mvn test green (5); mvn compile green.
  • Needs manual verification (I can't drive the JavaFX GUI here): run A*, then drag start/target around — path/visited should follow live and instantly; drag before running should just move the node; Clear/maze should stop the live recompute.
  • Perf note to watch: each cell change reruns A* + repaints; on very large grids this could feel heavy. Easy to optimize later if needed.

🤖 Generated with Claude Code

stephan and others added 3 commits July 9, 2026 00:42
After a run has finished, dragging the start or target node now recomputes and
repaints the visited cells + shortest path live as the node moves — and on drop
— matching the original. No animation/arrow during the recompute (that would be
unusable mid-drag); the search runs synchronously and paints final colours.

- GridService: `pathDisplayed` gate (the original's "algoDone", set on run
  completion, cleared on clear/maze) and `recomputeInstant(start, target)` that
  reruns A* with the dragged endpoint overridden and paints instantly.
- GridStepRenderer: "arrowless" mode — colour cells to their final state with no
  travelling arrow, CURRENT collapsed to VISITED, special nodes left untouched.
- GridSnapshot.of(grid, start, target): snapshot with explicit endpoints so the
  path can be previewed before the move is committed.
- NodeAnimations.visitedInstant: fill a visited cell cyan with no pulse.
- CellEventHandler: emit a preview callback on DRAG_OVER while dragging a special
  node, and a finished callback on drop.
- MainWindowController: suppress reveals during the instant repaint; wire the
  live preview (throttled to cell changes) and the drop finalize (also corrects a
  stale preview when a drop is invalid).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Follow-up to the instant-recompute feature:

- Visited cells stayed white during the drag recompute: the programmatic cyan
  fill was wiped by the CSS pass triggered by the :visited pseudo-class (base
  .cell is transparent). Give :visited its cyan in CSS so it persists on its
  own; the animated reveal keeps growing "from nothing" via a temporary
  "revealing" class that holds the cell transparent until the tile finishes.
- The recompute called the full grid.clear() every frame, which is meant for
  the Clear buttons — it reset the target's icon via getChildren().get(0) and
  stripped the start's style, which made the target icon vanish on drop and
  churned the special nodes. Add Grid.clearSearchFlags() (flags only, no icon/
  style/position changes) and use it for the instant recompute.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Match the original for start/target during the instant recompute:
- The path endpoints (start/target cells) now turn yellow too instead of being
  left blank, so the non-dragged node is always yellow. The arrowless renderer
  colours PATH on special nodes (keeping their icon); visited/wall stay off the
  endpoints.
- On drop, the dropped endpoint plays a reveal from a rounded square to a full
  yellow square (NodeAnimations.pathReveal), like the original's cell animation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant