completed borderShortcut algo