finished?

This commit is contained in:
2018-02-26 02:02:15 -05:00
parent 462246fda9
commit 1ab8e78c7c

View File

@@ -9,18 +9,19 @@ class Bezier:
if len(args) == 2: if len(args) == 2:
self.x = args[0] self.x = args[0]
self.y = args[1] self.y = args[1]
else:
#TODO find proper exception
raise RuntimeError('')
if 'step' in kwargs: if 'step' in kwargs:
self.step = kwargs[step] self.step = kwargs['step']
else: else:
self.step = 1e-3 self.step = 1e-3
if 'points' in kwargs:
self.points = kwargs['points']
else:
self.points = False
def __getitem__(self, t): def __getitem__(self, t):
def stepper(start, stop, step): def stepper(start, stop, step):
t = start t = start
c = lambda x,y: x>y if stop > start else lambda x,y: y>x c = (lambda x,y: x>=y) if (start > stop) else (lambda x,y: y>=x)
while c(t, stop): while c(t, stop):
yield t yield t
t += step t += step
@@ -44,18 +45,20 @@ class Bezier:
else: else:
stop = 0 stop = 0
if step is None or step == 0: if step is None or step == 0:
step = abs(self.step) if stop > step else -abs(step) step = abs(self.step) if stop > start else -abs(step)
start = min(start, 1) start = max(min(start, 1), 0)
start = max(start, 0) stop = max(min(stop, 1), 0)
stop = min(stop, 1) if self.points:
stop = max(stop, 0) return [self[i] for i in stepper(start, stop, step)]
return [self[i] for i in stepper(start, stop, step)] else:
pnts = [self[i] for i in stepper(start, stop, step)]
return [[i[0] for i in pnts], [i[1] for i in pnts]]
else: else:
n = len(self.x) - 1 n = len(self.x) - 1
x = 0 x = 0
y = 0 y = 0
for i in range(n+1): for i in range(n+1):
#eww #eww
x += self.x[i]*((1-t)**i)*(t**(n-i))*fact(n)/fact(i)/fact(n-i) x += self.x[i]*((1-t)**(n-i))*(t**i)*fact(n)/fact(i)/fact(n-i)
y += self.y[i]*((1-t)**i)*(t**(n-i))*fact(n)/fact(i)/fact(n-i) y += self.y[i]*((1-t)**(n-i))*(t**i)*fact(n)/fact(i)/fact(n-i)
return (x, y) return (x, y)