Distance Functions

I'm not sure how to test this locally, but this is the basic idea