コード例 #1
0
ファイル: test_point.py プロジェクト: jasontangxf/geometer
    def test_project(self):
        p1 = Point(1, 1, 0)
        p2 = Point(2, 1, 0)
        l = Line(p1, p2)
        assert l.project(Point(0, 0, 0)) == Point(0, 1, 0)

        e = Plane(0, 0, 1, 0)
        assert e.project(Point(1, 1, 5)) == p1
コード例 #2
0
ファイル: test_point.py プロジェクト: jasontangxf/geometer
 def test_parallel(self):
     p = Point(0, 0, 1)
     q = Point(1, 0, 1)
     r = Point(0, 1, 1)
     e = Plane(p, q, r)
     f = e.parallel(through=Point(0, 0, 0))
     assert f == Plane(0, 0, 1, 0)
     assert e.is_parallel(f)
コード例 #3
0
    def test_foci(self):
        e = Ellipse(Point(0, 0), 3, 2)
        f = e.foci
        f1 = Point(np.sqrt(5), 0)
        f2 = Point(np.sqrt(5), 0)

        assert len(f) == 2
        assert f1 in f and f2 in f
コード例 #4
0
    def test_tangent(self):
        q = Quadric([[1, 0, 0, 0],
                     [0, 1, 0, 0],
                     [0, 0, 1, 0],
                     [0, 0, 0, -1]])

        assert q.contains(Point(1, 0, 0))
        assert q.tangent(at=Point(1, 0, 0)) == Plane(Point(1, 0, 0), Point(1, 0, 1), Point(1, 1, 0))
コード例 #5
0
    def test_transformation(self):
        p = Point(0, 0)
        q = Point(2, 2)
        s = Segment(p, q)

        r = rotation(np.pi/2)
        assert r*s == Segment(p, Point(-2, 2))
        assert r.apply(s)._line == r.apply(s._line)
コード例 #6
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
コード例 #7
0
    def test_centroid(self):
        a = Point(0, 0, 1)
        b = Point(2, 0, 1)
        c = Point(2, 2, 1)
        d = Point(0, 2, 1)
        r = Rectangle(a, b, c, d)

        assert r.centroid == Point(1, 1, 1)
コード例 #8
0
ファイル: test_point.py プロジェクト: frenchmatthew/geometer
    def test_parallel(self):
        p = Point(0, 1)
        q = Point(1, 1)
        r = Point(0, 0)
        l = Line(p, q)
        m = l.parallel(through=r)

        assert m == Line(0, 1, 0)
        assert l.is_parallel(m)
コード例 #9
0
    def test_intersect(self):
        a = Point(0, 0)
        b = Point(0, 2)
        c = Point(2, 2)
        d = Point(2, 0)
        s1 = Segment(a, c)
        s2 = Segment(b, d)

        assert s1.intersect(s2) == [Point(1, 1)]
コード例 #10
0
    def test_transform(self):
        p = RegularPolygon(Point(0, 0, 0), 1, 6, axis=Point(0, 0, 1))
        t = translation(1, 1, 0)

        assert t * p == RegularPolygon(Point(1, 1, 0),
                                       1,
                                       6,
                                       axis=Point(0, 0, 1))
        assert isinstance(t * p, RegularPolygon)
コード例 #11
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
コード例 #12
0
    def test_intersections(self):
        c = Circle(Point(0, 0), 1)
        i = c.intersect(Line(0, 1, 0))
        assert len(i) == 2
        assert Point(1, 0) in i
        assert Point(-1, 0) in i

        c2 = Circle(Point(0, 2), 1)
        assert Point(0, 1) in c.intersect(c2)
コード例 #13
0
ファイル: test_shapes.py プロジェクト: jan-mue/geometer
    def test_equal(self):
        p = Point(0, 0)
        q = Point(2, 1)
        s = Segment(p, q)

        assert s == Segment(q, p)
        assert s == s
        assert s == Segment([(0, 0), (2, 1)], homogenize=True)
        assert s != Segment([(0, 0), (1, 2)], homogenize=True)
コード例 #14
0
ファイル: test_shapes.py プロジェクト: jan-mue/geometer
    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)
コード例 #15
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)
        s = Simplex(a, b, c, d)
        x = Point(1, 1, 1)
        t = translation(x)

        assert t * s == Simplex(a + x, b + x, c + x, d + x)
コード例 #16
0
ファイル: test_point.py プロジェクト: frenchmatthew/geometer
    def test_contains(self):
        p1 = Point(1, 1, 0)
        p2 = Point(2, 1, 0)
        p3 = Point(3, 4, 0)
        p4 = Point(0, 2, 0)

        p = Plane(p1, p2, p3)
        l = Line(p1, p2)
        assert p.contains(p4)
        assert p.contains(l)
コード例 #17
0
ファイル: test_shapes.py プロジェクト: frenchmatthew/geometer
    def test_intersect(self):
        a = PointCollection([(0, 0), (0, 0)], homogenize=True)
        b = PointCollection([(2, 0), (4, 0)], homogenize=True)
        c = PointCollection([(2, 2), (4, 4)], homogenize=True)
        d = PointCollection([(0, 2), (0, 4)], homogenize=True)
        s1 = SegmentCollection(a, c)
        s2 = SegmentCollection(b, d)

        assert s1.intersect(s2) == PointCollection([(1, 1), (2, 2)], homogenize=True)
        assert s1.intersect(Line(Point(0, 0), Point(1, 1))).size == 0
コード例 #18
0
    def test_init(self):
        a = Point(0, 0, 0)
        p = RegularPolygon(a, 1, 6, axis=Point(0, 0, 1))

        d = p.edges[0].length

        assert len(p.vertices) == 6
        assert np.isclose(dist(a, p.vertices[0]), 1)
        assert all(np.isclose(s.length, d) for s in p.edges[1:])
        assert np.allclose(p.angles, np.pi / 3)
        assert p.center == a
コード例 #19
0
ファイル: test_shapes.py プロジェクト: jan-mue/geometer
    def test_getitem(self):
        a = Point(0, 0, 1)
        b = Point(2, 0, 1)
        c = Point(2, 2, 1)
        d = Point(0, 2, 1)
        r = Rectangle(a, b, c, d)

        assert r[0] == a
        assert r[1] == b
        assert r[2] == c
        assert r[3] == d
コード例 #20
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)
コード例 #21
0
    def test_volume(self):
        a = Point(0, 0, 0)
        b = Point(1, 0, 0)
        c = Point(0, 1, 0)
        d = Point(0, 0, 1)
        s = Simplex(a, b, c, d)

        assert np.isclose(s.volume, 1 / 6)

        triangle = Simplex(a, b, c)
        assert np.isclose(triangle.volume, 1 / 2)
コード例 #22
0
 def test_edges(self):
     a = Point(0, 0)
     b = Point(0, 2)
     c = Point(2, 2)
     d = Point(2, 0)
     r = Rectangle(a, b, c, d)
     assert r.edges == [
         Segment(a, b),
         Segment(b, c),
         Segment(c, d),
         Segment(d, a)
     ]
コード例 #23
0
ファイル: test_curve.py プロジェクト: frenchmatthew/geometer
    def test_from_crossratio(self):
        a = Point(0, 1)
        b = Point(0, -1)
        c = Point(1.5, 0.5)
        d = Point(1.5, -0.5)
        e = Point(-1.5, 0.5)

        conic1 = Conic.from_points(a, b, c, d, e)
        cr = crossratio(a, b, c, d, e)
        conic2 = Conic.from_crossratio(cr, a, b, c, d)

        assert conic1 == conic2
コード例 #24
0
ファイル: test_shapes.py プロジェクト: jan-mue/geometer
    def test_centroid(self):
        a = Point(0, 0, 1)
        b = Point(2, 0, 1)
        c = Point(2, 2, 1)
        t = Triangle(a, b, c)

        s1, s2, s3 = t.edges
        l1 = s1.midpoint.join(c)
        l2 = s2.midpoint.join(a)

        assert t.centroid == (a + b + c) / 3
        assert t.centroid == l1.meet(l2)
コード例 #25
0
    def test_perpendicular(self):
        p = Point(1, 1, 0)
        q = Point(0, 0, 1)
        l = Line(p, q)
        m = l.perpendicular(p)

        assert is_perpendicular(l, m)

        r = Point(1, 2, 3)
        e = Plane(p, q, r)
        m = e.perpendicular(p)

        assert is_perpendicular(l, m)
コード例 #26
0
def test_is_collinear():
    p1 = Point(1, 0)
    p2 = Point(2, 0)
    p3 = Point(3, 0)
    l = Line(p1, p2)
    assert l.contains(p3)
    assert is_collinear(p1, p2, p3)

    p1 = PointCollection([(1, 0), (1, 1)], homogenize=True)
    p2 = PointCollection([(2, 0), (2, 1)], homogenize=True)
    p3 = PointCollection([(3, 0), (3, 1)], homogenize=True)
    p4 = PointCollection([(4, 0), (4, 1)], homogenize=True)

    assert all(is_collinear(p1, p2, p3, p4))
コード例 #27
0
ファイル: test_point.py プロジェクト: frenchmatthew/geometer
    def test_join(self):
        p1 = Point(1, 1, 4, 0)
        p2 = Point(2, 1, 5, 0)
        p3 = Point(3, 4, 6, 0)
        p4 = Point(0, 2, 7, 0)
        p5 = Point(1, 5, 8, 0)

        # 4 points
        assert join(p1, p2, p3, p4).contains(p5)

        # 3 points
        assert join(p1, p2, p3).contains(p3)

        # two lines
        l = Line(p1, p2)
        m = Line(p3, p4)
        assert join(l, m) == Plane(p1, p2, p3, p4)

        # coplanar lines
        l = Line(p1, p2)
        m = Line(p1, p3)
        assert join(l, m).contains(p3)

        # point and line
        p = join(l, p3)
        assert p == join(p1, p2, p3)

        # 2 points
        l = p1.join(p2)
        assert l.contains(Point(3, 1, 6, 0))
コード例 #28
0
ファイル: test_curve.py プロジェクト: frenchmatthew/geometer
    def test_from_points(self):
        a = Point(0, 1)
        b = Point(0, -1)
        c = Point(1.5, 0.5)
        d = Point(1.5, -0.5)
        e = Point(-1.5, 0.5)

        conic = Conic.from_points(a, b, c, d, e)

        assert conic.contains(a)
        assert conic.contains(b)
        assert conic.contains(c)
        assert conic.contains(d)
        assert conic.contains(e)
コード例 #29
0
ファイル: test_curve.py プロジェクト: frenchmatthew/geometer
    def test_from_tangent(self):
        a = Point(-1.5, 0.5)
        b = Point(0, -1)
        c = Point(1.5, 0.5)
        d = Point(1.5, -0.5)
        l = Line(0, 1, -1)

        conic = Conic.from_tangent(l, a, b, c, d)

        assert conic.contains(a)
        assert conic.contains(b)
        assert conic.contains(c)
        assert conic.contains(d)
        assert conic.is_tangent(l)
コード例 #30
0
    def test_from_points(self):
        a = Point(-1, 0)
        b = Point(0, 3)
        c = Point(1, 2)
        d = Point(2, 1)
        e = Point(0, -1)

        conic = Conic.from_points(a, b, c, d, e)

        assert conic.contains(a)
        assert conic.contains(b)
        assert conic.contains(c)
        assert conic.contains(d)
        assert conic.contains(e)