Skip to content

Instantly share code, notes, and snippets.

@pita5
Created December 17, 2011 15:21
Show Gist options
  • Save pita5/1490480 to your computer and use it in GitHub Desktop.
Save pita5/1490480 to your computer and use it in GitHub Desktop.
static void clipApplier(void *info, const CGPathElement *element)
{
NSMutableArray *a = (NSMutableArray*)info;
int nPoints;
switch (element->type)
{
case kCGPathElementMoveToPoint:
nPoints = 1;
break;
case kCGPathElementAddLineToPoint:
nPoints = 1;
break;
case kCGPathElementAddQuadCurveToPoint:
nPoints = 2;
break;
case kCGPathElementAddCurveToPoint:
nPoints = 3;
break;
case kCGPathElementCloseSubpath:
nPoints = 0;
break;
default:
[a replaceObjectAtIndex:0 withObject:[NSNumber numberWithBool:NO]];
return;
}
if (nPoints > 0)
{
CGPoint *p = element->points;
for (int i = 0; i < nPoints; i++)
{
if (p->x > 320 || p->x < 0 || p->y < 0 || p->y > 460)
return;
p++;
}
}
NSNumber *type = [NSNumber numberWithInt:element->type];
NSData *points = [NSData dataWithBytes:element->points length:nPoints*sizeof(CGPoint)];
[a addObject:[NSDictionary dictionaryWithObjectsAndKeys:type,@"type",points,@"points",nil]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment