Position now takes an x and y, instead of pos
This commit is contained in:
parent
7761d8eb94
commit
1f8ad31c75
@ -24,7 +24,7 @@ class Handle:
|
||||
"""
|
||||
|
||||
def __init__(self, pos=(0, 0), strength=NORMAL, connectable=False, movable=True):
|
||||
self._pos = Position(pos, strength)
|
||||
self._pos = Position(pos[0], pos[1], strength)
|
||||
self._connectable = connectable
|
||||
self._movable = movable
|
||||
self._visible = True
|
||||
|
@ -5,7 +5,7 @@ from gaphas.solver import NORMAL, Constraint, Variable
|
||||
class Position:
|
||||
"""A point constructed of two `Variable`'s.
|
||||
|
||||
>>> vp = Position((3, 5))
|
||||
>>> vp = Position(3, 5)
|
||||
>>> vp.x, vp.y
|
||||
(Variable(3, 20), Variable(5, 20))
|
||||
>>> vp.pos
|
||||
@ -14,9 +14,9 @@ class Position:
|
||||
(Variable(3, 20), Variable(5, 20))
|
||||
"""
|
||||
|
||||
def __init__(self, pos, strength=NORMAL):
|
||||
self._x = Variable(pos[0], strength)
|
||||
self._y = Variable(pos[1], strength)
|
||||
def __init__(self, x, y, strength=NORMAL):
|
||||
self._x = Variable(x, strength)
|
||||
self._y = Variable(y, strength)
|
||||
|
||||
def _set_x(self, v):
|
||||
self._x.value = v
|
||||
@ -44,7 +44,7 @@ class Position:
|
||||
def __getitem__(self, index):
|
||||
"""Shorthand for returning the x(0) or y(1) component of the point.
|
||||
|
||||
>>> h = Position((3, 5))
|
||||
>>> h = Position(3, 5)
|
||||
>>> h[0]
|
||||
Variable(3, 20)
|
||||
>>> h[1]
|
||||
@ -61,7 +61,7 @@ class Position:
|
||||
|
||||
class MatrixProjection(Constraint):
|
||||
def __init__(self, pos: Position, matrix: Matrix):
|
||||
proj_pos = Position((0, 0), pos.strength)
|
||||
proj_pos = Position(0, 0, pos.strength)
|
||||
super().__init__(proj_pos.x, proj_pos.y, pos.x, pos.y)
|
||||
|
||||
self._orig_pos = pos
|
||||
|
@ -237,7 +237,7 @@ class GtkView(Gtk.DrawingArea, Gtk.Scrollable):
|
||||
|
||||
v2i = self.get_matrix_v2i(item)
|
||||
ix, iy = v2i.transform_point(*pos)
|
||||
item_distance = item.point(Position((ix, iy)))
|
||||
item_distance = item.point(Position(ix, iy))
|
||||
if item_distance is None:
|
||||
print(f"Item distance is None for {item}")
|
||||
continue
|
||||
|
@ -18,8 +18,8 @@ from gaphas.position import Position
|
||||
class ItemPosition:
|
||||
def __init__(self):
|
||||
self.item = Item()
|
||||
self.pos1 = Position((1, 2))
|
||||
self.pos2 = Position((3, 4))
|
||||
self.pos1 = Position(1, 2)
|
||||
self.pos2 = Position(3, 4)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@ -29,12 +29,12 @@ def item_pos():
|
||||
|
||||
def test_line_constraint(item_pos):
|
||||
"""Test line creation constraint."""
|
||||
line = (Position((3, 4)), Position((5, 6)))
|
||||
line = (Position(3, 4), Position(5, 6))
|
||||
c = constraint(line=(item_pos.pos1, line))
|
||||
|
||||
assert isinstance(c, LineConstraint)
|
||||
assert Position((1, 2)) == c._point
|
||||
assert (Position((3, 4)), Position((5, 6))) == c._line
|
||||
assert Position(1, 2) == c._point
|
||||
assert (Position(3, 4), Position(5, 6)) == c._line
|
||||
|
||||
|
||||
def test_horizontal_constraint(item_pos):
|
||||
|
@ -12,13 +12,13 @@ def solver():
|
||||
|
||||
@pytest.mark.parametrize("position", [(0, 0), (1, 2)])
|
||||
def test_position(position):
|
||||
pos = Position(position)
|
||||
pos = Position(*position)
|
||||
assert position[0] == pos.x
|
||||
assert position[1] == pos.y
|
||||
|
||||
|
||||
def test_matrix_projection_exposes_variables():
|
||||
proj = MatrixProjection(Position((0, 0)), Matrix())
|
||||
proj = MatrixProjection(Position(0, 0), Matrix())
|
||||
|
||||
assert isinstance(proj.x, Variable)
|
||||
assert isinstance(proj.y, Variable)
|
||||
@ -33,7 +33,7 @@ def test_matrix_projection_exposes_variables():
|
||||
],
|
||||
)
|
||||
def test_projection_updates_when_original_is_changed(solver, position, matrix, result):
|
||||
pos = Position((0, 0))
|
||||
pos = Position(0, 0)
|
||||
proj = MatrixProjection(pos, matrix)
|
||||
solver.add_constraint(proj)
|
||||
solver.solve()
|
||||
@ -55,7 +55,7 @@ def test_projection_updates_when_original_is_changed(solver, position, matrix, r
|
||||
],
|
||||
)
|
||||
def test_original_updates_when_projection_is_changed(solver, position, matrix, result):
|
||||
pos = Position((0, 0))
|
||||
pos = Position(0, 0)
|
||||
proj = MatrixProjection(pos, matrix)
|
||||
solver.add_constraint(proj)
|
||||
solver.solve()
|
||||
@ -71,7 +71,7 @@ def test_original_updates_when_projection_is_changed(solver, position, matrix, r
|
||||
|
||||
|
||||
def test_projection_updates_when_matrix_is_changed(solver):
|
||||
pos = Position((0, 0))
|
||||
pos = Position(0, 0)
|
||||
matrix = Matrix()
|
||||
proj = MatrixProjection(pos, matrix)
|
||||
solver.add_constraint(proj)
|
||||
@ -85,7 +85,7 @@ def test_projection_updates_when_matrix_is_changed(solver):
|
||||
|
||||
|
||||
def test_matrix_projection_sets_handlers_just_in_time():
|
||||
pos = Position((0, 0))
|
||||
pos = Position(0, 0)
|
||||
matrix = Matrix()
|
||||
proj = MatrixProjection(pos, matrix)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user