Added nearest point on curve function