Exemplo n.º 1
0
def test_node_invert():
    segments = [
        Segment([Vector(0, 0), Vector(0, 10)]),
        Segment([Vector(0, 10), Vector(10, 10)]),
        Segment([Vector(10, 10), Vector(0, 0)])
    ]
    n = Node(segments)
    n.invert()

    assert n is not None

    assert len(n.segments) == 1
    assert n.line == Segment([Vector(0, 0), Vector(0, -10)]).line
    assert n.right
    assert not n.left
Exemplo n.º 2
0
def test_manual_union():
    poly_a = CSG.from_polygons([[
        [0, 0],
        [15, 0],
        [15, 15],
        [0, 15]
        ]])

    poly_b = CSG.from_polygons([[
        [30, 30],
        [10, 30],
        [10, 10],
        [30, 10]
        ]])

    a = Node(poly_a.clone().segments)
    assert len(a.all_segments()) == 4

    b = Node(poly_b.clone().segments)
    assert len(a.all_segments()) == 4

    a.invert()
    assert len(a.all_segments()) == 4
    b.clip_to(a)
    assert len(b.all_segments()) == 5
    b.invert()
    assert len(b.all_segments()) == 5
    a.clip_to(b)
    a_all_segments = a.all_segments()
    assert len(a.all_segments()) == 5
    b.clip_to(a)
    b_all_segments = b.all_segments()
    assert len(b.all_segments()) == 5

    segs = b.all_segments()
    assert len(segs) == 5

    a.build(segs)
    a_all_segments = a.all_segments()
    assert len(a.all_segments()) == 10

    a.invert()
    a_all_segments = a.all_segments()
    assert len(a.all_segments()) == 10