It looks a lot like f
& g
are meant to be calculating the slope & intercept of a straight line through the points, but the author mucked it up. If you'll allow me to abuse notation, f
is defined as a ratio of an x coordinate value to a y coordinate value, which I'll write as f ~ x/y
. Which means that in the definition of g
, you're subtracting a f*x ~ x^2 / y
term from a y
term.
Now if f
were actually meant to be defined as f ~ y/x
, then in g
's definition you'd be subtracting a f*x ~ y
term from a y
term, which would make much more sense. I also think the author might have accidentally lost a -1 in the definition of f
(which is why the denominator is the opposite way round from the numerator), but I can't say for sure without seeing the rest of the code.
Also when the y-coordinates of the left and right site are the same, you get a division by zero in the definition of f
which is probably why it's mucking up.
If you could explain what the start
point represents, and whether the algorithm is sweeping from the left or the right, I might be able to figure out exactly what it's trying to do.