Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hit testing between line and path




On Mar 11, 2008, at 11:55 PM, Luigi Castelli wrote:

Hi all,

I have a 16x16 matrix made by rectangular CGPaths.
The exact shape of the paths is actually a rounded rectangle.
All the CGPaths in the matrix are NOT adjacent to each other.
In other words there is some space between the paths - or cells of the matrix.

Now I want to implement 2D interpolation when the user drags on the matrix in an attempt to select its cells.
This would have the effect that even during fast drags the cells over which the mouse has passed will be selected.

So, if a line is drawn on top of the matrix how would I know which paths (cells) it intersected ?

What would be the best strategy to tackle such a problem ?

Any advice or suggestion is highly appreciated.

Track the mouse in a mouseMoved handler and at each mouse position use CGPathContainsPoint to  determine if the mouse is in a particular cell.

If that's not sufficient, you could use bressenham's algorithm or even simple interpolation to calculate intermediate points on a line and check whether they are in the path(s).  If you know how big your cells are you simply have to sample at half that distance to feel confident that you hit everything you might have hit.

Scott

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden

References: 
 >Hit testing between line and path (From: Luigi Castelli <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.