Example #1
0
 def constraint(self, item: Item, handle: Handle,
                glue_item: Item) -> MultiConstraint:
     """Return connection position constraint between item's handle and the
     port."""
     origin = MatrixProjection(self.point, glue_item.matrix_i2c)
     point = MatrixProjection(handle.pos, item.matrix_i2c)
     c = PositionConstraint(origin.pos, point.pos)
     return MultiConstraint(origin, point, c)
Example #2
0
 def constraint(self, item: Item, handle: Handle,
                glue_item: Item) -> Constraint:
     """Create connection line constraint between item's handle and the
     port."""
     start = MatrixProjection(self.start, glue_item.matrix_i2c)
     end = MatrixProjection(self.end, glue_item.matrix_i2c)
     point = MatrixProjection(handle.pos, item.matrix_i2c)
     line = LineConstraint((start.pos, end.pos), point.pos)
     return MultiConstraint(start, end, point, line)
def test_original_updates_when_projection_is_changed(solver, position, matrix,
                                                     result):
    pos = Position(0, 0)
    proj = MatrixProjection(pos, matrix)
    solver.add_constraint(proj)
    solver.solve()

    proj.x, proj.y = position

    solver.solve()

    assert pos.x == result[0]
    assert pos.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 #5
0
    def constraint(self, item, handle, glue_item):
        """Create connection line constraint between item's handle and the
        port."""
        start = MatrixProjection(self.start, glue_item.matrix_i2c)
        end = MatrixProjection(self.end, glue_item.matrix_i2c)
        point = MatrixProjection(handle.pos, item.matrix_i2c)

        x, y = item.matrix_i2c.transform_point(*handle.pos)
        x, y = glue_item.matrix_i2c.inverse().transform_point(x, y)

        # keep message at the same distance from head or bottom of lifetime
        # line depending on situation
        height = self.end.y - self.start.y
        if y / height < 0.5:
            delta = y - self.start.y
            align = 0
        else:
            delta = y - self.end.y
            align = 1
        line = LineAlignConstraint((start, end), point, align, delta)
        return MultiConstraint(start, end, point, line)
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)