Compare the angles.
ObjectA.Angle == ObjectB.Angle
Distance(ObjectA.X, ObjectA.Y, ObjectB.X, ObjectB.Y) < snapdistance
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.