zoukankan      html  css  js  c++  java
  • Filling a Path 模式

    Filling a Path

    When you fill the current path, Quartz acts as if each subpath contained in the path were closed. It then uses these closed subpaths and calculates the pixels to fill. There are two ways Quartz can calculate the fill area. Simple paths such as ovals and rectangles have a well-defined area. But if your path is composed of overlapping segments or if the path includes multiple subpaths, such as the concentric circles shown in Figure 3-12, there are two rules you can use to determine the fill area.

    The default fill rule is called the nonzero winding number rule. To determine whether a specific point should be painted, start at the point and draw a line beyond the bounds of the drawing. Starting with a count of 0, add 1 to the count every time a path segment crosses the line from left to right, and subtract 1 every time a path segment crosses the line from right to left. If the result is 0, the point is not painted. Otherwise, the point is painted. The direction that the path segments are drawn affects the outcome.Figure 3-12 shows two sets of inner and outer circles that are filled using the nonzero winding number rule. When each circle is drawn in the same direction, both circles are filled. When the circles are drawn in opposite directions, the inner circle is not filled.

    You can opt to use the even-odd rule. To determine whether a specific point should be painted, start at the point and draw a line beyond the bounds of the drawing. Count the number of path segments that the line crosses. If the result is odd, the point is painted. If the result is even, the point is not painted. The direction that the path segments are drawn doesn’t affect the outcome. As you can see in Figure 3-12, it doesn’t matter which direction each circle is drawn, the fill will always be as shown.

    Figure 3-12  Concentric circles filled using different fill rulesConcentric circles filled using different fill rules

    Quartz provides the functions shown in Table 3-5 for filling the current path. Some are convenience functions for stroking rectangles or ellipses.

    Table 3-5  Functions that fill paths

    Function

    Description

    CGContextEOFillPath

    Fills the current path using the even-odd rule.

    CGContextFillPath

    Fills the current path using the nonzero winding number rule.

    CGContextFillRect

    Fills the area that fits inside the specified rectangle.

    CGContextFillRects

    Fills the areas that fits inside the specified rectangles.

    CGContextFillEllipseInRect

    Fills an ellipse that fits inside the specified rectangle.

    CGContextDrawPath

    Fills the current path if you pass kCGPathFill (nonzero winding number rule) or kCGPathEOFill (even-odd rule). Fills and strokes the current path if you pass kCGPathFillStroke orkCGPathEOFillStroke.

    nonzero winding number rule

    非零就画原则  路径从左向右就+1,从右向左-1,如果结果非零就画,反之不画

    even-odd rule(奇偶规则)

    路径被穿过的次数,总计次数为奇数就画,偶数就不画

  • 相关阅读:
    Docker学习(一)
    mysql定时任务
    如何查看电脑是几核的?
    卸载Mysql connect 6.9.9
    找不到该项目怎么删除
    jmeter录制app脚本
    postman使用
    排查linux系统是否被入侵
    部署apache-tomcat环境
    sudo初级授权设置
  • 原文地址:https://www.cnblogs.com/sanjianghuiliu/p/3665293.html
Copyright © 2011-2022 走看看