Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uwm.edu!psuvax1!rutgers!usenet!mist.CS.ORST.EDU!boerned From: boerned@mist.CS.ORST.EDU (Dan Boerner) Newsgroups: comp.sys.mac.programmer Subject: Re: Selecting lines Keywords: hit detection Message-ID: <1991Mar06.102841.29652@lynx.CS.ORST.EDU> Date: 6 Mar 91 10:28:41 GMT References: Sender: boerned@mist.cs.orst.edu Organization: Computer Science Department, Oregon State Univ. Lines: 35 Nntp-Posting-Host: mist.cs.orst.edu This routine has the following advantages: o It is simple to understand o It is portable, since it only need a shape drawing iterator o It works for any shape, regardless of internal representation o It maintains a 1-1 correspondence between the image on the screen and the mouse location clicked because it is actually using your drawing code. o It is set up to return the *last* shape hit which is usually what you want since you want the top most shape selected. o It allows you to allow 'slop' by drawing each shape with a fat border surrounding your shape. This is particularly useful for line hit detection as no slop means a frustrated user. o It uses very little memory. o And best of all there is sample code in the Programming with MacApp book and since it only needs a shape iterator and your are keeping your shapes in a TList aren't you? You should easily be able to integrate it into your MacApp application. Nick Jackiw suggested the geometry approach in which you simply get down and dirty with sin and cosine (or precomputed sin tables) or whatever other optimizations and just figure out if the hit was on the line. He claims that it is faster than the bitmap approach (especially for complex shapes that reauire expensive flood fills in the bitmap approach) and uses no extra memory. It does require some thinking but then we know that Nick eats, sleeps and dreams geometry :) So there's a very quick overview, if your thirsty for more let me know as I've kept a running file with most of the msgs about this topic. It includes code for both approaches but is a little long for this forum. ----------- Dan Boerner Grad Student, Oregon State University boerned@mist.cs.orst.edu "Playing with MacApp and Building Blocks"