Re: Calculating accurate bounds of stroked paths [SOLVED]

2008-07-09 Thread Peter Zegelin
On 09/07/2008, at 5:24 PM, Graham Cox wrote: You will need to also take into account of the line width (as I'm sure you do) so I think the combined offset would be best expressed as: max(w / 2, ml * w / 2) where ml is the mitre limit. That's right, and precisely what I'

Re: Calculating accurate bounds of stroked paths [SOLVED]

2008-07-09 Thread Graham Cox
On 9 Jul 2008, at 5:11 pm, Chris Suter wrote: You could ignore the mitre limit and assume it was always mitre joint and it would give you a worst case bounds. However, it wouldn't be sensible to do that since the bounds would stretch out excessively for very acute angles. Without knowing

Re: Calculating accurate bounds of stroked paths [SOLVED]

2008-07-09 Thread Chris Suter
Hi Graham, On 09/07/2008, at 4:37 PM, Graham Cox wrote: On 9 Jul 2008, at 4:02 pm, Chris Suter wrote: so you can get a worst case bounds by ignoring the mitre limit. No you can't. If the stroke width is 'w' then you can outset the bounds by w/2 to enclose the path for straight edges and a

Re: Calculating accurate bounds of stroked paths [SOLVED]

2008-07-08 Thread Graham Cox
On 9 Jul 2008, at 4:37 pm, Graham Cox wrote: Thus the angle 'a' of the corner is equal to 2*sin(w/m) That of course should be 'arcsin', not 'sin' Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or

Re: Calculating accurate bounds of stroked paths

2008-07-08 Thread Graham Cox
Indeed, I think this is the same as m = 2w/sin(a). But for worst case bounds, the angle itself doesn't need to be measured or known, only the miter limit. Thanks for your help! cheers, Graham On 9 Jul 2008, at 4:34 pm, Peter Zegelin wrote: Cool I got it right - finally! Its on page 154

Re: Calculating accurate bounds of stroked paths [SOLVED]

2008-07-08 Thread Graham Cox
On 9 Jul 2008, at 4:02 pm, Chris Suter wrote: so you can get a worst case bounds by ignoring the mitre limit. No you can't. If the stroke width is 'w' then you can outset the bounds by w/2 to enclose the path for straight edges and angles >= 90 degrees. When there is a more acute angle

Re: Calculating accurate bounds of stroked paths

2008-07-08 Thread Peter Zegelin
Cool I got it right - finally! Its on page 154 of the spec (174 in PDF viewer) section 4.3. Me in another post "I believe the fully correct answer to calculate the extension is: (strokeWidth/2)/ sin(angle/2);" Peter On 09/07/2008, at 4:02 PM, Chris Suter wrote: "The miter limit help

Re: Calculating accurate bounds of stroked paths

2008-07-08 Thread Peter Zegelin
Ok - one last time!! I believe the fully correct answer to calculate the extension is: (strokeWidth/2)/ sin(angle/2); Take a stroke width of 20 half of which is 10. At 90deg the extension is: 10/sin(45) = 14.2 At 45deg the extension is 10/sin(22.5) = 26.1 At the limit of approx. 11deg the

Re: Calculating accurate bounds of stroked paths

2008-07-08 Thread Chris Suter
Hi Graham, On 08/07/2008, at 10:16 PM, Graham Cox wrote: A close second best would be a rect that was the worst case bounds for a given stroke width (it wouldn't need to know the actual path, just its basic bounds), which thus assumed that all angles were acute enough to trigger the mitre

Re: Calculating accurate bounds of stroked paths

2008-07-08 Thread Peter Zegelin
Actually Graham I think I got it a bit wrong. I was working by induction and it just happened that the two data points more or less worked. My picture at 45 deg wasn't actually 45 deg (I did it on sight). However I believe the correct value uses the sin. eg sin(11.5deg) = .199, sin(45) = .7

Re: Calculating accurate bounds of stroked paths

2008-07-08 Thread Peter Zegelin
Graham, Since no-one else has replied and I'm going to have to figure out this myself, I thought I'd take a stab at it. I've uploaded some screen shots http://www.fracturedsoftware.com/downloads/Stroke20.tiff and http://www.fracturedsoftware.com/downloads/Stroke30.tiff of a simple poly l

Re: Calculating accurate bounds of stroked paths

2008-07-08 Thread Kai
Hi, have you checked CGContextReplacePathWithStrokedPath (CGContextRef c) ? This together with CGRect CGContextGetPathBoundingBox (CGContextRef c) might do the trick for you. Best, Kai On 8.7.2008, at 14:16, Graham Cox wrote: I need to know a rect within which all pixels will be painted f

Re: Calculating accurate bounds of stroked paths

2008-07-08 Thread Matt Gough
Graham, I know this issue has cropped up before (probably on the Quartz list). Have your searched its archives? A simple answer to this sort of question involves painting the path into a bitmap and hunting for the boundary Matt On 8 Jul 2008, at 2:16pm, Graham Cox wrote: I need to know

Calculating accurate bounds of stroked paths

2008-07-08 Thread Graham Cox
I need to know a rect within which all pixels will be painted for a given path and stroke width. I'd prefer not to make this rect any larger than it really needs to be. To compute this, I have to factor in all sorts of bits and pieces such as the angles of the line joins, miter limits and s