Created
October 2, 2012 21:44
-
-
Save adamawolf/3823502 to your computer and use it in GitHub Desktop.
How to print out a CGPathRef for debugging purposes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void outputApplier(void* info, const CGPathElement* element) | |
{ | |
NSMutableArray* a = (NSMutableArray*) info; | |
int nPoints; | |
NSString * pathElementType = nil; | |
switch (element->type) | |
{ | |
case kCGPathElementMoveToPoint: | |
nPoints = 1; | |
pathElementType = @"kCGPathElementMoveToPoint"; | |
break; | |
case kCGPathElementAddLineToPoint: | |
nPoints = 1; | |
pathElementType = @"kCGPathElementAddLineToPoint"; | |
break; | |
case kCGPathElementAddQuadCurveToPoint: | |
nPoints = 2; | |
pathElementType = @"kCGPathElementAddQuadCurveToPoint"; | |
break; | |
case kCGPathElementAddCurveToPoint: | |
nPoints = 3; | |
pathElementType = @"kCGPathElementAddCurveToPoint"; | |
break; | |
case kCGPathElementCloseSubpath: | |
nPoints = 0; | |
pathElementType = @"kCGPathElementCloseSubpath"; | |
break; | |
default: | |
nPoints = 0; | |
pathElementType = @"unknown path element type"; | |
return; | |
} | |
NSMutableString * pointsList = [NSMutableString new]; | |
for (int i = 0; i < nPoints; i++) | |
{ | |
[pointsList appendFormat:@" (%@)", NSStringFromCGPoint(element->points[i])]; | |
} | |
NSLog(@"%@ : %@", pathElementType, pointsList); | |
} | |
... | |
CGPathRef somePath = ...; | |
CGPathApply(somePath, NULL, outputApplier); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. BTW you may find it useful, console command does similar out of the box
p (void)CGPathPrint(pathRef, 0)
. Found in NSHipster Blog.