Understand SVG graphics filling rules

Source: Internet
Author: User

This article is translated from the SVG specification on the w3.org website and serves as a memo for beginners of SVG.

Original Website:
SVG fill-Rule property in SVG 1.1 (second edition)

The SVG graphics filling rule is passedFill-ruleAttribute.

'Fill-rule'
Valid values: Nonzero | evenodd |
Inherit
Default Value: Nonzero
Applicable: Shape elements and

Text Content Element
Inheritance: Yes
Proportion: None
Media: Visible
Animation available: Yes

'Fill-rule'
Attribute is used to specify the algorithm used to determine whether an area on the canvas belongs to the image "internal" (the internal area will be filled ). For a simple non-crossover path, which area is "internal" is intuitively cleared. However, for a complex path, such as self-intersection or a sub-path surrounding another sub-path, the "internal" Understanding is not that clear.

'Fill-rule'
Attribute provides two options to specify how to determine the image's "internal ":

Nonzero
It is literally "non-zero ". According to this rule, it is necessary to determine whether a point is in the graph, from which a ray is taken in any direction, and then detect the intersection between the ray and the graph path. Counting starts from 0. If the path passes through the ray from left to right, the count is increased by 1. If the path passes through the ray from right to left, the count is reduced by 1. After the counting result is obtained, if the result is 0, the vertex is considered to be external to the image; otherwise, the result is considered to be internal. Demonstrate nonzero rules:

Click to view the sample SVG file (only applicable to browsers that support SVG)

Evenodd
The literal meaning is "parity ". According to this rule, you need to determine whether a point is in the graph, from which a ray is taken in any direction, and then check the number of intersections between the ray and the graph path. If the result is an odd number, the vertex is considered to be an internal vertex. If the result is an even number, the vertex is considered to be an external vertex. Demonstrated Evenodd
Rules:

Click to view the sample SVG file (only applicable to browsers that support SVG)

(Note: The above explanation does not indicate what to do when the path fragment is coincident or tangent to the ray, because any direction of the ray can be, you only need to simply select another ray without such special circumstances .)

This article is translated from the SVG specification on the w3.org website and serves as a memo for beginners of SVG.

Original Website:
SVG fill-Rule property in SVG 1.1 (second edition)

The SVG graphics filling rule is passedFill-ruleAttribute.

'Fill-rule'
Valid values: Nonzero | evenodd |
Inherit
Default Value: Nonzero
Applicable: Shape elements and

Text Content Element
Inheritance: Yes
Proportion: None
Media: Visible
Animation available: Yes

'Fill-rule'
Attribute is used to specify the algorithm used to determine whether an area on the canvas belongs to the image "internal" (the internal area will be filled ). For a simple non-crossover path, which area is "internal" is intuitively cleared. However, for a complex path, such as self-intersection or a sub-path surrounding another sub-path, the "internal" Understanding is not that clear.

'Fill-rule'
Attribute provides two options to specify how to determine the image's "internal ":

Nonzero
It is literally "non-zero ". According to this rule, it is necessary to determine whether a point is in the graph, from which a ray is taken in any direction, and then detect the intersection between the ray and the graph path. Counting starts from 0. If the path passes through the ray from left to right, the count is increased by 1. If the path passes through the ray from right to left, the count is reduced by 1. After the counting result is obtained, if the result is 0, the vertex is considered to be external to the image; otherwise, the result is considered to be internal. Demonstrate nonzero rules:

Click to view the sample SVG file (only applicable to browsers that support SVG)

Evenodd
The literal meaning is "parity ". According to this rule, you need to determine whether a point is in the graph, from which a ray is taken in any direction, and then check the number of intersections between the ray and the graph path. If the result is an odd number, the vertex is considered to be an internal vertex. If the result is an even number, the vertex is considered to be an external vertex. Demonstrated Evenodd
Rules:

Click to view the sample SVG file (only applicable to browsers that support SVG)

(Note: The above explanation does not indicate what to do when the path fragment is coincident or tangent to the ray, because any direction of the ray can be, you only need to simply select another ray without such special circumstances .)

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.