Compare the angles.
If
ObjectA.Angle == ObjectB.Angle
and
Distance(ObjectA.X, ObjectA.Y, ObjectB.X, ObjectB.Y) < snapdistance
then
Set position of ObjectA to ObjectB
This doesn't take into account flipping. If you want that, throw negative width and height detection into the mix.
If you'd like an example post a .capx. Kudos for the descriptive diagram.