February 2008 Archives

Debugging NSBezierPath drawing

| 1 Comment

I was working on some Cocoa programming, making heavy use of NSBezierPath. I wished there was an easy way to see just where my control points were ending up, and how the curves were being constructed. So I wrote a category method to add such a thing to the NSBezierPath class. It is here for all to share.

Here's an example of annotating a curve:

BezTest1

It's very simple, but very handy as you can easily switch from the normal stroking of the path to this annotated version in one line. It puts blue dots on all the regular points, green dots for the control points, adds lines to join control points to their anchor point, and adds a label so you can see the direction of the control point (so "cp3_2" is anchored at point 3, on the side of point 2. It also draws the bounding box in red, so you can see the extents of the full path.

Enjoy! I'd love to get feedback from anyone who tries this. (Please email me; the comments system is sadly flooded with spam and I may miss legitimate posts.)

My Photos

www.flickr.com
This is a Flickr badge showing public photos and videos from antonyme. Make your own badge here.

Recent Tweets

    About this Archive

    This page is an archive of entries from February 2008 listed from newest to oldest.

    January 2008 is the previous archive.

    May 2008 is the next archive.

    Find recent content on the main index or look in the archives to find all content.