Adaptation of Mike Bostock’s Collision Detection with rectangular elements.
Got most of the way there myself but needed this example by Ilya Boyandin to clean it up.