choose the vertex that gives the shortest distance when on the same vertical line