Contour fitting

Hi guys,

We are making heavy use of contour lines in our applications (hardly
surprising so far) ... A couple of points have come up where we would
like to improve on the way things are done.

Firstly, we find that it is possible to zoom in over an area where no
contour labels are visible. This is undesirable, so we would really like
to force a relabelling of contour lines based on what is currently
visible after every zoom action.

Also, the contour lines are clearly linear lines of best fit. Just
taking a guess, it looks like the contour lines are built by drawing a
straight line until the line of best fit diverges too much from the
data, at which point a new line is started. We would like to use a
smoother line-fitting algorithm, which I suppose would be done by
fitting nonlinear lines of best fit instead.

I'm happy to do the legwork, but am having trouble finding where the
relevant areas of code are. I'd really appreciate an overview of the
contour labelling algorithm and event structure, and also a description
of how the current contour fitting algorithm works.

Thanks,
-Tennessee