Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!snorkelwacker!apple!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: How do you grab lines like MacDraw? Message-ID: <9650@goofy.Apple.COM> Date: 9 Aug 90 17:36:23 GMT References: <4176@dogie.macc.wisc.edu> <89RN1MB@cs.swarthmore.edu> Organization: Apple Computer, Inc. Lines: 53 In article <89RN1MB@cs.swarthmore.edu> jackiw@cs.swarthmore.edu (Nick Jackiw) writes: > >Bitmap Inclusion > >This is Larry Rosenstein's favored approach. Calculate a rectangle about Only because I don't remember enough analytic geometry to compute the distance to most shapes. Also, the mathematical approach gets complicated when you start dealing with arbitrary polygons or curves. >your hit-point which is as wide and high as your desired slop: say 3 pixels You can also account for slop by drawing the objects a bit bigger than normal. >square. Now allocate an offscreen bitmap with these dimensions. (Or better, Remember that a bitmap's rowbytes must be even. I used a bitmap that was 16 bits wide an 1 bit high. >rectangle, this data need only be six bytes long.) If any bit has been >set--i. e. if Quickdraw has drawn your most recent object within a tiny >rectangle representing the user's hit--than that object is hit; select it. Normally objects are drawn back-to-front, which means that the last one over the mouse point is the one that should be selected. If your data structure allows you to scan in reverse order then it would be the first one. >most of them are probably in an Algebra I text; and they will be >consistently faster and take up less run-time memory than the bitmap It's not clear to me that they take up less memory, especially, if you have several kinds of shapes. You need only one piece of code for the bitmap approach vs. one for each kind of shape. Each of those calculations will require a comparable amount of code. Also, part of the code to implement the bitmap approach will be the normal drawing code, which you need anyway. >Give a holler if you want source code for algebraic stuff; someone else >can probably provide a working example of bitmap inclusion. You can get my code along with the "Programming with MacApp" book (the diskette is also available separately). It's written in the context of my drawing building block, but the key piece of code should be usable in other programs. I think the key method is listed in the book, so you don't even need the diskette. I would like to see the algebraic code and compare the speed of the two. I'm not sure that it's going to be faster than the bitmap approach. -- Larry Rosenstein, Object Specialist Apple Computer, Inc. 20525 Mariani Ave, MS 46-B Cupertino, CA 95014 AppleLink:Rosenstein1 domain:lsr@Apple.COM UUCP:{sun,voder,nsc,decwrl}!apple!lsr