update Interpolator for python3

This commit is contained in:
Frank DeMarco 2019-07-03 15:28:46 -04:00
parent 17b52242c5
commit 499d722189
1 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,7 @@ class Interpolator(list, GameChild):
def set_nodesets(self):
config = self.get_configuration()
if config.has_section("interpolate"):
for name, value in config.get_section("interpolate").iteritems():
for name, value in config.get_section("interpolate").items():
self.add_nodeset(name, value)
def add_nodeset(self, name, value, method=None):
@ -66,7 +66,7 @@ class Nodeset(list):
else:
self.set_interpolation_method(self.CUBIC, False)
for node in raw[1:].strip().split(","):
self.add_node(map(float, node.strip().split()), False)
self.add_node(list(map(float, node.strip().split())), False)
def set_interpolation_method(self, method, refresh=True):
self.interpolation_method = method
@ -104,7 +104,7 @@ class Nodeset(list):
def set_linear_splines(self):
self.splines = splines = []
for ii in xrange(len(self) - 1):
for ii in range(len(self) - 1):
x1, y1, x2, y2 = self[ii] + self[ii + 1]
m = float(y2 - y1) / (x2 - x1)
splines.append(LinearSpline(x1, y1, m))
@ -114,30 +114,30 @@ class Nodeset(list):
a = [node.y for node in self]
b = [None] * n
d = [None] * n
h = [self[ii + 1].x - self[ii].x for ii in xrange(n)]
h = [self[ii + 1].x - self[ii].x for ii in range(n)]
alpha = [None] + [(3.0 / h[ii]) * (a[ii + 1] - a[ii]) - \
(3.0 / h[ii - 1]) * (a[ii] - a[ii - 1]) \
for ii in xrange(1, n)]
for ii in range(1, n)]
c = [None] * (n + 1)
l = [None] * (n + 1)
u = [None] * (n + 1)
z = [None] * (n + 1)
l[0] = 1
u[0] = z[0] = 0
for ii in xrange(1, n):
for ii in range(1, n):
l[ii] = 2 * (self[ii + 1].x - self[ii - 1].x) - \
h[ii - 1] * u[ii - 1]
u[ii] = h[ii] / l[ii]
z[ii] = (alpha[ii] - h[ii - 1] * z[ii - 1]) / l[ii]
l[n] = 1
z[n] = c[n] = 0
for jj in xrange(n - 1, -1, -1):
for jj in range(n - 1, -1, -1):
c[jj] = z[jj] - u[jj] * c[jj + 1]
b[jj] = (a[jj + 1] - a[jj]) / h[jj] - \
(h[jj] * (c[jj + 1] + 2 * c[jj])) / 3
d[jj] = (c[jj + 1] - c[jj]) / (3 * h[jj])
self.splines = [CubicSpline(self[ii].x, a[ii], b[ii], c[ii],
d[ii]) for ii in xrange(n)]
d[ii]) for ii in range(n)]
def get_y(self, t, loop=False, reverse=False, natural=False):
if loop or reverse:
@ -150,7 +150,7 @@ class Nodeset(list):
elif t > self[-1].x:
t = self[-1].x
splines = self.splines
for ii in xrange(len(splines) - 1):
for ii in range(len(splines) - 1):
if t < splines[ii + 1].x:
return splines[ii].get_y(t)
return splines[-1].get_y(t)
@ -601,7 +601,7 @@ class GUI(Animation):
surface = self.display_surface
nodeset = self.get_nodeset()
step = 1
for x in xrange(rect.left, rect.right + step, step):
for x in range(rect.left, rect.right + step, step):
ii = x - rect.left
fx = nodeset.get_y(self.get_function_coordinates(ii)[0])
y = self.get_plot_coordinates(y=fx)[1]