Exemple #1
0
def test_eq():
    a = Transform2D((1, 2, 3, 4, 5, 6))
    b = Transform2D((1, 2, 3, 4, 5, 6))
    assert a == b
    c = (1, 2, 3, 4, 5, 6)
    assert a == c
    assert b == c
Exemple #2
0
    def recursive_point_collector(cls, node):
        # points from children
        # add points from local
        # multiply by local transform
        # return all points.
        child_points = []
        for child in node.getchildren():
            if child.tag in ['g', 'polygon']:
                child_points.extend(cls.recursive_point_collector(child))
        if node.get('points'):
            local_points = [
                tuple(map(float, p.split(',')))
                for p in node.get('points').split(' ')
            ]
        else:
            local_points = []

        points = child_points + local_points

        if node.get('transform'):
            local_transform = Transform2D(
                tuple(
                    map(float,
                        node.get('transform').strip("matrix()").split(","))))
        else:
            local_transform = Transform2D.identity()

        points = [local_transform.multiply_point(p) for p in points]
        return points
Exemple #3
0
def test___mul__():
    i = Transform2D.identity()
    a = Transform2D((1, 2, 3, 4, 5, 6))
    b = Transform2D((9, 8, 7, 6, 5, 4))
    c = Transform2D((33, 50, 25, 38, 22, 32))
    assert i * a == a
    assert a * i == a
    assert a * b == c
Exemple #4
0
    def calc_xform(parent_xform: Transform2D, edge: Edge) -> Transform2D:
        rel_x = tuple(map(operator.sub, edge.start, edge.end))
        rel_y = (-rel_x[1], rel_x[0])
        rel_p = edge.center
        rel_xform = Transform2D((*rel_x, *rel_y, *rel_p))

        xform = (parent_xform * rel_xform).normalize()
        return xform
Exemple #5
0
def get_sample_models():
    # room:
    #    edges = []  # type: List[Edge]
    #    base_edge = 0  # type: int
    #    square_inches = 0.  # type: float
    #    ratio = 0.  # type: float
    #    name = ""  # type: str
    #    id = ""  # type: str
    #    template = 'base'  # type: str
    #    transform = Transform2D.identity()  # type: Transform2D
    wall = constraints.Wall()
    passage = constraints.StraightPassage()
    dead_end = constraints.DeadEnd()

    entrance = rooms.BaseRoom()
    entrance.apply_constraint(wall)
    entrance.apply_constraint(dead_end)
    entrance.set_box(43, 43); entrance.set_square_inches(1849); entrance.set_ratio(1.0)
    entrance.name = 'Entrance'; entrance.id = 'entrance'

    hallway_door = rooms.BaseRoom()
    hallway_door.apply_constraint(wall)
    hallway_door.apply_constraint(passage)
    hallway_door.set_box(43, 5); hallway_door.set_square_inches(215); hallway_door.set_ratio(8.6)
    hallway_door.name = 'Main Hallway Door'; hallway_door.id = 'main_hallway_door'
    hallway_door.transform = Transform2D((1, 0, 0, 1, 0, 43))

    hallway = rooms.BaseRoom()
    hallway.set_box(43, 133); hallway.set_square_inches(5719); hallway.set_ratio(0.3233)
    hallway.name = 'Main Hallway'; hallway.id = 'main_hallway'
    hallway.transform = Transform2D((1, 0, 0, 1, 0, 48))

    closet_door = rooms.BaseRoom()
    closet_door.apply_constraint(wall)
    closet_door.apply_constraint(passage)
    closet_door.set_box(43, 5); closet_door.set_square_inches(215); closet_door.set_ratio(8.6)
    closet_door.name = 'Closet Door'; closet_door.id = 'closet_door'
    closet_door.transform = Transform2D((0, -1, 1, 0, 21.5, 114.5))

    closet = rooms.BaseRoom()
    closet.set_box(47, 25); closet.set_square_inches(1175); closet.set_ratio(1.88)
    closet.name = 'Closet'; closet.id = 'closet'
    closet.transform = Transform2D((0, -1, 1, 0, 26.5, 114.5))

    bathroom_door = rooms.BaseRoom()
    bathroom_door.apply_constraint(wall)
    bathroom_door.apply_constraint(passage)
    bathroom_door.set_box(47, 5); bathroom_door.set_square_inches(1175); bathroom_door.set_ratio(8.6)
    bathroom_door.name = 'Bathroom Door'; bathroom_door.id = 'bathroom_door'
    bathroom_door.transform = Transform2D((1, 0, 0, 1, 0, 181))

    bathroom = rooms.BaseRoom()
    bathroom.set_box(137, 98); bathroom.set_square_inches(13426); bathroom.set_ratio(1.398)
    bathroom.name = 'Bathroom'; bathroom.id = 'bathroom'
    bathroom.transform = Transform2D((1, 0, 0, 1, 0, 186))

    models = [entrance, hallway_door, hallway, closet_door, closet, bathroom_door, bathroom]
    return models
Exemple #6
0
def test_multiple_point():
    p = (5, -2)
    movement = Transform2D((1, 0, 0, 1, 10, 100))
    assert movement.multiply_point(p) == (15, 98)
    rotation0 = Transform2D((1, 0, 0, 1, 0, 0))
    assert rotation0.multiply_point(p) == (5, -2)
    rotation1 = Transform2D((0, -1, 1, 0, 0, 0))
    assert rotation1.multiply_point(p) == (-2, -5)
    rotation2 = Transform2D((-1, 0, 0, -1, 0, 0))
    assert rotation2.multiply_point(p) == (-5, 2)
    rotation3 = Transform2D((0, 1, -1, 0, 0, 0))
    assert rotation3.multiply_point(p) == (2, 5)
    everything = Transform2D((1, 2, 3, 4, 5, 6))
    assert everything.multiply_point(p) == (4, 8)
Exemple #7
0
def test_make_rooms(monkeypatch):
    metaroom3 = MetaRoom('hallway', 'Side Hallway')
    metaroom4 = MetaWall('doorway', 'Kitchen Door')

    room3 = Hallway()
    room3.name = 'Side Hallway'
    room3.set_box(43, 263)
    room3.transform = Transform2D((1, 0, 0, 1, 0, 48))

    graph3 = Graph(contents=metaroom3, model=room3)
    graph4 = Graph(contents=metaroom4, parent=graph3)
    graph3.children.append(graph4)

    def mock_attachment():
        return [graph3.model.edges[0]]

    monkeypatch.setattr(graph3.model, 'get_attachment_points', mock_attachment)
    Modeler.make_rooms(graph4)
    assert graph4.model.transform == (-1, 0, 0, -1, 0, 48)

    def mock_attachment():
        return [graph3.model.edges[1]]

    monkeypatch.setattr(graph3.model, 'get_attachment_points', mock_attachment)
    Modeler.make_rooms(graph4)
    assert graph4.model.transform == (0, -1, 1, 0, 21.5, 179.5)

    def mock_attachment():
        return [graph3.model.edges[2]]

    monkeypatch.setattr(graph3.model, 'get_attachment_points', mock_attachment)
    Modeler.make_rooms(graph4)
    assert graph4.model.transform == (1, 0, 0, 1, 0, 311)

    def mock_attachment():
        return [graph3.model.edges[3]]

    monkeypatch.setattr(graph3.model, 'get_attachment_points', mock_attachment)
    Modeler.make_rooms(graph4)
    assert graph4.model.transform == (0, 1, -1, 0, -21.5, 179.5)
Exemple #8
0
def test_normalize_identity():
    i1 = Transform2D.identity()
    assert i1.normalize() == i1
Exemple #9
0
def test_normalize():
    a = Transform2D((10, 0, 0, 5, 123, 456))
    assert a.normalize() == (1, 0, 0, 1, 123, 456)