PyX — Example: path/split.py

0.3 KB
3.6 KB
0.5 KB
0.8 KB

Splitting paths

split.png
from pyx import *

p = path.curve(0, 0, 1, 0, 1, 1, 2, 1)
p1, p2, p3 = p.split([0.5, p.end()-0.5])

c = canvas.canvas()
c.stroke(p, [style.linewidth.Thin, color.rgb.red])
c.stroke(p2, [style.linewidth.Thick, color.rgb.green])
c.writeEPSfile("split")
c.writePDFfile("split")

Description

In this example we use the split method of a path to split it into several paths. Similar to the at method you can pass a list of numbers to the split method (or PyX length instances) to specify the splitting point by the arc length or you can use parametrization instances like the one returned by the end method, where you can substract a length to conventiently express a certain location measured from the end of the path.

For a single splitting point, you can also pass the parameter directly instead of warpping this single value into a list. Note, however, that the return value of the split method is always a list; splitting a non-closed path at one point still yields two segments.

When splitting at the beginning or the end of the path, one segment may be empty. Still PyX returns a corresponding path of length 0.

When splitting at non-closed subpaths the result of the split method will be a list containing one path more than the number of splitting points. However, for a closed subpath a splitting at a single point will open the subpath but return a single path only. Consider a circle which you split at a single value: The result will still be a circle, but the path will not be closed anymore.