Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul arrow pathfinding #62

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Alch-Emi
Copy link

Currently, arrow pathfinding works using the following algorithm:

  • for each possible starting point (typically = 2)
    • for each possible ending point (1 for a point, 2 for a node)
      • run a greedy search from the start to the end
  • pick the fastest path

This algorithm often creates arrows that are way squigglier and hard to follow than they really need to be. Additionally, it often does four times more work than it needs to, because it runs once for every combination of start and end points.

This PR replaces the greedy search algorithm with a slightly more expensive A* algorithm, while also using an algorithm that allows automatically picking the best path from one of a number of start points to one of a number of end points, eliminating the need to run the algorithm more than once.

By using an A* algorithm, we also gain more control over the pathfinding, by the use of weights. This PR takes advantage of this fact to improve arrow generation in the following ways:

  • Making more turns than necessary is discouraged, decreasing line squigle factor (cost +1 / turn)
  • Pointing in the direction of the end arrow is encouraged (cost +5 if ending in the wrong direction, see 69241df)

This also opens the door for future work in order to discourage arrows from overlapping for long distances, but that's left to another PR.

Before

image

After

image

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.

None yet

1 participant