7
7
import math
8
8
import sys
9
9
10
- EPSILON = sys .float_info .epsilon
10
+ EPSILON = 1e-10 # sys.float_info.epsilon
11
11
12
12
def lerp (a , b , t ):
13
13
return a + (b - a ) * t
@@ -179,10 +179,11 @@ def bezier_interpolate(p0, p1, p2, p3, x):
179
179
# solve for x = 0
180
180
roots = bezier_cubic_roots (pa , pb , pc , pd )
181
181
if not roots :
182
+ # fall back to old method or decrease EPSILON precision?
182
183
assert False
183
184
184
185
# use the root as t for y
185
- y = cubic_bezier (p0 [1 ], p1 [1 ], p2 [1 ], p3 [1 ], roots [0 ])
186
+ y = cubic_bezier (p0 [1 ], p1 [1 ], p2 [1 ], p3 [1 ], min ( 1.0 , max ( 0 , roots [0 ])) )
186
187
return y
187
188
188
189
def bezier_interpolate_old (p0 , p1 , p2 , p3 , t ):
@@ -195,7 +196,7 @@ def bezier_interpolate_old(p0, p1, p2, p3, t):
195
196
196
197
# approximate the correct t value,
197
198
# maybe this is the newtonian method?
198
- # I kind of made it up, its slow but seems to work..
199
+ # I kind of made it up, its slow but seems to work
199
200
for i in range (20 ):
200
201
x = cubic_bezier (p0 [0 ], p1 [0 ], p2 [0 ], p3 [0 ], guess_t )
201
202
if x == t :
0 commit comments