1 .. module:: metapost.path
3 ===========================
4 Module :mod:`metapost.path`
5 ===========================
7 .. sectionauthor:: Michael Schindler <m-schindler@users.sourceforge.net>
9 The :mod:`metapost` subpackage provides some of the path functionality of the
10 MetaPost program. The :mod:`metapost.path` presents the path construction
13 Similarly to the :mod:`normpath`, there is a short length *epsilon* (always in
14 Postscript points pt) used as accuracy of numerical operations, such as
15 calculating angles from short path elements, or for omitting such short path
16 elements, etc. The default value is :math:`10^{-5}` and can be changed using
17 the module function :func:`metapost.set`.
20 Class :class:`path` --- MetaPost-like paths
21 -------------------------------------------
23 .. class:: path(pathitems, epsilon=None)
25 This class represents a MetaPost-like path which is created from the given
26 list of knots and curves/lines. It can find an optimal way through given
29 At points (knots), you can either specify a given tangent direction (angle
30 in degrees) or a certain *curlyness* (relative to the curvature at the other
31 end of a curve), or nothing. In the latter case, both the tangent and the
32 *mock* curvature (an approximation to the real curvature, introduced by J. D.
33 Hobby in MetaPost) will be continuous.
35 The shape of the cubic Bezier curves between two points is controlled by
36 its *tension*, unless you choose to set the control points manually.
38 All possible path items are described below. They are either :ref:`knots` or
39 :ref:`links`. Note that there is no explicit `closepath` class. Whether the
40 path is open or closed depends on the type of knots used, begin endpoints or
41 not. Note also that the number of knots and links must be equal for closed
42 paths, and that you cannot create a path comprising closed subpaths.
44 The *epsilon* argument governs the accuracy of the calculations implied in
45 creating the path (see above). The value *None* means fallback to the
46 default epsilon of the module.
48 Instances of the class :class:`path` inherit all properties of the Postscript
57 .. class:: beginknot(x, y, curl=1, angle=None)
59 The first knot, starting an open path at the coordinates (*x*, *y*). The
60 properties of the curve in that point can either be given by its curlyness
61 (default) or the angle of its tangent vector (in degrees). The *curl*
62 parameter is (as in MetaPost) the ratio of the curvatures at this point and
63 at the other point of the curve connecting it.
65 .. class:: startknot(x, y, curl=1, angle=None)
67 Synonym for :class:`beginknot`.
69 .. class:: endknot(x, y, curl=1, angle=None)
71 The last knot of an open path. Curlyness and angle are the same as in
74 .. class:: smoothknot(x, y)
76 This knot is the standard knot of MetaPost. It guarantees continuous tangent
77 vectors and *mock curvatures* of the two curves it connects.
79 Note: If one of the links is a line, the knot is changed to a
80 :class:`roughknot` with either a specified angle (if the *keepangles*
81 parameter is set in the line) or with *curl=1*.
83 .. class:: roughknot(x, y, left_curl=1, right_curl=None, left_angle=None, right_angle=None)
85 This knot is a possibly non-smooth knot, connecting two curves or lines. At
86 each side of the knot (left/right) you can specify either the curlyness or
89 Note: If one of the links is a line with the *keepangles* parameter set, the
90 angles will be set eplicitly, regardless of any curlyness set.
94 Synonym for :class:`smoothknot`.
102 .. class:: line(keepangles=False)
104 A straight line which corresponds to the MetaPost command "--". The option
105 *keepangles* will guarantee a continuous tangent. (The curvature may become
106 discontinuous, however.) This behavior is achieved by turning adjacent knots
107 into roughknots with specified angles. Note that a smoothknot and a
108 roughknot with given curlyness do behave differently near a line.
110 .. class:: tensioncurve(ltension=1, latleast=False, rtension=None, ratleast=None)
112 The standard type of curve in MetaPost. It corresponds to the MetaPost
113 command ".." or to "..." if the *atleast* parameters are set to True. The
114 tension parameters indicate the tensions at the beginning (l) and the end
115 (r) of the curve. Set the parameters (l/r)atleast to True if you want to
116 avoid inflection points.
118 .. class:: controlcurve(lcontrol, rcontrol)
120 A cubic Bezier curve which has its control points explicity set, similar to
121 the :class:`path.curveto` class of the Postscript paths. The control points
122 at the beginning (l) and the end (r) must be coordinate pairs (x, y).
124 .. class:: curve(ltension=1, latleast=False, rtension=None, ratleast=None)
126 Synonym for :class:`tensioncurve`.