Re: NSBezierPath containsPoint?
Re: NSBezierPath containsPoint?
- Subject: Re: NSBezierPath containsPoint?
- From: "Brian O'Brien" <email@hidden>
- Date: Thu, 20 Oct 2005 18:33:07 -0600
On 20-Oct-05, at 3:48 PM, glenn andreas wrote:
On Oct 20, 2005, at 4:25 PM, Brian O'Brien wrote:
Hi I've been drawing shapes with NSBezierPath and have been been
using containsPoint
to determine if the mouse is inside a shape.
This seems to work well for polygons, rectangles and ovals but
doesn't work for
a straight line.
It works perfectly fine for a straight line, it's just that
"containsPoint" determines if the point is _inside_ the path, and
since lines are infinitely thin, there are no points that are
"inside" the line.
How can i tell if the mouse is on top of a line?
Take the distance from the point to the line, and see if it is less
than some threshold (note that you'll want to find the point that
the normal from the point in question intersects the line to make
sure that it is between the end points, since most "distance of
point to line" calculations are based on an line, not a line
segment). A quick search of google turns up a ton of links,
include <http://astronomy.swin.edu.au/~pbourke/geometry/pointline/>
(there's lots of good basic geometry type code on that site).
There HAS to be a better way!
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
Widgetarium | the quickest path to widgets
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden