Skip to content

Fix straight path looping forever when the funnel restarts at a portal end - #206

Open
NayiemW wants to merge 1 commit into
andriyDev:mainfrom
NayiemW:funnel-apex-restart
Open

NayiemW wants to merge 1 commit into
andriyDev:mainfrom
NayiemW:funnel-apex-restart

Conversation

@NayiemW

@NayiemW NayiemW commented Nov 9, 2026

Copy link
Copy Markdown

find_next_point_in_straight_path keeps the portal at the start index as the initial funnel even when the apex (the point the caller is standing on) is one of that portal's ends. From a degenerate corner like that the funnel should restart at the apex, as in Mononen's simple stupid funnel: the portal constrains nothing there. Keeping both portal ends lets a later point that lies across the portal line from both ends bounce the apex between the two ends forever, so find_path's straight-path loop never advances and appends waypoints without bound (observed as an unbounded allocation on a large game map).

Two changes:

  • path.rs: when the apex is an end of the start portal, start the funnel degenerate at the apex instead of the full portal, so the first processed portal can actually advance the funnel.
  • query.rs: bound the straight-path loop at two steps per portal (each step advances the path index, so a straight path never needs more), turning any future non-advancing step into NoPathFound instead of an endless allocation.

Adds a regression test with two polygons sharing a short edge (a flat triangle and a raised quad beyond it, the target just past one end of the edge). On main the straight path alternates between the two ends of the edge and never reaches the target; with the fix it reaches the target in two steps.

Note for running the tests locally: on my machine the workspace's Cargo.lock needed googletest_macro 0.14.4 → 0.14.2 to compile the test suite. That change is not part of this PR.

I have used AI to assist me with this PR.

…l end

find_next_point_in_straight_path keeps the portal at the start index as
the initial funnel even when the apex (the point the caller is standing
on) is one of that portal's ends. From a degenerate corner like that the
funnel should restart at the apex, as in Mononen's simple stupid funnel:
the portal constrains nothing there. Keeping both portal ends lets a
later point that lies across the portal line from both ends bounce the
apex between the two ends forever, so find_path's straight-path loop
never advances and appends waypoints without bound (observed as an
unbounded allocation on a large game map).

Two changes:

- path.rs: when the apex is an end of the start portal, start the funnel
  degenerate at the apex instead of the full portal, so the first
  processed portal can actually advance the funnel.
- query.rs: bound the straight-path loop at two steps per portal (each
  step advances the path index, so a straight path never needs more),
  turning any future non-advancing step into NoPathFound instead of an
  endless allocation.

Adds a regression test with two polygons sharing a short edge (a flat
triangle and a raised quad beyond it, the target just past one end of
the edge). On main the straight path alternates between the two ends
of the edge and never reaches the target; with the fix it reaches the
target in two steps.
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