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
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)
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
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))
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)
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
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)
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)
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)]
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)
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
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)
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)
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)
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)
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)
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
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
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
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)
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)
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) ]
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
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)
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)
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))
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))
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)
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)
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)