Understanding the graphics fill rules for SVG

Source: Internet
Author: User

The graphics fill rule for SVG is specified by the fill-rule property.

Valid values: Nonzero | EvenOdd | Inherit
Default value: Nonzero

The Fill-rule property is used to specify which algorithm is used to determine whether an area on the canvas belongs to the "inside" of the drawing (the inner area is populated). For a simple no-cross path, which area is "internal" is very intuitive to clear. However, for a complex path, such as a self-intersecting or a sub-path enclosing another subpath, the "inner" understanding is less clear.

  

Nonzero
It literally means "not 0." According to this rule, to determine whether a point in the graph, from the point of a ray in any direction, and then detect the ray and graphics path intersection. Counting from 0 onwards, the path passes from left to right through the ray and the count is 1, and the right-to-left pass through the ray counts minus 1. After the result of the count, if the result is 0, the point is considered to be outside the graph, otherwise it is considered internal. Demonstrates the nonzero rule:

Click to view the sample SVG file (for SVG-enabled browsers only)

EvenOdd
It literally means "odd and even". According to this rule, to determine whether a point is within the graph, a ray from that point in any direction, and then detect the number of points of intersection of the Ray and the graphics path. If the result is odd then the point is considered to be inside, and the even number is considered to be the point outside. Demonstrates the evenodd rule:

Click to view the sample SVG file (for SVG-enabled browsers only)

(Hint: The above explanation does not indicate what to do when the path fragment coincides with the ray or tangent, because the ray in any direction is possible, then simply select another ray without this particular case.) )

Understanding the graphics fill rules for SVG

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.