From a094f92b3a5541f28d63de164585064d4a312b21 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 26 Apr 2017 01:54:44 -0700 Subject: [PATCH] added polyline and polygon functions (points --> Path of Line objects) --- svgpathtools/path.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/svgpathtools/path.py b/svgpathtools/path.py index 7afd58e..41989de 100644 --- a/svgpathtools/path.py +++ b/svgpathtools/path.py @@ -97,6 +97,21 @@ def bbox2path(xmin, xmax, ymin, ymax): return Path(b, r, t.reversed(), l.reversed()) +def polyline(*points): + """Converts a list of points to a Path composed of lines connecting those + points (i.e. a linear spline or polyline). See also `polygon()`.""" + return Path(*[Line(points[i], points[i+1]) + for i in range(len(points) - 1)]) + + +def polygon(*points): + """Converts a list of points to a Path composed of lines connecting those + points, then closes the path by connecting the last point to the first. + See also `polyline()`.""" + return Path(*[Line(points[i], points[(i + 1) % len(points)]) + for i in range(len(points))]) + + # Conversion################################################################### def bpoints2bezier(bpoints):