cleaned up getNearestPoint algorithm