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¶
- class game2d.GPath(**keywords)¶
A class representing a sequence of line segments
The path is defined by the
points
attribute which is an (even) sequence of alternating x and y values. When drawn in aGView
object, the line starts from one x-y pair inpoints
and goes to the next x-y pair. Ifpoints
has length 2n, then the result is n-1 line segments.The object uses the attribute
linecolor
to determine the color of the line and the attributelinewidth
to determine the width. The attributefillcolor
is unused (even though it is inherited fromGObject
).The attributes
width
andheight
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
andy
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.
Attributes¶
This class has all of the attributes of GObject. In addition, it has the following new or altered attributes.
- GPath.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.
- GPath.x¶
The horizontal coordinate of the object center.
invariant: Value must be an
int
orfloat
- GPath.y¶
The vertical coordinate of the object center.
invariant: Value must be an
int
orfloat
- GPath.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).
Invariant: Must be an int or float > 0.
- GPath.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).
Invariant: Must be an int or float > 0.
- GPath.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.
- GPath.contains(point)¶
Checks whether this shape contains the point
This method always returns False as a
GPath
has no interior.- Parameters
point (
Point2`
or a pair of numbers) – the point to check- Returns
True if the shape contains this point
- Return type
bool
- GPath.near(point)¶
Checks whether this path is near the given point
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 e-6, we return True.
- Parameters
point (
Point2`
or a pair of numbers) – the point to check- Returns
True if this path is near the give point; False otherwise.
- Return type
bool