Pergunta

my CGPathRef has 5 elements, i want to remove the starting point, and have a path with 4 elements whose beginning point is the same as the end of the path whose starting point i want to remove.

this is my function now which generates an exception:

static void constructPath(void *info, const CGPathElement *element) 
{
    NSBezierPath *bezierPath = (NSBezierPath *)info; 
    switch (element->type) {
        case kCGPathElementMoveToPoint:
            // some kind of skipping using points[0] kCGPathElementMoveToPoint
            [bezierPath lineToPoint:element->points[1]]; // line exception in gdb
            [bezierPath lineToPoint:element->points[2]];
            [bezierPath lineToPoint:element->points[3]];
            [bezierPath lineToPoint:element->points[4]];
            break;
        case kCGPathElementAddLineToPoint:

            if ([bezierPath isEmpty]) {
                [bezierPath moveToPoint:element->points[0]]; // the new start, how to go to next from here ?
            } else {

                [bezierPath moveToPoint:element->points[1]];
                [bezierPath moveToPoint:element->points[2]];
                [bezierPath moveToPoint:element->points[3]];
                [bezierPath moveToPoint:element->points[4]];
            }
            break;
        default:
            break;
    }
}
Foi útil?

Solução

Just ignore the first element of the original path (which is of type kCGPathElementMoveToPoint). Then for each line, add a new line, except when the path is empty, in which case you need to move to the original point.

static void constructPath(void *info, const CGPathElement *element)
{
    NSBezierPath *bezierPath = (NSBezierPath *)info;
    if ( kCGPathElementAddLineToPoint == element->type )
    {
        if ( [bezierPath isEmpty] ) {
            [bezierPath moveToPoint:element->points[0]];
        } else {
            [bezierPath lineToPoint:element->points[0]];
        }
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top