Position ports based on the edge directions