on October 4th, 2007 at 09:58 am
(This article isn't about clipping paths or graphics or Vecto, it's about CLOS, protocols, and change-class.)
Clipping paths in in Vecto have these semantics:
Vecto implements clipping with a grayscale mask channel. But I wanted a couple optimizations:
The protocol to support this has the generic functions EMPTYP, COPY, CLIPPING-DATA, and WRITABLE-CLIPPING-DATA. A more efficient drawing function is used if the canvas's clipping path object is EMPTYP, otherwise a slower function that references CLIPPING-DATA is used. WITH-GRAPHICS-STATE copies the clipping path with COPY. Clipping path updates are written to the channel returned by WRITABLE-CLIPPING-DATA.
I initially implemented this with three classes: CLIPPING-PATH, EMPTY-CLIPPING-PATH, and PROXY-CLIPPING-PATH. Here's how each class handles each generic function:
|EMPTYP||returns true||returns false|
|COPY||returns new EMPTY-
data slot is EQ to original
|CLIPPING-DATA||no method||returns data slot value|
initializes and returns data
|returns data slot||change-class to CLIPPING-
set data slot to copy-seq of data slot
Then I read Joe Marshall's take on CHANGE-CLASS, which he calls — with some caveats — horrendous. I don't want to use horrendous things! So I implemented a different approach using only one CLIPPING-PATH class:
The second approach seems ok to me (and I don't need a table to explain it), but the first approach doesn't seem that horrendous either. I didn't choose either technique for any special reasons; they're just the first things that occurred to me.
What do you think? Are they about the same, or does one seem better to you? Is there some other approach that would be even nicer? Let me know.