Windowcitis Can Be Contagious

servet8In 2004 I had to make a set of napkins and tablecloths of a unique design. The theme was fallen leaves of the fern-leaved beech (Fagus sylvatica ‘Asplenifolia’). I decided to use PostScript (Ghostscript actually). It has instructions like infill to test collisions, it shrugs at using an aspect-ratio of 28×36 threads per cm and it is very intuitive. I could preview (in the after-shrink aspect-ratio) on screen and paper. I used a very naive algorithm. 1) Generate a unique leaf 2) pick a random position and direction for it and 3) shift it along until it did not collide with anything. It worked wonders. I could generate a napkin of 81×81 cm with 555 leaves in a few minutes. However doing the 2000 leaves of the tablecloth took much longer. About 32 hours. Since I had to send the CD to the weavery in two days, I started it on my wife’s computer and let it run. About 31 hours later my, than, 10 year old son came to me for some help with a computer game… You guessed it, he had rebooted the computer because it was acting “funny.” (It was running FreeBSD.) I could not blame him, rebooting is normal behavior for a Windows user. With the deadline four hours away, I had no choice but optimizing the code for three hours so I could generated the table cloth in minutes.
There are two lessons I learned. First, you can be hit by someone else’s windowcitis, and second sometimes optimizing can lower the risk of failure in unexpected ways. Speaking of lowering failure risk, nowadays all my family members run OS X.

  1. John says:

    How did you optimize?

  2. coder says:

    I quickly found out that collision detection consumed 90% of the runtime. I cut the tablecloth in sections. For each section a list would be kept containing the leafs that were (even partially) in it. So instead of having to check for collisions against all previous leaves, only the leaves in a few sections (max 4) had to be checked. This drastically lowers the total number of collision detections.

  3. John Sinteur says:

    Obvious and simple. I like it.

  4. coder says:

    Thanks but at the time it caused “some” stress. :-)

Leave a Reply