• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSBezierPath containsPoint?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSBezierPath containsPoint?


  • Subject: Re: NSBezierPath containsPoint?
  • From: Greg Titus <email@hidden>
  • Date: Fri, 21 Oct 2005 08:31:05 -0700


On Oct 20, 2005, at 9:30 PM, Ben Kazez wrote:

On Oct 20, 2005, at 10:31 PM, "Brian O'Brien" wrote:


Believe it or not that was what I decided to do on my own...
basically its a rectangle with height 3 and a variable width. There
is no outline but it is solid filled.
Still I believe that the NSBezier class should do this for me...
Rather then a million programmers writing this over and over and over.
(and a million mailing list readers answering this question over and
over and over)

As you describe it, this would only work with horizontal lines.



Write an Objective-C category and put it online! This feature is very cool.

You may want to check out OmniAppKit's NSBezierPath-OAExtensions.[hm] at <http://www.omnigroup.com/developer/sourcecode/>.


It contains the following methods, originally written for OmniGraffle so they have been extensively tested in a real world app. Note that all of them work correctly for arbitrary bezier paths, i.e. you can get hits and intersections with the outline of closed shapes or complex curves as well as with simple lines. Brian will want just the -isStrokeHitByPoint: method, probably.

- (BOOL)intersectsRect:(NSRect)rect;

Does the path overlap this rectangle.

- (BOOL)intersectionWithLine:(NSPoint *)result lineStart:(NSPoint) lineStart lineEnd:(NSPoint)lineEnd;

Does the path intersect the line segment starting at ending at these two points. If so, it returns the point at which the path intersects the line in the result.

- (NSArray *)intersectionsWithPath:(NSBezierPath *)other; // returns array of positions

This returns an array of float values that are the positions along the path (see -getPointForPosition) where the path intersects with another path. There can be many intersections if the two paths are complex shapes which overlap each other.

- (int)segmentHitByPoint:(NSPoint)point padding:(float)padding;

This returns the segment of the path hit by the point, where padding is how close you have to get to the path stroke in order to register as a hit. Returning zero means that the path was missed entirely.

- (int)segmentHitByPoint:(NSPoint)point;

As above, but default to 5 pixels of padding.

- (BOOL)isStrokeHitByPoint:(NSPoint)point padding:(float)padding;

Simplified version of -segmentHitByPoint:padding:, just returns YES if the path is hit anywhere along it.

- (BOOL)isStrokeHitByPoint:(NSPoint)point;

Simplified version of -segmenetHitByPoint:, assumes 5 pixels of padding, and returns YES if the path is hit anywhere.

- (NSPoint)getPointForPosition:(float)position andOffset:(float)offset;
- (float)getPositionForPoint:(NSPoint)point;

A 'position' is a number from 0.0 to 1.0 which encodes how far along the path you are. 0.0 is the very beginning of the path, and 1.0 is the very end. These two methods convert from points to positions and back. The offset parameter on -getPointForPosition:andOffset: is so you can offset the point from the path by a number of pixels - it computes the normal of the path at that position and moves that many pixels along the normal.

Hope this helps,
    - Greg
_______________________________________________
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


References: 
 >Re: NSBezierPath containsPoint? (From: Ben Kazez <email@hidden>)

  • Prev by Date: Altering Cocoa Text Word Breaking
  • Next by Date: Re: Altering Cocoa Text Word Breaking
  • Previous by thread: Re: NSBezierPath containsPoint?
  • Next by thread: Authenticate a user
  • Index(es):
    • Date
    • Thread