Class GPath

This class represents a sequence of line segements. The path is defined by the points attribute which is an (even) sequence of alternating x and y values. When drawn in a GView object, the line starts from one x-y pair in points and goes to the next x-y pair. If points has length 2n, then the result is n-1 line segments.

The class uses the attribute linecolor to determine the color of the line and the attribute linewidth to determine the width. The attribute fillcolor is unused (even though it is inherited from GObject).

The attributes width and height are present in this object, but they are now read-only. These values are computed from the list of points.

On the other hand, the attributes x and y are used. By default, these values are 0. However, if they are nonzero, then Python will add them to all of the points in the path, shifting the path accordingly.

Constructor

GPath(**keywords)

Constructor: Creates a new sequence of line segments.

To use the constructor for this class, you should provide it with a list of keyword arguments that initialize various attributes. The keywords are the same as the attribute names. For example, to create a line from (0,0) to (2,3) with width 2, use the constructor call

GLine(points=[0,0,2,3],linewidth=2)

This class supports the same keywords as GObject, though some of them are unused, as the width and height attributes are now immutable. The primary keywords for this class are points, linecolor, and linewidth.

Parameter:keywords – dictionary of keyword arguments

Precondition: See below.

Attributes

This class has all of the attributes of GObject. In addition, it has the following new or altered attributes.

points

The sequence of points that make up this line.

Invariant: Must be a sequence (list or tuple) of int or float. The length of this sequence must be even with length at least 4.

x

The horizontal coordinate of the object center.

Invariant: Must be an int or float.

y

The vertical coordinate of the object center..

Invariant: Must be an int or float.

width

The horizontal width of this path.

The value is the width of the smallest bounding box that contains all of the points in the line AND the origin (0,0).

Immutable: This value cannot be changed without changing points

Invariant: Must be an int or float > 0.

height

The vertical height of this path.

The value is the height of the smallest bounding box that contains all of the points in the line AND the origin (0,0).

Immutable: This value cannot be changed without changing points

Invariant: Must be an int or float > 0.

fillcolor

This attribute is ignored.

Methods

This class has all of the methods of GObject. In addition, it has the following new or altered methods.

contains(x, y)

Returns: True if this path contains the point (x,y), False otherwise.

This method always returns False as a GPath has no interior.

Parameter:x – x coordinate of point to check

Precondition: an int or float

Parameter:y – y coordinate of point to check

Precondition: an int or float

near(x, y)

Returns: True if this path is near the point (x,y), False otherwise.

To determine if (x,y) is near the path, we compute the minimum distances from (x,y) to the path. If this distance is less than 1e-6, we return True.

Parameter:x – x coordinate of point to check

Precondition: an int or float

Parameter:y – y coordinate of point to check

Precondition: an int or float