[Drawkit] SonoDraw Beta 1 now available

Graham Cox graham.cox at bigpond.com
Tue Jul 29 18:30:05 PDT 2008


On 30 Jul 2008, at 9:03 am, Brad Larson wrote:

> Some things to note are that this is a Leopard-only application  
> (using garbage collection and some Leopard-specific UI elements,  
> like toolbars), and the source is intended to be installed in a  
> development directory at the same level as the source code for  
> DrawKit Beta 4, as well as the latest version of Sparkle (http://sparkle.andymatuschak.org/ 
>  ).  DrawKit may need to have its build settings altered to support  
> garbage collection (-fobjc-gc) in order to work with this program.

That's cool :) Did you find any difficulty with DK using Garbage  
Collection? It's something they promise should "just work" but so far  
I've not tried it.

> This version is not quite feature-complete, as the help files are  
> mere stubs,

Aren't they always? ;-)

> and I'm tracking down a glitch with DKArcPath where it doesn't  
> always draw with the correct radius.

Hmm, be good to know what that one is - not noticed it.

> The last large feature, though, involves preparing the pattern file  
> during the save process.  Our dispenser draws elements in the order  
> that they appear in the .pattern file.  This presents a problem when  
> a user draws out a pattern in SonoDraw, because they usually don't  
> draw the elements in an optimal order. The file gets saved out in  
> that drawn order, and it takes a much longer time to draw the shape  
> in the machine.  We'd like to add an optimization pass on saving out  
> the file that does a simple sorting of the drawing elements to get  
> them in the right order.  This doesn't need to be the optimal order,  
> just not terrible. DKObjectOwnerLayer has methods for reordering  
> drawing objects one at a time, but I'm trying to figure out the best  
> way to do a sort on a layer's objects.  Should I pull the objects  
> out into an NSMutableArray, sort that, and write the elements to  
> disk out of the array, or would a category on DKObjectOwnerLayer be  
> the way to go so that sorting could be handled on the internal  
> object array?

One problem is how you define the order in a 2D set. I suppose sorting  
on x then on y (with a stable sort algorithm, which Cocoa's is) would  
do for a first pass. I guess you're trying to minimise the movement of  
the machine. I've actually implemented something like that a long time  
ago for a microscope xy drive and the optimal path for objects in some  
arbitrary scattered order is a very hard problem - in fact it's the  
classic Travelling Salesman problem. (http://en.wikipedia.org/wiki/Travelling_salesman_problem 
) I ported some code from "Numeric Recipes in C" at the time that used  
simulated annealing to come up with a path that for the most part was  
very good - the perfect path isn't that important, just one that's  
good enough and can be computed in a reasonable time. Unfortunately I  
don't have that source any more but if you can get hold of that book I  
can vouch for the algorithm!

As a practical matter, your idea of pulling the objects out into an  
array and sorting that is a good one. In fact there's probably no  
reason to actually set the objects into that order in the drawing,  
just create a separate sorted array on the fly as needed (cache it if  
the number of objects is very large perhaps). If you did want to set  
the drawing's objects to the sorted array, just call setObjects: with  
the new array. One cool feature could be an overlay that shows the  
drawing order as a path - with the simulated annealing algorithm at  
play this does give a great insight into how it works (for bonus  
points, update the overlay as the algorithm proceeds...).

> Any and all feedback on this program is welcome.  Thanks again to  
> Graham for writing DrawKit.  It has allowed us to create a far  
> better vector illustrator for our niche application than we could do  
> completely on our own.


It looks like a very nice little app - and you have the dubious  
"honour" of being the first out of the gate with a finished DK app!  
(How does it feel on the bleeding edge?).

cheers, Graham


More information about the Drawkit mailing list