Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uwm.edu!bionet!agate!agate.berkeley.edu!nj From: nj@truffula.Berkeley.EDU (Narciso Jaramillo) Newsgroups: comp.sys.amiga.programmer Subject: Re: Clicking on irregular shapes? Message-ID: Date: 31 Mar 91 01:39:51 GMT References: <1991Mar27.212214.6204@orfeo.radig.de> <2710@sirius.ucs.adelaide.edu.au> <20181@cbmvax.commodore.com> <1991Mar29.022042.14110@leland.Stanford.EDU> <1757.tnews@templar.actrix.gen.nz> <2151@pdxgate.UUCP> Sender: usenet@agate.berkeley.edu (USENET Administrator) Organization: Postcarcinogenic Bliss, Inc. Lines: 48 In-Reply-To: bairds@eecs.cs.pdx.edu's message of 30 Mar 91 23:49:27 GMT mmaston@leland.Stanford.EDU (Michael Maston) asked: [in the context of object-oriented drawing programs] >> [how does one select] say an object drawn with a freehand tool? In article <2151@pdxgate.UUCP> bairds@eecs.cs.pdx.edu (Shawn L. Baird) writes: > If you're really lazy and don't mind wasting a little extra memory, or if > your objects have non-polygon shapes, try setting up a one plane mask of > the area. Then just check the point to see if it is a 1 or a 0 when clicking > occurs inside of the box. This is a good idea for irregularly-shaped Intuition buttons and *filled* objects, but it doesn't work for unfilled objects or non-closed objects, where you only want to select it if you hit the mouse button near the boundary of the object. The suggestion I accidentally sent through email to Michael depended on how he was storing the freehand objects. 1) If you're storing the freehand object as a plain old bitmap, the easiest thing to do is probably to just go ahead and search all the pixels in the bitmap that are within your pick sensitivity radius of the mouse button press. Since pick sensitivity is unlikely to be huge, this shouldn't take too long, unless there are a bunch of overlapping bitmaps. (Of course, you should do a bounding box test first, to make sure the mouse button actually hit near the bitmap.) 2) If you're storing the object as a sequence of lines, then you can go through each of the lines and do a standard line-pick check. 3) If the object is a sequence of curves, it's harder. The trick I plan to use is to check bounding boxes of curve segments first (I'm using splines with the convex-hull property). Then, for each of the curve segments whose bounding boxes the mouse button hit, I go through and ``redraw'' the curve segment (actually, just recomputing points on the curve without drawing), checking if any points on the curve are near the mouse press. Since I'm using a reasonably fast curve-drawing algorithm (forward differences), this shouldn't be too slow (unless there are a bunch of overlapping curve segments). Does anyone have any better suggestions for the last case? It's sort of a general problem with selecting parametrized curves. nj