added vectorized points() method for bezier segments

pull/114/head
Andy Port 2020-06-23 22:16:09 -07:00
parent 1f7503aabd
commit 70534a6b6c
1 changed files with 12 additions and 0 deletions

View File

@ -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: