Closest path

For https://github.com/codeparty/derby/issues/420

Would something like this be feasible? It seems to solve my problem.

(the modification is in two separate repos, here and in derby)
(also, this PR went into the wrong repo originally, my own)