The code for directness/indirectness

It is acturally a nearest neighbor search, so should be easy to convert.