Skip to content

Instantly share code, notes, and snippets.

@adamawolf
Created October 2, 2012 21:44
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save adamawolf/3823502 to your computer and use it in GitHub Desktop.
How to print out a CGPathRef for debugging purposes
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);
@DanSkeel
Copy link

Thanks. BTW you may find it useful, console command does similar out of the box p (void)CGPathPrint(pathRef, 0). Found in NSHipster Blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment