ba0k+@andrew.cmu.edu (Brian Patrick Arnold) (03/06/91)
Howdy, I need a little help on finding a good algorithm for selecting lines as objects, er, the detection of a mouse click "close enough" to a line. If anybody has such an animal, your help would be greatly appreciated. I use MacApp in MPW Object Pascal, but I can comprehend C++ and other languages, so example code in any language would be a boon to me. Thanks. - Brian
d88-jwa@byse.nada.kth.se (Jon W{tte) (03/06/91)
In article <> ba0k+@andrew.cmu.edu (Brian Patrick Arnold) writes: > I need a little help on finding a good algorithm for selecting lines >as objects, er, the detection of a mouse click "close enough" to a line. The last time around, the consensus was to use QuickDraw: Create an offscreen port with portBits just one/two/(your-marginal) pixels wide & tall. Draw your stuff, from front to back, in this port, and see when the portBits change. QuickDraw clipping makes this quite fast. >- Brian h+@nada.kth.se Jon W{tte "The IM-IV file manager chapter documents zillions of calls, all of which seem to do almost the same thing and none of which seem to do what I want them to do." -- Juri Munkki in comp.sys.mac.programmer
boerned@mist.CS.ORST.EDU (Dan Boerner) (03/06/91)
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"
Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) (03/12/91)
In article <> ba0k+@andrew.cmu.edu (Brian Patrick Arnold) writes: > I need a little help on finding a good algorithm for selecting lines >as objects, er, the detection of a mouse click "close enough" to a line. Jon W{tte writes in a message to All JW> The last time around, the consensus was to use QuickDraw: JW> Create an offscreen port with portBits just one/two/(your-marginal) JW> pixels wide & tall. Draw your stuff, from front to back, in this JW> port, and see when the portBits change. QuickDraw clipping makes JW> this quite fast. >- Brian I don't mean to be dense, but I couldn't quite get that... Could you expand on it a little? Thanks. Lawson -- Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!300!15.88!Lawson.English Internet: Lawson.English@p88.f15.n300.z1.fidonet.org
d88-jwa@byse.nada.kth.se (Jon W{tte) (03/14/91)
JW> The last time around, the consensus was to use QuickDraw:
Lawson.English@p88.f15.n300.z1.fidonet.org (Lawson English) writes:
I don't mean to be dense, but I couldn't quite get that...
Basically, you set off a longword as portBits, create an offscreen
grafPort that's one by one pixel large (gee, that much, huh ? :-)
and set the portBits of that grafPort to your long value.
Initialize the value (portBits) with 0.
Initialize "selected object" to NULL.
Repeat
Draw next item.
is "the value" <> 0 ?
yes: set "selected object" to this item
break out of loop
no: too bad
until there are no more items
"selected object" now contains your clicked-on object
Thanks.
You're welcome.
Lawson
h+@nada.kth.se
Jon W{tte
--
"The IM-IV file manager chapter documents zillions of calls, all of which
seem to do almost the same thing and none of which seem to do what I want
them to do." -- Juri Munkki in comp.sys.mac.programmer