Exemple #1
0
def test_segment_copy():
    s1 = Segment([Vector(0, 0), Vector(0, 10)])

    s2 = s1.clone()

    assert s1 == s2
    assert s1 is not s2
Exemple #2
0
def test_new_segment():
    vertices = [Vector(0, 0), Vector(0, 10)]
    segment = Segment(vertices=vertices)

    assert segment is not None
    assert segment.line.origin == Vector(0, 0)
    assert segment.line.direction == Vector(0, 1)
    assert segment.line.normal == Vector(1, 0)
Exemple #3
0
def test_repr():
    vertices = [Vector(0.0, 0.0), Vector(0.0, 10.0)]
    segment = Segment(vertices=vertices)

    assert repr(
        segment
    ) == "<Segment (Vector(0.0, 0.0, 0.0), Vector(0.0, 10.0, 0.0))>", repr(
        segment)
Exemple #4
0
def test_some_node_stuff_2():
    n = Node()
    segments = [
        Segment([Vector(-15.0, -30.0), Vector(-30, -30)]),
        Segment([Vector(-10, -30), Vector(-15.0, -30.0)]),
        Segment([Vector(-10.0, -15.0), Vector(-10, -30)]),
        Segment([Vector(-30, -10), Vector(-15.0, -10.0)]),
        Segment([Vector(-30, -30), Vector(-30, -10)])
    ]

    n.build(segments.copy())
Exemple #5
0
def test_some_node_stuff():
    n = Node()
    segments = [
        Segment([Vector(-15, -30), Vector(-30, -30)]),
        Segment([Vector(-10, -30), Vector(-15, -30)]),
        Segment([Vector(-10, -15), Vector(-10, -30)]),
        Segment([Vector(-30, -10), Vector(-15, -10)]),
        Segment([Vector(-30, -30), Vector(-30, -10)])
    ]

    n.build(segments)
Exemple #6
0
def test_segment_flip():
    segment = Segment([Vector(0, 0), Vector(0, 10)])

    assert segment.line.origin == Vector(0, 0)
    assert segment.line.direction == Vector(0, 1)
    assert segment.line.normal == Vector(1, 0)

    segment.flip()

    assert segment.vertices[1] == (Vector(0, 0))
    assert segment.vertices[0] == (Vector(0, 10))
    assert segment.line.origin == Vector(0, 0).negated()
    assert segment.line.direction == Vector(0, 1).negated()
    assert segment.line.normal == Vector(1, 0).negated()
Exemple #7
0
def test_init_node_2():
    segments = [
        Segment([Vector(0, 0), Vector(0, 10)]),
        Segment([Vector(0, 10), Vector(10, 10)]),
        Segment([Vector(10, 10), Vector(0, 0)])
    ]
    n = Node()
    n.build(segments)
    assert n is not None

    assert len(n.segments) == 1
    assert n.line == Segment([Vector(0, 0), Vector(0, 10)]).line
    assert not n.right
    assert n.left
Exemple #8
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
Exemple #9
0
def test_node_clone():
    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)

    m = n.clone()

    assert m == n
    assert m is not n
Exemple #10
0
def test_circle_union():
    stepcount = 30

    def pol2cart(angle: float, radius: float = 1.0) -> Vector:
        x = radius * math.cos(angle)
        y = radius * math.sin(angle)

        return Vector(x, y)

    def delta(i: float, steps: int = 36) -> float:
        return (math.pi * 2 / steps) * i

    def csg_circle(position: Vector = Vector(0, 0), size: float = 100) -> CSG:
        polygons = [pol2cart(delta(i, stepcount), size) + position
                    for i in range(stepcount)]
        return CSG.from_polygons([polygons])

    circles = [
        (Vector(0.0, 0.0, 0.0), 30, False),
        (Vector(13, 20, 0.0), 17, False),
        (Vector(2, 33, 0.0), 4, False),
        (Vector(0, 33, 0.0), 3, False)
    ]

    circles = [
        (Vector(0.0, 0.0, 0.0), 30, False),
        (Vector(9.159937903903145, -28.501722699929672, 0.0),
         1.9358049315341745, False),
        (Vector(9.000231775034093, -27.141412518165417, 0.0),
         1.3679879000715582, False),
    ]

    output = csg_circle(circles[0][0], circles[0][1])

    assert len(output.to_polygons()) == 1
    point_count = len(output.to_polygons()[0])

    for c in circles[1:]:
        next = csg_circle(c[0], c[1])
        output = output.union(next)
        polygons = output.to_polygons()
        assert len(polygons) == 1

        new_point_count = len(polygons[0])
        assert new_point_count > point_count, c

        point_count = new_point_count
Exemple #11
0
 def csg_circle(position: Vector = Vector(0, 0), size: float = 100) -> CSG:
     polygons = [pol2cart(delta(i, stepcount), size) + position
                 for i in range(stepcount)]
     return CSG.from_polygons([polygons])
Exemple #12
0
    def pol2cart(angle: float, radius: float = 1.0) -> Vector:
        x = radius * math.cos(angle)
        y = radius * math.sin(angle)

        return Vector(x, y)