diff --git a/gaphas/connector.py b/gaphas/connector.py index d201294..f2ed0e0 100644 --- a/gaphas/connector.py +++ b/gaphas/connector.py @@ -16,9 +16,7 @@ def deprecated(message, since): @functools.wraps(func) def wrapper(*args, **kwargs): warnings.warn( - f"{func.__name__}: {message}", - category=DeprecationWarning, - stacklevel=2, + f"{func.__name__}: {message}", category=DeprecationWarning, stacklevel=2 ) return func(*args, **kwargs) @@ -56,22 +54,6 @@ class Position: pos = property(lambda s: (s.x, s.y), _set_pos) - def set_x(self, vx): - """ - Set the variable for x. - - NOTE: This changes the variable object itself, not only the value! - """ - self._v_x = vx - - def set_y(self, vy): - """ - Set the variable for y. - - NOTE: This changes the variable object itself, not only the value! - """ - self._v_y = vy - def __str__(self): return f"<{self.__class__.__name__} object on ({self.x}, {self.y})>" diff --git a/gaphas/item.py b/gaphas/item.py index 3d69b58..4ceb788 100644 --- a/gaphas/item.py +++ b/gaphas/item.py @@ -319,12 +319,6 @@ class Element(Item): h_sw = handles[SW] h_se = handles[SE] - # Share variables - h_sw.pos.set_x(h_nw.pos.x) - h_se.pos.set_x(h_ne.pos.x) - h_ne.pos.set_y(h_nw.pos.y) - h_se.pos.set_y(h_sw.pos.y) - # edge of element define default element ports self._ports = [ LinePort(h_nw.pos, h_ne.pos), @@ -336,6 +330,11 @@ class Element(Item): # initialize min_x variables self.min_width, self.min_height = 10, 10 + self.constraint(horizontal=(h_nw.pos, h_ne.pos)) + self.constraint(horizontal=(h_sw.pos, h_se.pos)) + self.constraint(vertical=(h_nw.pos, h_sw.pos)) + self.constraint(vertical=(h_ne.pos, h_se.pos)) + # create minimal size constraints self.constraint(left_of=(h_nw.pos, h_se.pos), delta=self._min_width) self.constraint(above=(h_nw.pos, h_se.pos), delta=self._min_height) diff --git a/tests/test_canvas.py b/tests/test_canvas.py index 8dacf6e..23045c7 100644 --- a/tests/test_canvas.py +++ b/tests/test_canvas.py @@ -94,13 +94,12 @@ def test_disconnect_item_with_constraint(): c.connect_item(line, line.handles()[0], b1, b1.ports()[0], constraint=cons) assert count(c.get_connections(handle=line.handles()[0])) == 1 - ncons = len(c.solver.constraints) - assert ncons == 5 + assert len(c.solver.constraints) == 13 c.disconnect_item(line, line.handles()[0]) assert count(c.get_connections(handle=line.handles()[0])) == 0 - assert len(c.solver.constraints) == 4 + assert len(c.solver.constraints) == 12 def test_disconnect_item_by_deleting_element(): @@ -141,13 +140,13 @@ def test_disconnect_item_with_constraint_by_deleting_element(): assert count(c.get_connections(handle=line.handles()[0])) == 1 ncons = len(c.solver.constraints) - assert ncons == 5 + assert ncons == 13 c.remove(b1) assert count(c.get_connections(handle=line.handles()[0])) == 0 - assert 2 == len(c.solver.constraints) + assert 6 == len(c.solver.constraints) def test_line_projection(): diff --git a/tests/test_connector.py b/tests/test_connector.py index dfdb35b..62df26b 100644 --- a/tests/test_connector.py +++ b/tests/test_connector.py @@ -11,19 +11,6 @@ def test_position(position): assert position[1] == pos.y -def test_set_xy(): - pos = Position((1, 2)) - x = Variable() - y = Variable() - assert x is not pos.x - assert y is not pos.y - - pos.set_x(x) - pos.set_y(y) - assert x is pos.x - assert y is pos.y - - def test_handle_x_y(): h = Handle() assert 0.0 == h.pos.x diff --git a/tests/test_segment.py b/tests/test_segment.py index a44ca04..62600ec 100644 --- a/tests/test_segment.py +++ b/tests/test_segment.py @@ -369,7 +369,7 @@ def test_orthogonal_line_merge(simple_canvas): """Test orthogonal line merging. """ - assert 4 == len(simple_canvas.canvas.solver._constraints) + assert 12 == len(simple_canvas.canvas.solver._constraints) simple_canvas.line.handles()[-1].pos = 100, 100 @@ -379,14 +379,14 @@ def test_orthogonal_line_merge(simple_canvas): segment.split_segment(0) simple_canvas.line.orthogonal = True - assert 4 + 3 == len(simple_canvas.canvas.solver._constraints) + assert 6 + 6 + 3 == len(simple_canvas.canvas.solver._constraints) assert 4 == len(simple_canvas.line.handles()) assert 3 == len(simple_canvas.line.ports()) # Test the merging segment.merge_segment(0) - assert 4 + 2 == len(simple_canvas.canvas.solver._constraints) + assert 6 + 6 + 2 == len(simple_canvas.canvas.solver._constraints) assert 3 == len(simple_canvas.line.handles()) assert 2 == len(simple_canvas.line.ports()) diff --git a/tests/test_undo.py b/tests/test_undo.py index 61fb46d..d0c09fe 100644 --- a/tests/test_undo.py +++ b/tests/test_undo.py @@ -11,10 +11,10 @@ def test_undo_on_delete_element(revert_undo, undo_fixture): canvas = Canvas() canvas.add(b1) - assert 2 == len(canvas.solver.constraints) + assert 6 == len(canvas.solver.constraints) canvas.add(b2) - assert 4 == len(canvas.solver.constraints) + assert 12 == len(canvas.solver.constraints) canvas.add(line) @@ -26,7 +26,7 @@ def test_undo_on_delete_element(revert_undo, undo_fixture): connector = Connector(line, line.handles()[-1]) connector.connect(sink) - assert 6 == len(canvas.solver.constraints) + assert 14 == len(canvas.solver.constraints) assert 2 == len(list(canvas.get_connections(item=line))) del undo_fixture[2][:] # Clear undo_list @@ -34,7 +34,7 @@ def test_undo_on_delete_element(revert_undo, undo_fixture): # Here disconnect is not invoked! canvas.remove(b2) - assert 3 == len(canvas.solver.constraints) + assert 7 == len(canvas.solver.constraints) assert 1 == len(list(canvas.get_connections(item=line))) cinfo = canvas.get_connection(line.handles()[0]) @@ -48,7 +48,7 @@ def test_undo_on_delete_element(revert_undo, undo_fixture): undo_fixture[0]() # Call undo - assert 6 == len(canvas.solver.constraints) + assert 14 == len(canvas.solver.constraints) assert 2 == len(list(canvas.get_connections(item=line))) cinfo = canvas.get_connection(line.handles()[0])