Miter Threshold Limits - iOS Drawing: Practical UIKit Solutions (2014)

iOS Drawing: Practical UIKit Solutions (2014)

B. Miter Threshold Limits

Chapter 4 introduces miter limits and bevels. This appendix explores their iOS implementation with practical numbers. When the diagonal length of a miter—that is, the triangular join between two lines—exceeds a path’s limit, Quartz converts those points into bevel joins. The normal geometric distance for a miter can be calculated like this:

CGFloat diagonal = (lineWidth / 2.0f) / sin(theta / 2.0f);

Quartz appears to use the value for a path of width 2 for all its cutoffs. Table B-1 details the resulting threshold values for angles between 1 and 45 degrees.

Image

Image

Image

Image

Image

Image

Image

Table B-1 Miter Limits

For example, for a Bezier path including an 8-degree angle, a miter limit of 14.3 will affect that path, but a miter limit of 14.4 will not. UIBezierPath’s default limit is 10, which will limit the miter for any angle under 11 degrees.

Table B-1 includes several sample images. These samples show an angle at the specified degree with the miter limit set just above (left) or just below (right) the critical level for that angle. What you see is the natural angle with and without a miter.

At 1 degree, the natural miter extends out about 114.6 points; in Table B-1, the first point is actually cropped out of the image due to this length. At 45 degrees, a miter extends just 2.6 points, barely rising above the alternative miter.