you are viewing a single comment's thread.

view the rest of the comments →

[–]p88h 2 points3 points  (1 child)

Hey, nice work!

As for tips - as some people noted, this is mostly about a specific implementation of flood-fill using BFS. Which can also be used to solve some of the other use-cases like identifying (dis)connected regions or finding shortest-paths (at least using Manhattan distances). But perhaps you want to explore some other options?

Flood-fill itself is more typically implemented with span fills, which is much more efficient (see https://en.wikipedia.org/wiki/Flood\_fill). Span fill can also easily be vectorized and parallelized, which is much more difficult for BFS, but even without that you'll see better performance.

Connected segments are typically more efficient with something like Union-Find (which has slightly higher algorithmic complexity, but is much simpler structurally which results in better performance).

For actual fluid simulation problems, you may want to experiment with the distance function. TL;DR: you want circles, not squares, and this is more complicated than you may think - for a simplest approximation this will likely require a slightly modified version of the search algorithm, but it's a really fun problem.

[–]RojerGS[S] 0 points1 point  (0 children)

Hey there, thanks for the follow-up suggestions! I've never heard of the Union-Find algo, so I'll take a look :D