I am working on a drawing program and am trying to figure out the best way to imitate the 'magnet' behavior found in applications such as Omnigraffle. The idea is: as a line is drawn between two objects (visual objects on screen, not OOP objects), as the line from the first object approaches the second, a 'magnet' or 'node' on the second will highlight or the second object will highlight.
I was looking to keep all of the on-screen objects in an array and using notifications to send that array the position of the end of the line as it moves. This way, I could have each object do its own comparison and say "Hey, I have a node near the line, I think I'll light it up".
I was also wondering if it would be the same approach if I wanted to have two objects, say boxes for instance, that would snap together, side by side, when they came into proximity with each other. This way, it would be possible to line up the boxes on the same X or Y coordinate
I'm not concerned about the highlighting or having the line snap to the position of a node, I'm just wondering about the best way to implement the 'edge proximity detection' part of this problem.