Module metapost.path

The metapost subpackage provides some of the path functionality of the MetaPost program. The metapost.path presents the path construction facility of MetaPost.

Similarly to the normpath, there is a short length epsilon (always in Postscript points pt) used as accuracy of numerical operations, such as calculating angles from short path elements, or for omitting such short path elements, etc. The default value is \(10^{-5}\) and can be changed using the module function metapost.set().

Class path — MetaPost-like paths

class metapost.path.path(pathitems, epsilon=None)

This class represents a MetaPost-like path which is created from the given list of knots and curves/lines. It can find an optimal way through given points.

At points (knots), you can either specify a given tangent direction (angle in degrees) or a certain curlyness (relative to the curvature at the other end of a curve), or nothing. In the latter case, both the tangent and the mock curvature (an approximation to the real curvature, introduced by J. D. Hobby in MetaPost) will be continuous.

The shape of the cubic Bezier curves between two points is controlled by its tension, unless you choose to set the control points manually.

All possible path items are described below. They are either Knots or Links. Note that there is no explicit closepath class. Whether the path is open or closed depends on the type of knots used, begin endpoints or not. Note also that the number of knots and links must be equal for closed paths, and that you cannot create a path comprising closed subpaths.

The epsilon argument governs the accuracy of the calculations implied in creating the path (see above). The value None means fallback to the default epsilon of the module.

Instances of the class path inherit all properties of the Postscript paths in path.

Knots

class metapost.path.beginknot(x, y, curl=1, angle=None)

The first knot, starting an open path at the coordinates (x, y). The properties of the curve in that point can either be given by its curlyness (default) or the angle of its tangent vector (in degrees). The curl parameter is (as in MetaPost) the ratio of the curvatures at this point and at the other point of the curve connecting it.

class metapost.path.startknot(x, y, curl=1, angle=None)

Synonym for beginknot.

class metapost.path.endknot(x, y, curl=1, angle=None)

The last knot of an open path. Curlyness and angle are the same as in beginknot.

class metapost.path.smoothknot(x, y)

This knot is the standard knot of MetaPost. It guarantees continuous tangent vectors and mock curvatures of the two curves it connects.

Note: If one of the links is a line, the knot is changed to a roughknot with either a specified angle (if the keepangles parameter is set in the line) or with curl=1.

class metapost.path.roughknot(x, y, left_curl=1, right_curl=None, left_angle=None, right_angle=None)

This knot is a possibly non-smooth knot, connecting two curves or lines. At each side of the knot (left/right) you can specify either the curlyness or the tangent angle.

Note: If one of the links is a line with the keepangles parameter set, the angles will be set eplicitly, regardless of any curlyness set.

class metapost.path.knot(x, y)

Synonym for smoothknot.