Created
February 4, 2015 20:40
-
-
Save Shehryar/568600a40a6364eeee56 to your computer and use it in GitHub Desktop.
Prints out the CGPoint human readable representation of a UIBezierPath to console
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
- (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