def test_intersection(self): c = Circle(Point(0, 2), 2) l = Line(Point(-1, 2), Point(1, 2)) assert c.contains(Point(0, 0)) assert c.intersect(l) == [Point(-2, 2), Point(2, 2)] assert c.intersect(l-Point(0, 2)) == [Point(0, 0)]
def test_intersect(self): q = QuadricCollection([Circle(Point(0, 1), 1), Circle(Point(0, 2), 2)]) l = LineCollection( [Line(Point(-1, 1), Point(1, 1)), Line(Point(-1, 2), Point(1, 2))]) assert q.intersect(l) == [ PointCollection([Point(1, 1), Point(-2, 2)]), PointCollection([Point(-1, 1), Point(2, 2)]), ] q = QuadricCollection( [Sphere(Point(0, 0, 1), 1), Sphere(Point(0, 0, 2), 2)]) l = LineCollection([ Line(Point(-1, 0, 1), Point(1, 0, 1)), Line(Point(-1, 0, 2), Point(1, 0, 2)), ]) m = Line(Point(-1, 0, 2), Point(1, 0, 2)) assert q.intersect(l) == [ PointCollection([Point(-1, 0, 1), Point(-2, 0, 2)]), PointCollection([Point(1, 0, 1), Point(2, 0, 2)]), ] assert q.intersect(m) == [ PointCollection([Point(0, 0, 2), Point(-2, 0, 2)]), PointCollection([Point(0, 0, 2), Point(2, 0, 2)]), ]
def test_copy(self): c1 = Circle(Point(0, 1), 4.5) c2 = c1.copy() assert c1 == c2 assert c1 is not c2 assert c1.center == c2.center assert c1.radius == c2.radius
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_from_points_and_conics(self): c1 = Circle() p1 = Point(0, -1) p2 = Point(0, 1) p3 = Point(1, 0) c2 = Circle(Point(0, 2), 2) q1 = Point(0, 0) q2 = Point(0, 4) q3 = Point(2, 2) t = Transformation.from_points_and_conics([p1, p2, p3], [q1, q2, q3], c1, c2) assert t * p1 == q1 assert t * p2 == q2 assert t * p2 == q2 assert t.apply(c1) == c2
def test_intersect(self): c = Circle(Point(0, 2), 2) l = Line(Point(-1, 2), Point(1, 2)) assert c.contains(Point(0, 0)) assert c.intersect(l) == [Point(-2, 2), Point(2, 2)] assert c.intersect(l - Point(0, 2)) == [Point(0, 0)] l = LineCollection( [Line(Point(-1, 2), Point(1, 2)), Line(Point(0, 2), Point(0, 0))]) assert c.intersect(l) == [ PointCollection([Point(-2, 2), Point(0, 0)]), PointCollection([Point(2, 2), Point(0, 4)]), ] c1 = Circle(Point(0, 0), 5) c2 = Circle(Point(8, 0), 5) intersections = c1.intersect(c2) assert Point(4, 3) in intersections assert Point(4, -3) in intersections
def test_intersect(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) c3 = Conic.from_lines(Line(1, 0, 0), Line(0, 1, 0)) assert Point(1, 0) in c.intersect(c3) assert Point(0, 1) in c.intersect(c3) assert Point(-1, 0) in c.intersect(c3) assert Point(0, -1) in c.intersect(c3)
def test_transform(self): c = Circle() t = translation(1, 1) assert t * c == Circle(Point(1, 1)) assert t.apply(c).center == Point(1, 1)
def test_intersection_angle(self): c1 = Circle() c2 = Circle(Point(1, 1), 1) assert np.isclose(c1.intersection_angle(c2), np.pi / 2)
def test_center(self): c = Circle(Point(0, 1), 1) assert c.center == Point(0, 1)
def test_contains(self): c = Circle(Point(0, 1), 1) assert c.contains(Point(0, 2)) assert c.contains(Point(1, 1))
def test_circle(self): c = Circle(Point(0, 1), 1) assert c.contains(Point(0, 2)) assert c.contains(Point(1, 1)) assert c.tangent(at=Point(0, 0)) == Line(0, 1, 0) assert c.center == Point(0, 1)
def test_intersect(self): c = Circle(Point(0, 2), 2) l = Line(Point(-1, 2), Point(1, 2)) assert c.contains(Point(0, 0)) assert c.intersect(l) == [Point(-2, 2), Point(2, 2)] assert c.intersect(l - Point(0, 2)) == [Point(0, 0)] l = LineCollection([Line(Point(-1, 2), Point(1, 2)), Line(Point(0, 2), Point(0, 0))]) assert c.intersect(l) == [PointCollection([Point(-2, 2), Point(0, 0)]), PointCollection([Point(2, 2), Point(0, 4)])] c1 = Circle(Point(0, 0), 5) c2 = Circle(Point(8, 0), 5) intersections = c1.intersect(c2) assert Point(4, 3) in intersections assert Point(4, -3) in intersections c1 = Circle(Point(0, 0)) c2 = Circle(Point(0.5, 0)) i = c1.intersect(c2) assert len(i) == 4 assert len([p for p in i if p.isreal]) == 2