Example #1
0
 def test_intersect(self):
     a = Point(0, 0, 0)
     b = Point(1, 0, 0)
     c = Point(0, 1, 0)
     d = Point(0, 0, 1)
     cube = Cuboid(a, b, c, d)
     l = Line(Point(2, 0.5, 0.5), Point(-1, 0.5, 0.5))
     assert cube.intersect(l) == [Point(0, 0.5, 0.5), Point(1, 0.5, 0.5)]
Example #2
0
    def test_add(self):
        a = Point(0, 0, 0)
        b = Point(1, 0, 0)
        c = Point(0, 1, 0)
        d = Point(0, 0, 1)
        cube = Cuboid(a, b, c, d)
        p = Point(1, 2, 3)

        assert cube + p == Cuboid(a + p, b + p, c + p, d + p)
        assert cube - p == Cuboid(a - p, b - p, c - p, d - p)
Example #3
0
    def test_transform(self):
        a = Point(0, 0, 0)
        b = Point(1, 0, 0)
        c = Point(0, 1, 0)
        d = Point(0, 0, 1)
        cube = Cuboid(a, b, c, d)
        x = Point(1, 1, 1)
        t = translation(x)

        assert t * cube == Cuboid(a + x, b + x, c + x, d + x)
        assert isinstance(t * cube, Cuboid)
Example #4
0
    def test_edges(self):
        a = Point(0, 0, 0)
        b = Point(1, 0, 0)
        c = Point(0, 1, 0)
        d = Point(0, 0, 1)
        cube = Cuboid(a, b, c, d)

        assert len(cube.edges) == 12
Example #5
0
 def test_area(self):
     a = Point(0, 0, 0)
     b = Point(1, 0, 0)
     c = Point(0, 1, 0)
     d = Point(0, 0, 1)
     cube = Cuboid(a, b, c, d)
     assert len(cube.faces) == 6
     assert len(cube.vertices) == 8
     assert cube.area == 6
Example #6
0
    def test_getitem(self):
        a = Point(0, 0, 0)
        b = Point(1, 0, 0)
        c = Point(0, 1, 0)
        d = Point(0, 0, 1)
        cube = Cuboid(a, b, c, d)

        x, y, z = b - a, c - a, d - a
        yz = Rectangle(a, a + z, a + y + z, a + y)
        xz = Rectangle(a, a + x, a + x + z, a + z)
        xy = Rectangle(a, a + x, a + x + y, a + y)

        assert isinstance(cube[0], Polygon)
        assert cube[0] == yz
        assert cube[1] == xz
        assert cube[2] == xy
        assert cube[0, 0] == a
Example #7
0
def test_dist():
    p = Point(0, 0)
    q = Point(1, 0)
    assert np.isclose(dist(p, q), 1)

    p = Point(1000000, 0)
    q = Point(1000001, 0)
    assert np.isclose(dist(p, q), 1)

    p1 = Point(1j, 0, 0, 2j)
    p2 = Point(0, 2j, 0, 0)
    assert np.isclose(dist(p1, p2), 3)

    p1 = Point(1, 0, 0)
    p2 = Point([1, 0, 0, 0])
    assert dist(p1, p2) == dist(p2, p1) == np.inf

    p1 = Point(0, 0, 0)
    p2 = Point(1, 0, 0)
    assert np.isclose(dist(p1, p2), 1)

    e = Plane(1, 0, 0, 0)
    assert np.isclose(dist(e, p2), 1)

    p = Point(1, 2, 0)
    l = Line(Point(0, 0, 0), Point(3, 0, 0))
    assert np.isclose(dist(p, l), 2)

    l = Line(p2, Point(1, 1, 0))
    assert np.isclose(dist(l, e), 1)
    assert np.isclose(dist(l, p1), 1)

    p = Point(0, 0)
    poly = Rectangle(Point(-1, 1), Point(1, 1), Point(1, 2), Point(-1, 2))
    assert np.isclose(dist(p, poly), 1)

    p = Point(0, 0, 0)
    poly = Rectangle(Point(-1, -1, 1), Point(1, -1, 1), Point(1, 1, 1),
                     Point(-1, 1, 1))
    assert np.isclose(dist(p, poly), 1)
    assert np.isclose(dist(Point(-1, -1, 0), poly), 1)
    assert np.isclose(dist(Point(-4, 0, -3), poly), 5)

    a = Point(0, 0, 0)
    b = Point(1, 0, 0)
    c = Point(0, 1, 0)
    d = Point(0, 0, 1)
    cube = Cuboid(a, b, c, d)
    # TODO: speed this up
    assert np.isclose(dist(p, cube), 0)
    assert np.isclose(dist(Point(-1, 0, 0), cube), 1)
    assert np.isclose(dist(Point(0.5, 0.5, 2), cube), 1)

    p = PointCollection([(1, 0, 1), (1, 1, 0)], homogenize=True)
    e = PlaneCollection([(0, 0, 1, 0), (1, 0, 0, 0)])
    s = Segment(Point(1, 0, 1), Point(1, 2, 1))
    # TODO: speed this up
    assert np.allclose(dist(e, p), 1)
    assert np.allclose(dist(p, cube), 0)
    assert np.allclose(dist(p, poly), [0, 1])
    assert np.allclose(dist(p, s), [0, 1])