The class Polygon

The class Polygon represents a polygon as its topologically sorted sequence of vertices.

class polygon.Polygon(color, vertices)

Class methods:

from_dict(dic)

returns a Polygon from a dict

Attributes:

color

the color of the polygon, an (R, G, B) tuple

Methods:

to_dict()

Returns a dict

add(p)

Adds the given Point to the polygon

bounding_box()

To be implemented. Returns the bounding box of the polygon (Rectangle)

rasterization(mtx)

To be implemented. Returns a list of pixels Point corresponding to the polygon’s rasterization with the given window-to -viewport transformations mtx

Operation

Result

pol[i]

Returns the i-th vertex of the polygon the vectorial image

The class supports the functions len, str and the comparison operator ==.

The class Polygon is implemented in the file polygon.py.

You can pass the tests of the following test files test-polygon.txt.