Example #1
0
def test_line_constraint(pos1):
    """Test line creation constraint."""
    line = (Position(3, 4), Position(5, 6))
    c = constraint(line=(pos1, line))

    assert isinstance(c, LineConstraint)
    assert Position(1, 2) == c._point
    assert (Position(3, 4), Position(5, 6)) == c._line
def test_position_notifies_on_pos_change(handler):
    pos = Position(3, 3)
    pos.add_handler(handler)

    pos.pos = (4, 4)

    assert len(handler.events) == 1
    assert handler.events[0][0] is pos
    assert handler.events[0][1] == (3.0, 3.0)
def test_position_notifies_on_y_change(handler):
    pos = Position(3, 3)
    pos.add_handler(handler)

    pos.y = 4

    assert handler.events
    assert handler.events[0][0] is pos
    assert handler.events[0][1] == (3.0, 3.0)
def test_projection_updates_when_original_is_changed(solver, position, matrix,
                                                     result):
    pos = Position(0, 0)
    proj = MatrixProjection(pos, matrix)
    solver.add_constraint(proj)
    solver.solve()

    pos.x, pos.y = position
    solver.solve()

    assert proj.x == result[0]
    assert proj.y == result[1]
def test_projection_updates_when_matrix_is_changed(solver):
    pos = Position(0, 0)
    matrix = Matrix()
    proj = MatrixProjection(pos, matrix)
    solver.add_constraint(proj)
    solver.solve()

    matrix.translate(2, 3)
    solver.solve()

    assert proj.x == 2
    assert proj.y == 3
Example #6
0
    def __init__(
        self,
        pos: Pos = (0, 0),
        strength: int = NORMAL,
        connectable: bool = False,
        movable: bool = True,
    ) -> None:
        """Create a new handle.

        Position is in item  coordinates.
        """
        self._pos = Position(pos[0], pos[1], strength)
        self._connectable = connectable
        self._movable = movable
        self._visible = True
def test_matrix_projection_sets_handlers_just_in_time():
    pos = Position(0, 0)
    matrix = Matrix()
    proj = MatrixProjection(pos, matrix)

    def handler(c):
        pass

    assert not matrix._handlers
    assert not pos.x._handlers
    assert not pos.y._handlers

    proj.add_handler(handler)

    assert matrix._handlers
    assert pos.x._handlers
    assert pos.y._handlers

    proj.remove_handler(handler)

    assert not matrix._handlers
    assert not pos.x._handlers
    assert not pos.y._handlers
def test_matrix_projection_exposes_variables():
    proj = MatrixProjection(Position(0, 0), Matrix())

    assert isinstance(proj.x, Variable)
    assert isinstance(proj.y, Variable)
def test_position_can_compare_with_tuple():
    pos = Position(3, 3)

    assert pos < (4, 4)
def test_position(position):
    pos = Position(*position)
    assert position[0] == pos.x
    assert position[1] == pos.y
Example #11
0
def pos2():
    return Position(3, 4)
Example #12
0
def pos1():
    return Position(1, 2)