October 10, 2011
Presented without context or comment:
- (void)printBezierCode {
static int printBezierCodeIdx = 0;
printBezierCodeIdx++;
printf("\n");
printf("NSBezierPath *p%d = [NSBezierPath bezierPath];\n", printBezierCodeIdx);
NSBezierPath *p = [self bezierPath];
NSInteger i;
NSInteger numElements = [p elementCount];
if (numElements > 0)
{
NSPoint points[3];
for (i = 0; i < numElements; i++)
{
switch ([p elementAtIndex:i associatedPoints:points])
{
case NSMoveToBezierPathElement:
printf("[p%d moveToPoint:NSMakePoint(%f, %f)];\n",
printBezierCodeIdx, points[0].x, points[0].y);
break;
case NSLineToBezierPathElement:
printf("[p%d lineToPoint:NSMakePoint(%f, %f)];\n",
printBezierCodeIdx, points[0].x, points[0].y);
break;
case NSCurveToBezierPathElement:
printf("[p%d curveToPoint:NSMakePoint(%f, %f) "
"controlPoint1:NSMakePoint(%f, %f) "
"controlPoint2:NSMakePoint(%f, %f)];\n",
printBezierCodeIdx,
points[2].x, points[2].y,
points[0].x, points[0].y,
points[1].x, points[1].y);
break;
case NSClosePathBezierPathElement:
printf("[p%d closePath];\n", printBezierCodeIdx);
break;
}
}
}
}
Formatting adjusted for this post.
