function calculating distance from a point to a line
implementation of the Ramer-Douglas-Peucker algorithm