Skip to content

Instantly share code, notes, and snippets.

@Shehryar
Created February 4, 2015 20:40
Show Gist options
  • Save Shehryar/568600a40a6364eeee56 to your computer and use it in GitHub Desktop.
Save Shehryar/568600a40a6364eeee56 to your computer and use it in GitHub Desktop.
Prints out the CGPoint human readable representation of a UIBezierPath to console
- (void)someDrawingMethod
{
// Whatever drawing code
CGMutablePathRef pathRef = CGPathCreateMutable();
// More drawing code
UIBezierPath *path = [UIBezierPath bezierPathWithCGPath:pathRef];
CGpathRelease(pathRef);
CGPathApply(path.CGpath, NULL, outPutCGPath);
}
static void outputCGPath(void *info, const CGPathElement *element)
{
// NSMutableArray* a = (__bridge 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment