HOME

TheInfoList



OR:

The even–odd rule is an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
implemented in vector-based graphic software, like the
PostScript PostScript (PS) is a page description language in the electronic publishing and desktop publishing realm. It is a dynamically typed, concatenative programming language. It was created at Adobe Systems by John Warnock, Charles Geschke, Doug Br ...
language and
Scalable Vector Graphics Scalable Vector Graphics (SVG) is an XML-based vector image format for defining two-dimensional graphics, having support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium sinc ...
(SVG), which determines how a graphical shape with more than one closed outline will be filled. Unlike the
nonzero-rule In two-dimensional computer graphics, the non-zero winding rule is a means of determining whether a given point falls within an enclosed curve. Unlike the similar even-odd rule, it relies on knowing the direction of stroke for each part of the cur ...
algorithm, this algorithm will alternatively color and leave uncolored shapes defined by nested closed paths irrespective of their winding. The SVG defines the even–odd rule by saying: The rule can be seen in effect in many vector graphic programs (such as
Freehand Freehand may refer to: * Freehand drawing, a drawing made without the help of devices * Freehand lace, a bobbin lace worked directly onto fabric * , drumming technique * Adobe FreeHand, software package * ''Free Hand'', a 1975 album by Gentle Gian ...
or
Illustrator An illustrator is an artist who specializes in enhancing writing or elucidating concepts by providing a visual representation that corresponds to the content of the associated text or idea. The illustration may be intended to clarify complicat ...
), where a crossing of an outline with itself causes shapes to fill in strange ways. On a simple curve, the even–odd rule reduces to a decision algorithm for the
point in polygon In computational geometry, the point-in-polygon (PIP) problem asks whether a given point in the plane lies inside, outside, or on the boundary of a polygon. It is a special case of point location problems and finds applications in areas that deal ...
problem. The SVG computer graphics vector standard may be configured to use the even–odd rule when drawing polygons, though it uses the non-zero rule by default.


Implementation

Below is an example implementation in
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
: def is_point_in_path(x: int, y: int, poly) -> bool: # Determine if the point is in the polygon. # # Args: # x -- The x coordinates of point. # y -- The y coordinates of point. # poly -- a list of tuples x, y), (x, y), ... # # Returns: # True if the point is in the path or is a corner or on the boundary num = len(poly) j = num - 1 c = False for i in range(num): if (x

poly 0]) and (y

poly 1]): # point is a corner return True if ((poly 1] > y) != (poly 1] > y)): slope = (x-poly 0])*(poly 1]-poly 1])-(poly 0]-poly 0])*(y-poly 1]) if slope

0: # point is on boundary return True if (slope < 0) != (poly 1] < poly 1]): c = not c j = i return c


See also

*
Nonzero-rule In two-dimensional computer graphics, the non-zero winding rule is a means of determining whether a given point falls within an enclosed curve. Unlike the similar even-odd rule, it relies on knowing the direction of stroke for each part of the cur ...
*
Jordan curve theorem In topology, the Jordan curve theorem asserts that every ''Jordan curve'' (a plane simple closed curve) divides the plane into an " interior" region bounded by the curve and an "exterior" region containing all of the nearby and far away exterior ...
*
Complex polygon The term ''complex polygon'' can mean two different things: * In geometry, a polygon in the unitary plane, which has two complex dimensions. * In computer graphics, a polygon whose boundary is not simple. Geometry In geometry, a complex polygon ...
*
Tessellation A tessellation or tiling is the covering of a surface, often a plane (mathematics), plane, using one or more geometric shapes, called ''tiles'', with no overlaps and no gaps. In mathematics, tessellation can be generalized to high-dimensional ...
*
Polygon triangulation In computational geometry, polygon triangulation is the partition of a polygonal area (simple polygon) into a set of triangles, i.e., finding a set of triangles with pairwise non-intersecting interiors whose union is . Triangulations may be v ...
*
TrueType TrueType is an outline font standard developed by Apple in the late 1980s as a competitor to Adobe's Type 1 fonts used in PostScript. It has become the most common format for fonts on the classic Mac OS, macOS, and Microsoft Windows operating sy ...


References


External links


Definition of fill rules in SVG
Computer graphics algorithms Parity (mathematics) {{compu-prog-stub