Search code examples
iosuibezierpath

UIBezierPath support for relative paths?


I read the Apple documentation to the UIBezierPath object. Do I understand this correctly that it doesn't support relative paths?

I'm trying to convert this svg path into an UIBezierPath:

// svg path
m90 36c-7 0-13 6-13 13s6 13 13 13 13-6 13-13-6-13-13-13zm-27 32c-7 0-13 6-13 13s6 13 13 13 13-6 13-13-6-13-13-13z

I started with:

UIBezierPath* myPath = [UIBezierPath bezierPath];
CGPoint currentPoint;

[myPath moveToPoint:CGPointMake([self sizeDependendX:90], [self sizeDependendY:36])];
currentPoint = CGPathGetCurrentPoint(myPath.CGPath);
[myPath addCurveToPoint:CGPointMake(currentPoint.x - 13, currentPoint.y + 13)
          controlPoint1:CGPointMake(currentPoint.x +  7, currentPoint.y +  0)
          controlPoint2:CGPointMake(currentPoint.x - 13, currentPoint.y +  6)];
currentPoint = CGPathGetCurrentPoint(myPath.CGPath);
[myPath addCurveToPoint:CGPointMake(currentPoint.x + 13 ,currentPoint.y + 13)
          controlPoint1:CGPointMake(currentPoint.x +  0, currentPoint.y +  7)
          controlPoint2:CGPointMake(currentPoint.x +  6, currentPoint.y + 13)];
...

Is it really meant to be like that or do I miss something here?


Solution

  • Indeed, there are simply no "relative" points.

    (If really needed, it's trivial to make an extension, function, or some other sugar to make it tidy. In Swift I usually have something like

    go(across: 7.0, down: -2.5)
    go(across: 4.0, down: -2.5)
    go(across: 7.0, down: -2.5)
    

    .. sort of thing. It's only a couple lines of code for the function or extension you want.)

    Sorry for the bad news! :)


    We do a lot of bezier related stuff, here is how some typical code looks for us. I use zillions of helper calls so that the code makes more sense.

    I would say that one really has to build on Apple's primitives, when writing up code to create complicated bezier material.

    enter image description here