1 \section{Module
\module{path
}}
3 \sectionauthor{J\"org Lehmann
}{joergl@users.sourceforge.net
}
7 The
\module{path
} module defines several important classes which are
8 documented in the present section.
10 \subsection{Class
\class{path
} --- PostScript-like paths
}
14 \declaremodule{}{path
}
16 \begin{classdesc
}{path
}{*pathitems
}
17 This class represents a PostScript like path consisting of the
18 path elements
\var{pathitems
}.
20 All possible path items are described in Sect.~
\ref{path:pathitem
}.
21 Note that there are restrictions on the first path element and likewise
22 on each path element after a
\class{closepath
} directive. In both cases,
23 no current point is defined and the path element has to be an instance
24 of one of the following classes:
\class{moveto
},
\class{arc
}, and
28 Instances of the class
\class{path
} provide the following
29 methods (in alphabetic order):
31 \begin{methoddesc
}{append
}{pathitem
}
32 Appends a
\var{pathitem
} to the end of the path.
35 \begin{methoddesc
}{arclen
}{}
36 Returns the total arc length of the path.$^
\dagger$
39 \begin{methoddesc
}{arclentoparam
}{lengths
}
40 Returns the parameter values corresponding to the arc lengths
41 \var{lengths
}.$^
\dagger$
44 \begin{methoddesc
}{at
}{param=None, arclen=None
}
45 Returns the coordinates (as
2-tuple) of the path point corresponding
46 to the parameter value
\var{param
} or, alternatively, the arc length
47 \var{arclen
}.$^
\ddagger$ At discontinuities in the path, the limit
48 from below is returned.$^
\dagger$
51 \begin{methoddesc
}{bbox
}{}
52 Returns the bounding box of the path. Note that this returned
53 bounding box may be too large, if the path contains any
54 \class{curveto
} elements, since for these the control box, i.e., the
55 bounding box enclosing the control points of the B\'ezier curve is
59 \begin{methoddesc
}{begin
}{}
60 Returns the coordinates (as
2-tuple) of the first point of the path.$^
\dagger$
63 \begin{methoddesc
}{curvradius
}{param=None, arclen=None
}
64 Returns the curvature radius (or None if infinite) at parameter
65 param or, alternatively, arc length
\var{arclen
}.$^
\ddagger$ This is
66 the inverse of the curvature at this parameter. Note that this
67 radius can be negative or positive, depending on the sign of the
71 \begin{methoddesc
}{end
}{}
72 Returns the coordinates (as
2-tuple) of the end point of the path.$^
\dagger$
75 \begin{methoddesc
}{intersect
}{opath
}
76 Returns a tuple consisting of two lists of parameter values
77 corresponding to the intersection points of the path with the other
78 path
\var{opath
}, respectively.$^
\dagger$
81 \begin{methoddesc
}{joined
}{opath
}
82 Appends
\var{opath
} to the end of the path, thereby merging the last
83 subpath (which must not be closed) of the path with the first sub
84 path of
\var{opath
} and returns the resulting new path.$^
\dagger$
87 \begin{methoddesc
}{range
}{}
88 Returns the maximal parameter value
\var{param
} that is allowed in the
92 \begin{methoddesc
}{reversed
}{}
93 Returns the reversed path.$^
\dagger$
96 \begin{methoddesc
}{split
}{params
}
97 Splits the path at the parameters
\var{params
}, which have to be
98 sorted in ascending order, and returns a corresponding list of
99 \class{normpath
} instances.$^
\dagger$
102 \begin{methoddesc
}{tangent
}{param=None, arclen=None, length=None
}
103 Return a
\class{line
} instance corresponding to the tangent vector
104 to the path at the parameter value
\var{param
} or, alternatively,
105 the arc length
\var{arclen
}.$^
\ddagger$ At discontinuities in the
106 path, the limit from below is returned. If
\var{length
} is not
107 \texttt{None
}, the tangent vector will be scaled
108 correspondingly.$^
\dagger$
112 \begin{methoddesc
}{trafo
}{param=None, arclen=None
}
113 Returns a trafo which maps a point $(
0,
1)$ to the tangent vector to
114 the path at the parameter value
\var{param
} or, alternatively, the
115 arc length
\var{arclen
}.$^
\ddagger$ At discontinuities in the path,
116 the limit from below is returned.$^
\dagger$
119 \begin{methoddesc
}{transformed
}{trafo
}
120 Returns the path transformed according to the linear transformation
121 \var{trafo
}. Here,
\texttt{trafo
} must be an instance of the
122 \class{trafo.trafo
} class.$^
\dagger$
125 Some notes on the above:
127 \item The $
\dagger$ denotes methods which require a prior
128 conversion of the path into a
\class{normpath
} instance. This is
129 done automatically, but if you need to call such methods often or
130 if you need to change the precision used for this conversion,
131 it is a good idea to manually perform the conversion.
132 \item Instead of using the
\method{joined()
} method, you can also join two
133 paths together with help of the
\verb|<<| operator, for instance
135 \item $^
\ddagger$ In the methods accepting both a parameter value
136 \var{param
} and an arc length
\var{arclen
}, exactly one of these
137 arguments has to provided. Each argument can either be a
138 number/length or a tuple. In the former case, the parameter value
139 \var{param
} (
\var{arclen
}) refers to the whole path and has to be
140 smaller or equal to
\method{self.range()
} (
\method{self.arclen()
}),
141 otherwise an exception is raised. In the latter case, the first
142 element has to be an integer specifying the subpath and the second
143 element specifies the parameter value or the arc length inside of
147 \subsection{Path elements
}
149 \label{path:pathitem
}
151 The class
\class{pathitem
} is the superclass of all PostScript path
152 construction primitives. It is never used directly, but only by
153 instantiating its subclasses, which correspond one by one to the
154 PostScript primitives.
156 Except for the path elements ending in
\code{_pt
}, all coordinates
157 passed to the path elements can be given as number (in which case they
158 are interpreted as user units with the currently set default type) or in
161 The following operation move the current point and open a new subpath:
163 \begin{classdesc
}{moveto
}{x, y
}
164 Path element which sets the current point to the absolute coordinates (
\var{x
},
165 \var{y
}). This operation opens a new subpath.
168 \begin{classdesc
}{rmoveto
}{dx, dy
}
169 Path element which moves the current point by (
\var{dx
},
\var{dy
}).
170 This operation opens a new subpath.
173 Drawing a straight line can be accomplished using:
175 \begin{classdesc
}{lineto
}{x, y
}
176 Path element which appends a straight line from the current point to the
177 point with absolute coordinates (
\var{x
},
\var{y
}), which becomes
178 the new current point.
181 \begin{classdesc
}{rlineto
}{dx, dy
}
182 Path element which appends a straight line from the current point to the
183 a point with relative coordinates (
\var{dx
},
\var{dy
}), which becomes
184 the new current point.
187 For the construction of arc segments, the following three operations
190 \begin{classdesc
}{arc
}{x, y, r, angle1, angle2
}
191 Path element which appends an arc segment in counterclockwise direction
192 with absolute coordinates (
\var{x
},
\var{y
}) of the center and
193 radius
\var{r
} from
\var{angle1
} to
\var{angle2
} (in degrees).
194 If before the operation, the current point is defined, a straight line
195 is from the current point to the beginning of the arc segment is
196 prepended. Otherwise, a subpath, which thus is the first one in the
197 path, is opened. After the operation, the current point is at the end
201 \begin{classdesc
}{arcn
}{x, y, r, angle1, angle2
}
202 Path element which appends an arc segment in clockwise direction
203 with absolute coordinates (
\var{x
},
\var{y
}) of the center and
204 radius
\var{r
} from
\var{angle1
} to
\var{angle2
} (in degrees).
205 If before the operation, the current point is defined, a straight line
206 is from the current point to the beginning of the arc segment is
207 prepended. Otherwise, a subpath, which thus is the first one in the
208 path, is opened. After the operation, the current point is at the end
212 \begin{classdesc
}{arct
}{x1, y1, x2, y2, r
}
213 Path element which appends an arc segment of radius
\var{r
}
214 connecting between (
\var{x1
},
\var{y1
}) and (
\var{x2
},
\var{y2
}).\\
217 B\'ezier curves can be constructed using: \
219 \begin{classdesc
}{curveto
}{x1, y1, x2, y2, x3, y3
}
220 Path element which appends a B\'ezier curve with
221 the current point as first control point and the other control points
222 (
\var{x1
},
\var{y1
}), (
\var{x2
},
\var{y2
}), and (
\var{x3
},
\var{y3
}).
225 \begin{classdesc
}{rcurveto
}{dx1, dy1, dx2, dy2, dx3, dy3
}
226 Path element which appends a B\'ezier curve with
227 the current point as first control point and the other control points
228 defined relative to the current point by the coordinates
229 (
\var{dx1
},
\var{dy1
}), (
\var{dx2
},
\var{dy2
}), and (
\var{dx3
},
\var{dy3
}).
232 Note that when calculating the bounding box (see Sect.~
\ref{bbox
}) of
233 B\'ezier curves,
\PyX{} uses for performance reasons the so-called
234 control box, i.e., the smallest rectangle enclosing the four control
235 points of the B\'ezier curve. In general, this is not the smallest
236 rectangle enclosing the B\'ezier curve.
238 Finally, an open subpath can be closed using:
240 \begin{classdesc
}{closepath
}{}
241 Path element which closes the current subpath.
244 For performance reasons, two non-PostScript path elements are defined,
245 which perform multiple identical operations:
247 \begin{classdesc
}{multilineto_pt
}{points_pt
}
248 Path element which appends straight line segments starting from
249 the current point and going through the list of points given
250 in the
\var{points_pt
} argument. All coordinates have to
251 be given in PostScript points.
254 \begin{classdesc
}{multicurveto_pt
}{points_pt
}
255 Path element which appends B\'ezier curve segments starting from
256 the current point and going through the list of each three control
257 points given in the
\var{points_pt
} argument.
261 \subsection{Class
\class{normpath
}}
263 \label{path:normpath
}
265 The
\class{normpath
} class represents a specialized form of a
266 \class{path
} containing only the elements
\class{moveto
},
267 \class{lineto
},
\class{curveto
} and
\class{closepath
}. Such normalized
268 paths are used for all of the more sophisticated path operations
269 which are denoted by a $
\dagger$ in the description of the
\class{path
}
272 Any path can easily be converted to its normalized form by passing it
273 as parameter to the
\class{normpath
} constructor,
277 Additionally, you can specify the accuracy (in points) which is used
278 in all
\class{normpath
} calculations by means of the keyword argument
279 \var{epsilon
}, which defaults to $
10^
{-
5}$. Note that the sum of a
280 \class{normpath
} and a
\class{path
} always yields a
\class{normpath
}.
282 \begin{classdesc
}{normpath
}{arg=
[], epsilon=
1e-5}
283 Construct a normpath from
\var{arg
}. All numerical calculations will
284 be performed using an accuracy of the order of
\var{epsilon
} points.
285 The first argument
\var{arg
} can be a
\class{path
} or a another
286 \class{normpath
} instance. Alternatively, a list of
287 \class{normsubpath
} instances can be supplied as argument.
290 In addition to the
\class{path
} methods, a
\class{normpath
} instance
291 also offers the following methods, which operate on the instance itself:
293 \begin{methoddesc
}{join
}{other
}
294 Join
\var{other
}, which has to be a
\class{path
} instance, to
295 the
\class{normpath
} instance.
298 \begin{methoddesc
}{reverse
}{}
299 Reverses the
\class{normpath
} instance.
302 \begin{methoddesc
}{transform
}{trafo
}
303 Transforms the
\class{normpath
} instance according to the linear
304 transformation
\var{trafo
}.
307 \subsection{Predefined paths
}
309 \label{path:predefined
}
311 For convenience, some oft-used paths are already predefined. All
312 of them are subclasses of the
\class{path
} class.
314 \begin{classdesc
}{line
}{x0, y0, x1, y1
}
315 A straight line from the point (
\var{x0
},
\var{y0
}) to the point (
\var{x1
},
\var{y1
}).
318 \begin{classdesc
}{curve
}{x0, y0, x1, y1, x2, y2, x3, y3
}
319 A B\'ezier curve with
320 control points (
\var{x0
},
\var{y0
}), $
\dots$, (
\var{x3
},
\var{y3
}).\
323 \begin{classdesc
}{rect
}{x, y, w, h
}
324 A closed rectangle with lower left point (
\var{x
},
\var{y
}), width
\var{w
}, and
328 \begin{classdesc
}{circle
}{x, y, r
}
329 A closed circle with center (
\var{x
},
\var{y
}) and radius
\var{r
}.
334 %%% TeX-master: "manual.tex"
335 %%% ispell-dictionary: "british"