~ubuntu-branches/debian/sid/pyx/sid

« back to all changes in this revision

Viewing changes to manual/path.rst

  • Committer: Package Import Robot
  • Author(s): Stuart Prescott
  • Date: 2012-12-17 13:45:12 UTC
  • mto: (9.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20121217134512-q85pr3q75fxii7mq
Tags: upstream-0.12.1
Import upstream version 0.12.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
1
2
.. module:: path
2
3
 
3
4
==================
11
12
the present section.
12
13
 
13
14
 
 
15
.. _postscript_like_paths:
 
16
 
14
17
Class :class:`path` --- PostScript-like paths
15
18
---------------------------------------------
16
19
 
36
39
 
37
40
.. method:: path.arclen()
38
41
 
39
 
   Returns the total arc length of the path.\ :math:`^\dagger`
 
42
   Returns the total arc length of the path. [#normpathconvert]_
40
43
 
41
44
 
42
45
.. method:: path.arclentoparam(lengths)
43
46
 
44
 
   Returns the parameter value(s) corresponding to the arc length(s) *lengths*.\
45
 
   :math:`^\dagger`
 
47
   Returns the parameter value(s) corresponding to the arc length(s) *lengths*.
 
48
   [#normpathconvert]_
46
49
 
47
50
 
48
51
.. method:: path.at(params)
49
52
 
50
53
   Returns the coordinates (as 2-tuple) of the path point(s) corresponding to the
51
 
   parameter value(s) *params*.\ :math:`^\ddagger` :math:`^\dagger`
 
54
   parameter value(s) *params*. [#normpathconvert]_ [#value_or_list]_
52
55
 
53
56
 
54
57
.. method:: path.atbegin()
55
58
 
56
 
   Returns the coordinates (as 2-tuple) of the first point of the path.\
57
 
   :math:`^\dagger`
 
59
   Returns the coordinates (as 2-tuple) of the first point of the path. [#normpathconvert]_
58
60
 
59
61
 
60
62
.. method:: path.atend()
61
63
 
62
 
   Returns the coordinates (as 2-tuple) of the end point of the path.\
63
 
   :math:`^\dagger`
 
64
   Returns the coordinates (as 2-tuple) of the end point of the path. [#normpathconvert]_
64
65
 
65
66
 
66
67
.. method:: path.bbox()
67
68
 
68
 
   Returns the bounding box of the path. Note that this returned bounding box may
69
 
   be too large, if the path contains any :class:`curveto` elements, since for
70
 
   these the control box, i.e., the bounding box enclosing the control points of
71
 
   the Bézier curve is returned.
 
69
   Returns the bounding box of the path.
72
70
 
73
71
 
74
72
.. method:: path.begin()
77
75
   point in the path.
78
76
 
79
77
 
80
 
.. method:: path.curveradius(param=None, arclen=None)
 
78
.. method:: path.curveradius(params)
81
79
 
82
80
   Returns the curvature radius/radii (or None if infinite) at parameter value(s)
83
 
   params.\ :math:`^\ddagger` This is the inverse of the curvature at this
 
81
   *params*. [#value_or_list]_ This is the inverse of the curvature at this
84
82
   parameter. Note that this radius can be negative or positive, depending on the
85
 
   sign of the curvature.\ :math:`^\dagger`
 
83
   sign of the curvature. [#normpathconvert]_
86
84
 
87
85
 
88
86
.. method:: path.end()
99
97
.. method:: path.intersect(opath)
100
98
 
101
99
   Returns a tuple consisting of two lists of parameter values corresponding to the
102
 
   intersection points of the path with the other path *opath*, respectively.\
103
 
   :math:`^\dagger` For intersection points which are not farther apart then
104
 
   *epsilon* points, only one is returned.
 
100
   intersection points of the path with the other path *opath*, respectively.
 
101
   [#normpathconvert]_ For intersection points which are not farther apart then
 
102
   *epsilon* (defaulting to :math:`10^{-5}` PostScript points), only one is returned.
105
103
 
106
104
 
107
105
.. method:: path.joined(opath)
108
106
 
109
107
   Appends *opath* to the end of the path, thereby merging the last subpath (which
110
108
   must not be closed) of the path with the first sub path of *opath* and returns
111
 
   the resulting new path.\ :math:`^\dagger`
 
109
   the resulting new path. [#normpathconvert]_ Instead of using the
 
110
   :meth:`joined` method, you can also join two paths together with help of the
 
111
   ``<<`` operator, for instance ``p = p1 << p2``.
112
112
 
113
113
 
114
114
.. method:: path.normpath(epsilon=None)
115
115
 
116
116
   Returns the equivalent :class:`normpath`. For the conversion and for later
117
 
   calculations with this :class:`normpath` and accuracy of *epsilon* points is
118
 
   used. If *epsilon* is *None*, the global *epsilon* of the :mod:`path` module is
 
117
   calculations with this :class:`normpath` an accuracy of *epsilon* is used.
 
118
   If *epsilon* is *None*, the global *epsilon* of the :mod:`path` module is
119
119
   used.
120
120
 
121
121
 
122
122
.. method:: path.paramtoarclen(params)
123
123
 
124
 
   Returns the arc length(s) corresponding to the parameter value(s) *params*.\
125
 
   :math:`^\ddagger` :math:`^\dagger`
 
124
   Returns the arc length(s) corresponding to the parameter value(s) *params*.
 
125
   [#value_or_list]_ [#normpathconvert]_
126
126
 
127
127
 
128
128
.. method:: path.range()
132
132
 
133
133
.. method:: path.reversed()
134
134
 
135
 
   Returns the reversed path.\ :math:`^\dagger`
 
135
   Returns the reversed path. [#normpathconvert]_
136
136
 
137
137
 
138
138
.. method:: path.rotation(params)
139
139
 
140
 
   Returns (a) rotations(s) which (each), which rotate the x-direction to the
141
 
   tangent and the y-direction to the normal at that param.\ :math:`^\dagger`
 
140
   Returns a transformation or a list of transformations, which rotate the
 
141
   x-direction to the tangent vector and the y-direction to the normal vector
 
142
   at the parameter value(s) *params*. [#value_or_list]_ [#normpathconvert]_
142
143
 
143
144
 
144
145
.. method:: path.split(params)
145
146
 
146
147
   Splits the path at the parameter values *params*, which have to be sorted in
147
148
   ascending order, and returns a corresponding list of :class:`normpath`
148
 
   instances.\ :math:`^\dagger`
 
149
   instances. [#normpathconvert]_
149
150
 
150
151
 
151
152
.. method:: path.tangent(params, length=1)
152
153
 
153
 
   Return (a) :class:`line` instance(s) corresponding to the tangent vector(s) to
154
 
   the path at the parameter value(s) *params*.\ :math:`^\ddagger` The tangent
155
 
   vector will be scaled to the length *length*.\ :math:`^\dagger`
 
154
   Return a :class:`line` instance or a list of :class:`line` instances,
 
155
   corresponding to the tangent vectors at the parameter value(s) *params*.
 
156
   [#value_or_list]_ The tangent vector will be scaled to the length *length*.
 
157
   [#normpathconvert]_
156
158
 
157
159
 
158
160
.. method:: path.trafo(params)
159
161
 
160
 
   Returns (a) trafo(s) which (each) translate to a point on the path corresponding
161
 
   to the param, rotate the x-direction to the tangent and the y-direction to the
162
 
   normal in that point.\ :math:`^\dagger`
 
162
   Returns a transformation or a list of tranformations, which translate the
 
163
   origin to a point on the path corresponding to parameter value(s) *params*
 
164
   and rotate the x-direction to the tangent vector and the y-direction to the
 
165
   normal vector. [#normpathconvert]_
163
166
 
164
167
 
165
168
.. method:: path.transformed(trafo)
166
169
 
167
170
   Returns the path transformed according to the linear transformation *trafo*.
168
 
   Here, ``trafo`` must be an instance of the :class:`trafo.trafo` class.\
169
 
   :math:`^\dagger`
170
 
 
171
 
Some notes on the above:
172
 
 
173
 
* The :math:`\dagger` denotes methods which require a prior conversion of the
174
 
  path into a :class:`normpath` instance. This is done automatically (using the
175
 
  precision *epsilon* set globally using :meth:`path.set`). If you need a
176
 
  different *epsilon* for a normpath, you also can perform the conversion
177
 
  manually.
178
 
 
179
 
* Instead of using the :meth:`joined` method, you can also join two paths
180
 
  together with help of the ``<<`` operator, for instance ``p = p1 << p2``.
181
 
 
182
 
* :math:`^\ddagger` In these methods, *params* may either be a single value or a
183
 
  list. In the latter case, the result of the method will be a list consisting of
184
 
  the results for every parameter.  The parameter itself may either be a length
185
 
  (or a number which is then interpreted as a user length) or an instance of the
186
 
  class :class:`normpathparam`. In the former case, the length refers to the arc
187
 
  length along the path.
 
171
   Here, ``trafo`` must be an instance of the :class:`trafo.trafo` class.
 
172
   [#normpathconvert]_
 
173
 
 
174
 
 
175
.. [#normpathconvert]
 
176
   This method requires a prior conversion of the path into a :class:`normpath`
 
177
   instance. This is done automatically (using the precision *epsilon* set
 
178
   globally using :meth:`path.set`). If you need a different *epsilon* for a
 
179
   normpath, you also can perform the conversion manually.
 
180
 
 
181
.. [#value_or_list]
 
182
   In these methods, *params* may either be a single value or a
 
183
   list. In the latter case, the result of the method will be a list consisting of
 
184
   the results for each parameter.  The parameter itself may either be a length
 
185
   (or a number which is then interpreted as a user length) or an instance of the
 
186
   class :class:`normpathparam`. In the former case, the length refers to the arc
 
187
   length along the path.
188
188
 
189
189
 
190
190
.. _path_pathitem:
225
225
 
226
226
.. class:: rlineto(dx, dy)
227
227
 
228
 
   Path element which appends a straight line from the current point to the a point
 
228
   Path element which appends a straight line from the current point to the point
229
229
   with relative coordinates (*dx*, *dy*), which becomes the new current point.
230
230
 
231
231
For the construction of arc segments, the following three operations are
237
237
   Path element which appends an arc segment in counterclockwise direction with
238
238
   absolute coordinates (*x*, *y*) of the center and  radius *r* from *angle1* to
239
239
   *angle2* (in degrees).  If before the operation, the current point is defined, a
240
 
   straight line is from the current point to the beginning of the arc segment is
 
240
   straight line from the current point to the beginning of the arc segment is
241
241
   prepended. Otherwise, a subpath, which thus is the first one in the path, is
242
242
   opened. After the operation, the current point is at the end of the arc segment.
243
243
 
244
244
 
245
245
.. class:: arcn(x, y, r, angle1, angle2)
246
246
 
247
 
   Path element which appends an arc segment in clockwise direction with absolute
248
 
   coordinates (*x*, *y*) of the center and  radius *r* from *angle1* to *angle2*
249
 
   (in degrees).  If before the operation, the current point is defined, a straight
250
 
   line is from the current point to the beginning of the arc segment is prepended.
251
 
   Otherwise, a subpath, which thus is the first one in the path, is opened. After
252
 
   the operation, the current point is at the end of the arc segment.
 
247
   Same as :class:`arc` but in clockwise direction.
253
248
 
254
249
 
255
250
.. class:: arct(x1, y1, x2, y2, r)
256
251
 
257
 
   Path element which appends an arc segment of radius *r* connecting between
258
 
   (*x1*, *y1*) and (*x2*, *y2*). ---
259
 
 
260
 
Bézier curves can be constructed using: \
261
 
 
 
252
   Path element consisting of a line followed by an arc of radius *r*. The arc
 
253
   is part of the circle inscribed to the angle at *x1*, *y1* given by lines in
 
254
   the directions to the current point and to *x2*, *y2*. The initial line
 
255
   connects the current point to the point where the circle touches the line
 
256
   through the current point and *x1*, *y1*. The arc then continues to the
 
257
   point where the circle touches the line through *x1*, *y1* and *x2*, *y2*.
 
258
 
 
259
Bézier curves can be constructed using:
262
260
 
263
261
.. class:: curveto(x1, y1, x2, y2, x3, y3)
264
262
 
292
290
.. class:: multilineto_pt(points_pt)
293
291
 
294
292
   Path element which appends straight line segments starting from the current
295
 
   point and going through the list of points given  in the *points_pt* argument.
296
 
   All coordinates have to  be given in PostScript points.
 
293
   point and going through the list of points given in the *points_pt*
 
294
   argument. All coordinates have to be given in PostScript points.
297
295
 
298
296
 
299
297
.. class:: multicurveto_pt(points_pt)
300
298
 
301
 
   Path element which appends Bézier curve segments starting from the current point
302
 
   and going through the list of each three control points given in the *points_pt*
303
 
   argument. Thus, *points_pt* must be a sequence of 6-tuples.
 
299
   Path element which appends Bézier curve segments starting from the current
 
300
   point. *points_pt* is a sequence of 6-tuples containing the coordinates of
 
301
   the two control points and the end point of a multicurveto segment.
304
302
 
305
303
 
306
304
.. _path_normpath:
309
307
-----------------------
310
308
 
311
309
The :class:`normpath` class is used internally for all non-trivial path
312
 
operations, i.e. the ones marked by a :math:`\dagger` in the description of the
313
 
:class:`path` above. It represents a path as a list of subpaths, which are
 
310
operations, cf. footnote [#normpathconvert]_ in Sect. :ref:`postscript_like_paths`.
 
311
It represents a path as a list of subpaths, which are
314
312
instances of the class :class:`normsubpath`. These :class:`normsubpath`\ s
315
313
themselves consist of a list of :class:`normsubpathitems` which are either
316
314
straight lines (:class:`normline`) or Bézier curves (:class:`normcurve`).
317
315
 
318
 
A given path can easily be converted to the corresponding :class:`normpath`
319
 
using the method with this name::
 
316
A given path ``p`` can easily be converted to the corresponding
 
317
:class:`normpath` ``np`` by::
320
318
 
321
319
   np = p.normpath()
322
320
 
323
 
Additionally, you can specify the accuracy (in points) which is used in all
324
 
:class:`normpath` calculations by means of the argument *epsilon*, which
325
 
defaults to to :math:`10^{-5}` points. This default value can be changed using
326
 
the module function :func:`path.set`.
 
321
Additionally, the accuracy is used in all :class:`normpath` calculations can be
 
322
specified by means of the argument *epsilon*, which defaults to to
 
323
:math:`10^{-5}` where units of PostScript points are understood. This default
 
324
value can be changed using the module function :func:`path.set`.
327
325
 
328
326
To construct a :class:`normpath` from a list of :class:`normsubpath` instances,
329
 
you pass them to the :class:`normpath` constructor:
330
 
 
 
327
they are passed to the :class:`normpath` constructor:
331
328
 
332
329
.. class:: normpath(normsubpaths=[])
333
330
 
334
331
   Construct a :class:`normpath` consisting of *subnormpaths*, which is a list of
335
332
   :class:`subnormpath` instances.
336
333
 
337
 
Instances of :class:`normpath` offers all methods of regular :class:`path`\ s,
 
334
Instances of :class:`normpath` offer all methods of regular :class:`path` instances,
338
335
which also have the same semantics. An exception are the methods :meth:`append`
339
336
and :meth:`extend`. While they allow for adding of instances of
340
337
:class:`subnormpath` to the :class:`normpath` instance, they also keep the
341
338
functionality of a regular path and allow for regular path elements to be
342
 
appended. The later are converted to the proper normpath representation during
 
339
appended. The latter are converted to the proper normpath representation during
343
340
addition.
344
341
 
345
342
In addition to the :class:`path` methods, a :class:`normpath` instance also
377
374
   list of :class:`normsubpathitem` instances. If *closed* is set, the
378
375
   :class:`normsubpath` will be closed, thereby appending a straight line segment
379
376
   from the first to the last point, if it is not already present. All calculations
380
 
   with the :class:`normsubpath` are performed with an accuracy of *epsilon*.
 
377
   with the :class:`normsubpath` are performed with an accuracy of *epsilon*
 
378
   (in units of PostScript points).
381
379
 
382
380
Most :class:`normsubpath` methods behave like the ones of a :class:`path`.
383
381
 
386
384
 
387
385
.. method:: normsubpath.append(anormsubpathitem)
388
386
 
389
 
   Append the *anormsubpathitem* to the end of the :class:`normsubpath` instance.
 
387
   Append the *normsubpathitem* to the end of the :class:`normsubpath` instance.
390
388
   This is only possible if the :class:`normsubpath` is not closed, otherwise an
391
 
   exception is raised.
 
389
   :exc:`NormpathException` is raised.
392
390
 
393
391
 
394
392
.. method:: normsubpath.extend(normsubpathitems)
395
393
 
396
394
   Extend the :class:`normsubpath` instances by *normsubpathitems*, which has to be
397
395
   a list of :class:`normsubpathitem` instances. This is only possible if the
398
 
   :class:`normsubpath` is not closed, otherwise an exception is raised.
 
396
   :class:`normsubpath` is not closed, otherwise an :exc:`NormpathException` is
 
397
   raised.
399
398
 
400
399
 
401
400
.. method:: normsubpath.close()
402
401
 
403
 
   Close the :class:`normsubpath` instance, thereby appending a straight line
404
 
   segment from the first to the last point, if it is not already present.
 
402
   Close the :class:`normsubpath` instance by appending a straight line
 
403
   segment from the first to the last point, if not already present.
405
404
 
406
405
 
407
406
.. _path_predefined:
410
409
----------------
411
410
 
412
411
 
413
 
For convenience, some oft-used paths are already predefined. All of them are
 
412
For convenience, some often used paths are already predefined. All of them are
414
413
subclasses of the :class:`path` class.
415
414
 
416
415