QuickDraw – Polygon reconstruction

One esoteric feature I implemented in my QuickDraw viewer is polygon reconstruction. QuickDraw has the notion of comments, instructions that typically don’t execute in the main screen renderer, but can be used by other renderers, typically printers. One set of such comments allows to take a sequence of lines and make a polygon out of it. What’s the point? A polygon is a sequence of lines, no?

The problem is, in a rendering system, what is called a line has a width (or we would not see it), and is actually a rather thin polygon. Because of this, joining lines is not the same as just drawing both of them, in fact PostScript (and thus PDF and CoreGraphics) defines three ways to join lines: miter, round and bevel. All these look better than no joint at all. Below is a zoom in of a QuickDraw picture of a map I drew, with no polygon joining:

Clip with non joined lines

And now the same part of the map with polygon joining enabled:

Clip with joined lines

Why would a QuickDraw picture contain a polygon as a sequence of lines instead of an actual polygon, which exist in that language? Early Macintoshes had very little memory and my understanding is that large polygons could overload their memory, so this was a trick to minimise memory usage.

The way this is handled is when the renderer encounters a polyBegin comment, it won’t draw subsequent line operations. Instead they are added to a polygon and the full polygon is rendered when polyEnd is encountered. If a polyClose comment is encountered, the polygon is closed, i.e. a line is added from the last point to the first.

Now there is more complexity that my code does not handle currently, as a polygon can be smoothed, which basically means it’s a bezier curve. In this mode, some lines need to be ignored (they are approximating the bezier curve) and the smoothed polygon can not only be framed, but also filled. More work to do.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.