Imagine a set of (continious and enclosed) shapes on a plane and 2 points somewhere there. I need an algorithm to verify that it's possible to traverse from 1 point to another without ever leaving the interior of the set. The shapes can overlap, and in the simplest case, when no two shapes overlap each other, apparently the path exists only if both points belong to a single shape and do not cross it's border. But if some shapes do overlap, it seems tricky to check whether the path between two points crosses any "gaps" between shapes or just traverses from one shape to another.
The scheme to illustrate the condition. Green lines pass the check, red don't
For the sake of simplicity we can approximate shapes as polygons. The crucial part of my problem is that I can't and don't want to merge shapes (reasons are justified by the way they are described/stored), especially given that there are options when the merge produces a "multipolygon" with holes, which also doesn't make the problem easier. So I need an algo which doesn't involve any mutations on the source data and operates directly on cartesian values of polygon bounds.
Finally solved with ChatGPT. After some "discussion" we came up with the algorithm:
It seems to work perfectly for convex polygons, but I need to do more testing with concave ones. It (the AI) also provided some (pretty obvious) points of improvement with some particular references I found useful:
The humanity is doomed, it seems, but I finally find my satisfaction.