Having list of rectangles parallel to axis in form (minx, miny, maxx, maxy):
rectangles = [ Rectangle(90,40,110,70), Rectangle(10,40,40,70), Rectangle(75,60,95,80), Rectangle(30,20,60,50), Rectangle(100,20,130,50), Rectangle(70,10,85,40) ] I need to get list of groups of rectangles, where each rectangle intersects with at least one other:
[ (Rectangle(10,40,40,70), Rectangle(30,20,60,50)), (Rectangle(70,10,85,40)), (Rectangle(75,60,95,80), Rectangle(90,40,110,70), Rectangle(100,20,130,50)) ] The algorithm can't be naive, it needs to be fast.
What I tried:
- Find python interval tree implementation - I couldn't find anything good...
- I tried this repo: https://github.com/booo/rectangleintersection/blob/master/rectangleIntersection.py, it works with the example above but fails with real world data.
- I read through scikit image and Shapely documentation but didn't find algorithms for rectangle intersection.