Concept

Even–odd rule

Résumé
The even–odd rule is an algorithm implemented in vector-based graphic software, like the PostScript language and Scalable Vector Graphics (SVG), which determines how a graphical shape with more than one closed outline will be filled. Unlike the nonzero-rule 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: This 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 rule can be seen in effect in many vector graphic programs (such as Freehand or Illustrator), 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 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. Below is a partial example implementation in Python: def is_point_in_path(x: int, y: int, poly) -> bool:

Determine if the point is on the path, corner, or boundary of the polygon

Args:

x -- The x coordinates of point.

y -- The y coordinates of point.

poly -- a list of tuples [(x, y), (x, y), ...

À propos de ce résultat
Cette page est générée automatiquement et peut contenir des informations qui ne sont pas correctes, complètes, à jour ou pertinentes par rapport à votre recherche. Il en va de même pour toutes les autres pages de ce site. Veillez à vérifier les informations auprès des sources officielles de l'EPFL.