resize nodeset
This commit is contained in:
parent
97118c3336
commit
4d19d295e0
|
@ -160,6 +160,14 @@ class Nodeset(list):
|
|||
if refresh:
|
||||
self.set_splines()
|
||||
|
||||
def resize(self, left, length, refresh=True):
|
||||
old_left = self[0].x
|
||||
old_length = self[-1].x - old_left
|
||||
for node in self:
|
||||
node.x = left + length * (node.x - old_left) / old_length
|
||||
if refresh:
|
||||
self.set_splines()
|
||||
|
||||
|
||||
class Node(list):
|
||||
|
||||
|
@ -173,6 +181,14 @@ class Node(list):
|
|||
return self[1]
|
||||
return list.__get__(self, name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name == "x":
|
||||
list.__setitem__(self, 0, value)
|
||||
elif name == "y":
|
||||
list.__setitem__(self, 1, value)
|
||||
else:
|
||||
list.__setattr__(self, name, value)
|
||||
|
||||
|
||||
class Spline:
|
||||
|
||||
|
@ -339,6 +355,14 @@ class GUI(Animation):
|
|||
self.adjust_for_split(y_range, nodeset)
|
||||
self.set_axis_labels()
|
||||
|
||||
def get_function_coordinates(self, xp=0, yp=0):
|
||||
nodeset = self.get_nodeset()
|
||||
x_min, x_max, (y_min, y_max) = nodeset[0].x, nodeset[-1].x, self.y_range
|
||||
rect = self.plot_rect
|
||||
x = float(xp) / (rect.right - rect.left) * (x_max - x_min) + x_min
|
||||
y = float(yp) / (rect.bottom - rect.top) * (y_min - y_max) + y_max
|
||||
return x, y
|
||||
|
||||
def adjust_for_split(self, y_range, nodeset):
|
||||
middle = nodeset[0].y
|
||||
below, above = middle - y_range[0], y_range[1] - middle
|
||||
|
@ -416,11 +440,11 @@ class GUI(Animation):
|
|||
elif self.axis_labels[0][0][1].collidepoint(pos):
|
||||
text = "{0} {1}".format(*map(self.get_formatted_measure,
|
||||
self.get_nodeset()[0]))
|
||||
self.prompt.activate(text, self.set_node, 0)
|
||||
self.prompt.activate(text, self.resize_nodeset, 0)
|
||||
elif self.axis_labels[1][0][1].collidepoint(pos):
|
||||
text = "{0} {1}".format(*map(self.get_formatted_measure,
|
||||
self.get_nodeset()[-1]))
|
||||
self.prompt.activate(text, self.set_node, -1)
|
||||
self.prompt.activate(text, self.resize_nodeset, -1)
|
||||
else:
|
||||
bi = self.collide_buttons(pos)
|
||||
if bi is not None:
|
||||
|
@ -472,15 +496,20 @@ class GUI(Animation):
|
|||
self.set_markers()
|
||||
self.draw()
|
||||
|
||||
def set_node(self, text, index):
|
||||
def resize_nodeset(self, text, index):
|
||||
result = match("^\s*(-{,1}\d*\.{,1}\d*)\s+(-{,1}\d*\.{,1}\d*)\s*$",
|
||||
text)
|
||||
if result:
|
||||
try:
|
||||
nodeset = self.get_nodeset()
|
||||
old = nodeset[index]
|
||||
if nodeset.add_node(map(float, result.group(1, 2))) is not None:
|
||||
nodeset.remove(old, False)
|
||||
x, y = map(float, result.group(1, 2))
|
||||
if (index == -1 and x > nodeset[0].x) or \
|
||||
(index == 0 and x < nodeset[-1].x):
|
||||
nodeset[index].y = y
|
||||
if index == -1:
|
||||
nodeset.resize(nodeset[0].x, x - nodeset[0].x)
|
||||
else:
|
||||
nodeset.resize(x, nodeset[-1].x - x)
|
||||
self.store_in_configuration()
|
||||
self.set_y_range()
|
||||
self.set_axis_labels()
|
||||
|
@ -524,14 +553,6 @@ class GUI(Animation):
|
|||
if marker.location.collidepoint(pos):
|
||||
return marker
|
||||
|
||||
def get_function_coordinates(self, xp=0, yp=0):
|
||||
nodeset = self.get_nodeset()
|
||||
x_min, x_max, (y_min, y_max) = nodeset[0].x, nodeset[-1].x, self.y_range
|
||||
rect = self.plot_rect
|
||||
x = float(xp) / (rect.right - rect.left) * (x_max - x_min) + x_min
|
||||
y = float(yp) / (rect.bottom - rect.top) * (y_min - y_max) + y_max
|
||||
return x, y
|
||||
|
||||
def set_markers(self):
|
||||
self.markers = markers = []
|
||||
for node in self.get_nodeset()[1:-1]:
|
||||
|
|
Loading…
Reference in New Issue