Re: Appending CGPath to CGPath
Re: Appending CGPath to CGPath
- Subject: Re: Appending CGPath to CGPath
- From: Roland King <email@hidden>
- Date: Sat, 16 Apr 2011 14:40:09 +0800
On 16-Apr-2011, at 12:23 PM, Graham Cox wrote:
>
> On 16/04/2011, at 1:55 PM, Roland King wrote:
>
>> I have a CGPath which represents a small (but somewhat complicated) shape and I want to append a number of them together, connected with straight lines, to form a complete closed shape which I then want to use as a clip region. I thought that CGPathAddPath would do what I wanted as I can easily give it an affine transform matrix to move and rotate the template path and add it several times, however if I understand the documentation correctly, that adds the path as a new subpath, not connecting it up. As I want to use the final path as a clip region that's not going to work, I need one continuous path.
>>
>> Is there a way to append two CGPaths together such that they really connect up to be one path? I can think of a way to do this with CGPathApply but it seems a bit hokey.
>>
>> The motivation is that the small, complicated, oft-repeated path is pretty slow to draw, it has a number of connected arcs and I'm drawing several thousand of them when all I really need to do is draw it once, and then add it translated and rotated, over and over again and I can construct the transformation matrices very quickly. And yes that is measured performance, not premature optimization.
>
>
> Taking your last paragraph first, I think you are deluding yourself regarding the performance gain you'll get. A transform doesn't magically avoid the need to iterate over all the path's points, it merely moves all its points elsewhere, and draws it again. It's certainly much faster than recomputing the path, but drawing?
>
Where I'm getting the most time spent is in CGPathAddArc(), and this particular shape has a lot of them. My assumption here is that CGPathAddArc, which takes two angles, is having to calculate a bunch of trig functions of those and figure out which bezier paths to add to approximate it. Once I have the path calculated once, yes to rotate and translate it I'll have to iterate over the points and multiply each of them by the transformation, but that's a quicker operation than recalculating each one of those arcs all over again from basics.
Adding them separately hasn't worked for a clip, I tried this. What that does is treat each subpath individually, close them, then check inside each of them. So if I PathAddPath my clip ends up just being the area inside each of the template shapes I added, not the area inside each of those shapes joined up by lines (the shapes themselves are open).
Looks like it's going to be CGPathApply for me. I'll tell you if it comes out any faster. _______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden