-
Notifications
You must be signed in to change notification settings - Fork 0
evenOddFill specification
This page describes the behavior of the evenOddFill() function of the HTML5 canvas. Essentially this is intended to be equivalent to the fill() function but using the even-odd winding rule instead of the non-zero winding rule. The two winding rule options are intended to be equivalent to the SVG fill-rule property so some parts of this specification have been copied verbatim from that specification and from the existing HTML5 canvas specification.
An alternative way for controlling the winding rule is described at fillRule speification. The advantages and disadvantages of the two alternative APIs is being discussed on various forums and tracked on WebKit bug #105508.
In the end I hope this specification or the alternative, in some form or another, will be adopted as a web standard, probably as part of a larger document.
The nonZeroFill() method must fill all the subpaths of the intended path, using fillStyle, and using the non-zero winding number rule. Open subpaths must be implicitly closed when being filled (without affecting the actual subpaths).
The non-zero winding number rule determines the "insideness" of a point on the canvas by drawing a ray from that point to infinity in any direction and then examining the places where a segment of the shape crosses the ray. Starting with a count of zero, add one each time a path segment crosses the ray from left to right and subtract one each time a path segment crosses the ray from right to left. After counting the crossings, if the result is zero then the point is outside the path. Otherwise, it is inside. The following drawing illustrates the nonzero rule:
Note: Thus, if two overlapping but otherwise independent subpaths have opposite windings, they cancel out and result in no fill. If they have the same winding, that area just gets painted once.
The evenOddFill() method must fill all the subpaths of the intended path, using fillStyle, and using the even-odd winding number rule. Open subpaths must be implicitly closed when being filled (without affecting the actual subpaths).
The even-odd winding number rule determines the "insideness" of a point on the canvas by drawing a ray from that point to infinity in any direction and counting the number of path segments from the given shape that the ray crosses. If this number is odd, the point is inside; if even, the point is outside. The following drawing illustrates the evenodd rule:
Note: Thus, if two overlapping but otherwise independent subpaths have opposite windings, they cancel out and result in no fill. If they have the same winding, the rays for that area intersect both paths and is also not painted.
TODO
TODO
TODO
TODO
TODO

