From 70534a6b6c3de76a7c63f6b734e88cfe9ec21a88 Mon Sep 17 00:00:00 2001 From: Andy Port Date: Tue, 23 Jun 2020 22:16:09 -0700 Subject: [PATCH] added vectorized points() method for bezier segments --- svgpathtools/path.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/svgpathtools/path.py b/svgpathtools/path.py index 1b1322b..3cce50a 100644 --- a/svgpathtools/path.py +++ b/svgpathtools/path.py @@ -576,6 +576,10 @@ class Line(object): distance = self.end - self.start return self.start + distance*t + def points(self, ts): + """Faster than running Path.point many times.""" + return self.poly(ts) + def length(self, t0=0, t1=1, error=None, min_depth=None): """returns the length of the line segment between t0 and t1.""" return abs(self.end - self.start)*(t1-t0) @@ -815,6 +819,10 @@ class QuadraticBezier(object): """returns the coordinates of the Bezier curve evaluated at t.""" return (1 - t)**2*self.start + 2*(1 - t)*t*self.control + t**2*self.end + def points(self, ts): + """Faster than running Path.point many times.""" + return self.poly(ts) + def length(self, t0=0, t1=1, error=None, min_depth=None): if t0 == 1 and t1 == 0: if self._length_info['bpoints'] == self.bpoints(): @@ -1073,6 +1081,10 @@ class CubicBezier(object): -self.start + 3*(self.control1 - self.control2) + self.end ))) + def points(self, ts): + """Faster than running Path.point many times.""" + return self.poly(ts) + def length(self, t0=0, t1=1, error=LENGTH_ERROR, min_depth=LENGTH_MIN_DEPTH): """Calculate the length of the path up to a certain position""" if t0 == 0 and t1 == 1: