def test_reflect(): b = Symbol('b') m = Symbol('m') l = Line((0, b), slope=m) p = Point(x, y) r = p.reflect(l) dp = l.perpendicular_segment(p).length dr = l.perpendicular_segment(r).length assert verify_numerically(dp, dr) t = Triangle((0, 0), (1, 0), (2, 3)) assert t.area == -t.reflect(l).area e = Ellipse((1, 0), 1, 2) assert e.area == -e.reflect(Line((1, 0), slope=0)).area assert e.area == -e.reflect(Line((1, 0), slope=oo)).area pytest.raises(NotImplementedError, lambda: e.reflect(Line( (1, 0), slope=m))) assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=oo)) \ == Triangle(Point(5, 0), Point(4, 0), Point(4, 2)) assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=oo)) \ == Triangle(Point(-1, 0), Point(-2, 0), Point(-2, 2)) assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((0, 3), slope=0)) \ == Triangle(Point(1, 6), Point(2, 6), Point(2, 4)) assert Polygon((1, 0), (2, 0), (2, 2)).reflect(Line((3, 0), slope=0)) \ == Triangle(Point(1, 0), Point(2, 0), Point(2, -2)) # test entity overrides c = Circle((x, y), 3) cr = c.reflect(l) assert cr == Circle(r, -3) assert c.area == -cr.area pent = RegularPolygon((1, 2), 1, 5) l = Line((0, pi), slope=sqrt(2)) rpent = pent.reflect(l) assert rpent.center == pent.center.reflect(l) assert [w.evalf(3) for w in rpent.vertices] == \ [Point2D(Float('-0.585815', dps=3), Float('4.27051', dps=3)), Point2D(Float('-1.69409', dps=3), Float('4.66211', dps=3)), Point2D(Float('-2.40918', dps=3), Float('3.72949', dps=3)), Point2D(Float('-1.74292', dps=3), Float('2.76123', dps=3)), Point2D(Float('-0.615967', dps=3), Float('3.0957', dps=3))] assert pent.area.equals(-rpent.area)
def test_Point2D(): p1 = Point2D(1, 5) p2 = Point2D(4, 2.5) p3 = Point2D(6.1, 3.5) assert p1.distance(p2) == sqrt(61)/2 assert p2.distance(p3) == sqrt(541)/10 assert p1.bounds == (1, 5, 1, 5) assert Point2D.is_concyclic() is False pytest.raises(ValueError, lambda: Point2D(1, 1, 1)) pytest.raises(ValueError, lambda: Point2D(1, I))
def test_Point2D(): p1 = Point2D(1, 5) p2 = Point2D(4, 2.5) p3 = Point2D(6.1, 3.5) assert p1.distance(p2) == sqrt(61) / 2 assert p2.distance(p3) == sqrt(541) / 10