do not keep filehandles around; instead use the same file open method at all places
[PyX/mjg.git] / examples / drawing / pathitem.txt
blob5909ff7dd3f15f3d8b55522aa8fd9249eccdf914
1 Constructing paths from pathitems
3 In this example, some simple paths are constructed out of pathitems, which are
4 the basic building blocks of paths. While we only use `moveto`, `lineto` and
5 `closepath` instances, we can already see some features of paths in PyX. ...
7 In the first path instance `rect1`, we alternatingly use `moveto` and `lineto`
8 pathitem instances. A `moveto` instance sets an internal ''current point'',
9 while a `lineto` instance additionally creates a straight line connecting the
10 old and the new ''current point''. Due to the intermediate `moveto`
11 instances, we generate a path which contains 4 separate subpaths. When
12 stroking this path with a thick linewidth in order to show the details, the
13 corners of the result exhibits that the individual lines are not connected.
15 In the second case `rect2`, we skip the intermediate `moveto` instances. The
16 default join method between pathitems within a single subpath is to miter them.
17 This results in a different rendering except for the start and end point of the
18 path.
20 In order to get rid of the ragged effect at the corners, we close the path as
21 shown by `rect3`. Here, one can (and should) skip the last connecting line since
22 a `closepath` pathitem implicitly adds a straight connection line between the
23 first and the last point of the subpath.
25 ! PyX resembles the full PostScript path model. The whole PostScript path
26 construction functionality is available by means of pathitems and the resulting
27 PostScript code will make use of the corresponding PostScript operators. For
28 PDF output, where some of the PostScript features are not available (all forms
29 of arcs are missing in PDF), proper replacement code is generated automatically.
31 !! You might ask why you should skip the last straight connection line of
32 finite length when closing a path. This is not a question of reducing the file
33 size but increasing the rendering stability of the drawing. The problem is that
34 in case of rounding errors a very short connection line might mistakenly be
35 inserted when rendering a `closepath`. Depending on the linejoin setting, this
36 can create a major visual defect.