I want to revisit Tuesday’s discussion of clipping; when I wrote that post I was laboring under certain misconceptions related to Core Graphics paths, which I would like to discuss. As a consequence of correcting these misconceptions, I can see that Core Graphics clipping is much easier to work with than I had supposed.
How to set path in MAC OSX,osx add to path,how to setup path in mac oshow to set java path in MAC.
My basic mistake was to assume that a Core Graphics path was, essentially, a single closed loop. In fact, a path is a collection of line segments and loops; it is essentially a collection of subpaths, where a subpath corresponds to my original conception of an overall path.
In particular, I misunderstood the purpose of these functions:
I thought that CGContextBeginPath
and CGContextClosePath
formed a pair, and that a path was defined by Core Graphics calls made between these bookends. In fact, CGContextMoveToPoint
and CGContextClosePath
form the pair; CGContextMoveToPoint
establishes the first point on a subpath to which CGContextClosePath
will connect, if it is called.
Once this misapprehension was corrected, some other issues related to clipping became clear.
I had been puzzled by this language in the Core Graphics documentation for CGContextClip
:
The function uses the nonzero winding number rule to calculate the intersection of the current path with the current clipping path. Quartz then uses the path resulting from the intersection as the new current clipping path for subsequent painting operations.
and CGContextEOClip
:
The function uses the even-odd rule to calculate the intersection of the current path with the current clipping path. Quartz then uses the path resulting from the intersection as the new current clipping path for subsequent painting operations.
When I was working on clipping to hollow shapes, I first tried this procedure:
CGContext*Clip
CGContext*Clip
However, no matter which CGContext*Clip
functions I called at which point, and no matter which winding I used when defining the hulls, I could not get the clipping paths to interact in the way I wanted. I now understand why: These functions effectively apply the “nonzero winding” or “even-odd” rule to the current path (i.e. collection of subpaths), and then take the intersection of the resulting clipping region with the current clipping region.
(Incidentally, the difference between the “nonzero winding” and “even-odd” rules is reasonably well explained here; it’s not Apple documentation, but it’s on-point.)
This function defines a relatively complex clipping region, used to create the image at the top of this post:
Three points:
CGContextAddArc
states that the final argument (clockwise
) must be 1 on the iPhone to create a CCW arc; this does not appear to be true, although I may be misinterpreting my results CGContextMoveToPoint()s
preceding the arcs are crucial; without them, Core Graphics will insert line segments between the last point of one arc and the first point of another, with undesirable resultsWith our new understanding of paths and clipping, we can simplify the code that we saw on Tuesday:
When browsing through your files and folders in Finder, it is easy to get lost and not know where you are or what directory you are browsing. If you have several folders of the same name in different locations on your Mac, it is quite confusing when you do not know the path of the folder you are in. With the path bar enabled, you will always know where the file or folder selected is located.
The path bar is a slim strip near the bottom of your Finder window. To enable the path bar, first open a Finder window. This is done by double-clicking on your Macintosh hard drive icon from the desktop. Next, go to the View menu and choose Show Path Bar. The Show Path Bar option is grayed out if a Finder window is not open.
The left most end of the path bar is the top level, which will always show the drive (also known as the volume) where the window’s contents are located. This maybe your Mac hard drive, a network drive, iDisk or an external storage device. The top level is followed by arrows pointing to subfolders that show the path of the currently selected item. You can move up the hierarchy by clicking on a folder along the path bar. You can also use the path bar to move files to other locations in the hierarchy - just click and drag a file to a folder along the path bar.
___________________________________________________________
Computing Tips and Techniques are brought to you by the Information Technology Group for the purpose of sharing a wide variety of technology tips with its clients. The collection of these tips are protected by intellectual property rights, such as copyright. All intellectual property rights belong to the manufacturer of the software product in question.