#NEWLINE# def test_polygon( ) : #NEWLINE# #INDENT# x = Symbol ( 'x' , real = True ) #NEWLINE# y = Symbol ( 'y' , real = True ) #NEWLINE# x1 = Symbol ( 'x1' , real = True ) #NEWLINE# half = Rational ( 1 , 2 ) #NEWLINE# ( a , b , c ) = ( Point ( 0 , 0 ) , Point ( 2 , 0 ) , Point ( 3 , 3 ) ) #NEWLINE# t = Triangle ( a , b , c ) #NEWLINE# assert ( Polygon ( a , Point ( 1 , 0 ) , b , c ) == t ) #NEWLINE# assert ( Polygon ( Point ( 1 , 0 ) , b , c , a ) == t ) #NEWLINE# assert ( Polygon ( b , c , a , Point ( 1 , 0 ) ) == t ) #NEWLINE# assert ( Polygon ( a , Point ( 3 , 0 ) , b , c ) == t ) #NEWLINE# assert ( Polygon ( a , b , Point ( 3 , ( - 1 ) ) , b , c ) == t ) #NEWLINE# raises ( GeometryError , ( lambda : Polygon ( ( 0 , 0 ) , ( 1 , 0 ) , ( 0 , 1 ) , ( 1 , 1 ) ) ) ) #NEWLINE# assert ( Polygon ( Point ( ( - 4 ) , 15 ) , Point ( ( - 11 ) , 15 ) , Point ( ( - 15 ) , 15 ) , Point ( ( - 15 ) , ( 33 / 5 ) ) , Point ( ( - 15 ) , ( ( - 87 ) / 10 ) ) , Point ( ( - 15 ) , ( - 15 ) ) , Point ( ( ( - 42 ) / 5 ) , ( - 15 ) ) , Point ( ( - 2 ) , ( - 15 ) ) , Point ( 7 , ( - 15 ) ) , Point ( 15 , ( - 15 ) ) , Point ( 15 , ( - 3 ) ) , Point ( 15 , 10 ) , Point ( 15 , 15 ) ) == Polygon ( Point ( ( - 15 ) , ( - 15 ) ) , Point ( 15 , ( - 15 ) ) , Point ( 15 , 15 ) , Point ( ( - 15 ) , 15 ) ) ) #NEWLINE# p1 = Polygon ( Point ( 0 , 0 ) , Point ( 3 , ( - 1 ) ) , Point ( 6 , 0 ) , Point ( 4 , 5 ) , Point ( 2 , 3 ) , Point ( 0 , 3 ) ) #NEWLINE# p2 = Polygon ( Point ( 6 , 0 ) , Point ( 3 , ( - 1 ) ) , Point ( 0 , 0 ) , Point ( 0 , 3 ) , Point ( 2 , 3 ) , Point ( 4 , 5 ) ) #NEWLINE# p3 = Polygon ( Point ( 0 , 0 ) , Point ( 3 , 0 ) , Point ( 5 , 2 ) , Point ( 4 , 4 ) ) #NEWLINE# p4 = Polygon ( Point ( 0 , 0 ) , Point ( 4 , 4 ) , Point ( 5 , 2 ) , Point ( 3 , 0 ) ) #NEWLINE# p5 = Polygon ( Point ( 0 , 0 ) , Point ( 4 , 4 ) , Point ( 0 , 4 ) ) #NEWLINE# p6 = Polygon ( Point ( ( - 11 ) , 1 ) , Point ( ( - 9 ) , 6.6 ) , Point ( ( - 4 ) , ( - 3 ) ) , Point ( ( - 8.4 ) , ( - 8.7 ) ) ) #NEWLINE# r = Ray ( Point ( ( - 9 ) , 6.6 ) , Point ( ( - 9 ) , 5.5 ) ) #NEWLINE# assert ( p1 == p2 ) #NEWLINE# assert ( len ( p1 . args ) == 6 ) #NEWLINE# assert ( len ( p1 . sides ) == 6 ) #NEWLINE# assert ( p1 . perimeter == ( ( ( 5 + ( 2 * sqrt ( 10 ) ) ) + sqrt ( 29 ) ) + sqrt ( 8 ) ) ) #NEWLINE# assert ( p1 . area == 22 ) #NEWLINE# assert ( not p1 . is_convex ( ) ) #NEWLINE# assert p3 . is_convex ( ) #NEWLINE# assert p4 . is_convex ( ) #NEWLINE# dict5 = p5 . angles #NEWLINE# assert ( dict5 [ Point ( 0 , 0 ) ] == ( pi / 4 ) ) #NEWLINE# assert ( dict5 [ Point ( 0 , 4 ) ] == ( pi / 2 ) ) #NEWLINE# assert ( p5 . encloses_point ( Point ( x , y ) ) is None ) #NEWLINE# assert p5 . encloses_point ( Point ( 1 , 3 ) ) #NEWLINE# assert ( p5 . encloses_point ( Point ( 0 , 0 ) ) is False ) #NEWLINE# assert ( p5 . encloses_point ( Point ( 4 , 0 ) ) is False ) #NEWLINE# assert ( p1 . encloses ( Circle ( Point ( 2.5 , 2.5 ) , 5 ) ) is False ) #NEWLINE# assert ( p1 . encloses ( Ellipse ( Point ( 2.5 , 2 ) , 5 , 6 ) ) is False ) #NEWLINE# ( p5 . plot_interval ( 'x' ) == [ x , 0 , 1 ] ) #NEWLINE# assert ( p5 . distance ( Polygon ( Point ( 10 , 10 ) , Point ( 14 , 14 ) , Point ( 10 , 14 ) ) ) == ( 6 * sqrt ( 2 ) ) ) #NEWLINE# assert ( p5 . distance ( Polygon ( Point ( 1 , 8 ) , Point ( 5 , 8 ) , Point ( 8 , 12 ) , Point ( 1 , 12 ) ) ) == 4 ) #NEWLINE# warnings . filterwarnings ( 'error' , message = 'Polygons may intersect producing erroneous output' ) #NEWLINE# raises ( UserWarning , ( lambda : Polygon ( Point ( 0 , 0 ) , Point ( 1 , 0 ) , Point ( 1 , 1 ) ) . distance ( Polygon ( Point ( 0 , 0 ) , Point ( 0 , 1 ) , Point ( 1 , 1 ) ) ) ) ) #NEWLINE# warnings . filterwarnings ( 'ignore' , message = 'Polygons may intersect producing erroneous output' ) #NEWLINE# assert ( hash ( p5 ) == hash ( Polygon ( Point ( 0 , 0 ) , Point ( 4 , 4 ) , Point ( 0 , 4 ) ) ) ) #NEWLINE# assert ( p5 == Polygon ( Point ( 4 , 4 ) , Point ( 0 , 4 ) , Point ( 0 , 0 ) ) ) #NEWLINE# assert ( Polygon ( Point ( 4 , 4 ) , Point ( 0 , 4 ) , Point ( 0 , 0 ) ) in p5 ) #NEWLINE# assert ( p5 != Point ( 0 , 4 ) ) #NEWLINE# assert ( Point ( 0 , 1 ) in p5 ) #NEWLINE# assert ( p5 . arbitrary_point ( 't' ) . subs ( Symbol ( 't' , real = True ) , 0 ) == Point ( 0 , 0 ) ) #NEWLINE# raises ( ValueError , ( lambda : Polygon ( Point ( x , 0 ) , Point ( 0 , y ) , Point ( x , y ) ) . arbitrary_point ( 'x' ) ) ) #NEWLINE# assert ( p6 . intersection ( r ) == [ Point ( ( - 9 ) , ( 33 / 5 ) ) , Point ( ( - 9 ) , ( ( - 84 ) / 13 ) ) ] ) #NEWLINE# p1 = RegularPolygon ( Point ( 0 , 0 ) , 10 , 5 ) #NEWLINE# p2 = RegularPolygon ( Point ( 0 , 0 ) , 5 , 5 ) #NEWLINE# raises ( GeometryError , ( lambda : RegularPolygon ( Point ( 0 , 0 ) , Point ( 0 , 1 ) , Point ( 1 , 1 ) ) ) ) #NEWLINE# raises ( GeometryError , ( lambda : RegularPolygon ( Point ( 0 , 0 ) , 1 , 2 ) ) ) #NEWLINE# raises ( ValueError , ( lambda : RegularPolygon ( Point ( 0 , 0 ) , 1 , 2.5 ) ) ) #NEWLINE# assert ( p1 != p2 ) #NEWLINE# assert ( p1 . interior_angle == ( ( 3 * pi ) / 5 ) ) #NEWLINE# assert ( p1 . exterior_angle == ( ( 2 * pi ) / 5 ) ) #NEWLINE# assert ( p2 . apothem == ( 5 * cos ( ( pi / 5 ) ) ) ) #NEWLINE# assert ( p2 . circumcenter == p1 . circumcenter == Point ( 0 , 0 ) ) #NEWLINE# assert ( p1 . circumradius == p1 . radius == 10 ) #NEWLINE# assert ( p2 . circumcircle == Circle ( Point ( 0 , 0 ) , 5 ) ) #NEWLINE# assert ( p2 . incircle == Circle ( Point ( 0 , 0 ) , p2 . apothem ) ) #NEWLINE# assert ( p2 . inradius == p2 . apothem == ( ( 5 * ( 1 + sqrt ( 5 ) ) ) / 4 ) ) #NEWLINE# p2 . spin ( ( pi / 10 ) ) #NEWLINE# dict1 = p2 . angles #NEWLINE# assert ( dict1 [ Point ( 0 , 5 ) ] == ( ( 3 * pi ) / 5 ) ) #NEWLINE# assert p1 . is_convex ( ) #NEWLINE# assert ( p1 . rotation == 0 ) #NEWLINE# assert p1 . encloses_point ( Point ( 0 , 0 ) ) #NEWLINE# assert ( p1 . encloses_point ( Point ( 11 , 0 ) ) is False ) #NEWLINE# assert p2 . encloses_point ( Point ( 0 , 4.9 ) ) #NEWLINE# p1 . spin ( ( pi / 3 ) ) #NEWLINE# assert ( p1 . rotation == ( pi / 3 ) ) #NEWLINE# assert ( p1 . vertices [ 0 ] == Point ( 5 , ( 5 * sqrt ( 3 ) ) ) ) #NEWLINE# for var in p1 . args : #NEWLINE# #INDENT# if isinstance ( var , Point ) : #NEWLINE# #INDENT# assert ( var == Point ( 0 , 0 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert ( ( var == 5 ) or ( var == 10 ) or ( var == ( pi / 3 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# assert ( p1 != Point ( 0 , 0 ) ) #NEWLINE# assert ( p1 != p5 ) #NEWLINE# p1_old = p1 #NEWLINE# assert ( p1 . rotate ( ( pi / 3 ) ) == RegularPolygon ( Point ( 0 , 0 ) , 10 , 5 , ( ( 2 * pi ) / 3 ) ) ) #NEWLINE# assert ( p1 == p1_old ) #NEWLINE# assert ( p1 . area == ( ( ( ( - 250 ) * sqrt ( 5 ) ) + 1250 ) / ( 4 * tan ( ( pi / 5 ) ) ) ) ) #NEWLINE# assert ( p1 . length == ( 20 * sqrt ( ( ( ( - sqrt ( 5 ) ) / 8 ) + ( 5 / 8 ) ) ) ) ) #NEWLINE# assert ( p1 . scale ( 2 , 2 ) == RegularPolygon ( p1 . center , ( p1 . radius * 2 ) , p1 . _n , p1 . rotation ) ) #NEWLINE# assert ( RegularPolygon ( ( 0 , 0 ) , 1 , 4 ) . scale ( 2 , 3 ) == Polygon ( Point ( 2 , 0 ) , Point ( 0 , 3 ) , Point ( ( - 2 ) , 0 ) , Point ( 0 , ( - 3 ) ) ) ) #NEWLINE# assert ( repr ( p1 ) == str ( p1 ) ) #NEWLINE# angles = p4 . angles #NEWLINE# assert feq ( angles [ Point ( 0 , 0 ) ] . evalf ( ) , Float ( '0.7853981633974483' ) ) #NEWLINE# assert feq ( angles [ Point ( 4 , 4 ) ] . evalf ( ) , Float ( '1.2490457723982544' ) ) #NEWLINE# assert feq ( angles [ Point ( 5 , 2 ) ] . evalf ( ) , Float ( '1.8925468811915388' ) ) #NEWLINE# assert feq ( angles [ Point ( 3 , 0 ) ] . evalf ( ) , Float ( '2.3561944901923449' ) ) #NEWLINE# angles = p3 . angles #NEWLINE# assert feq ( angles [ Point ( 0 , 0 ) ] . evalf ( ) , Float ( '0.7853981633974483' ) ) #NEWLINE# assert feq ( angles [ Point ( 4 , 4 ) ] . evalf ( ) , Float ( '1.2490457723982544' ) ) #NEWLINE# assert feq ( angles [ Point ( 5 , 2 ) ] . evalf ( ) , Float ( '1.8925468811915388' ) ) #NEWLINE# assert feq ( angles [ Point ( 3 , 0 ) ] . evalf ( ) , Float ( '2.3561944901923449' ) ) #NEWLINE# p1 = Point ( 0 , 0 ) #NEWLINE# p2 = Point ( 5 , 0 ) #NEWLINE# p3 = Point ( 0 , 5 ) #NEWLINE# t1 = Triangle ( p1 , p2 , p3 ) #NEWLINE# t2 = Triangle ( p1 , p2 , Point ( Rational ( 5 , 2 ) , sqrt ( Rational ( 75 , 4 ) ) ) ) #NEWLINE# t3 = Triangle ( p1 , Point ( x1 , 0 ) , Point ( 0 , x1 ) ) #NEWLINE# s1 = t1 . sides #NEWLINE# assert ( Triangle ( p1 , p2 , p1 ) == Polygon ( p1 , p2 , p1 ) == Segment ( p1 , p2 ) ) #NEWLINE# raises ( GeometryError , ( lambda : Triangle ( Point ( 0 , 0 ) ) ) ) #NEWLINE# assert ( Triangle ( p1 , p1 , p1 ) == p1 ) #NEWLINE# assert ( Triangle ( p2 , ( p2 * 2 ) , ( p2 * 3 ) ) == Segment ( p2 , ( p2 * 3 ) ) ) #NEWLINE# assert ( t1 . area == Rational ( 25 , 2 ) ) #NEWLINE# assert t1 . is_right ( ) #NEWLINE# assert ( t2 . is_right ( ) is False ) #NEWLINE# assert t3 . is_right ( ) #NEWLINE# assert ( p1 in t1 ) #NEWLINE# assert ( t1 . sides [ 0 ] in t1 ) #NEWLINE# assert ( Segment ( ( 0 , 0 ) , ( 1 , 0 ) ) in t1 ) #NEWLINE# assert ( Point ( 5 , 5 ) not in t2 ) #NEWLINE# assert t1 . is_convex ( ) #NEWLINE# assert feq ( t1 . angles [ p1 ] . evalf ( ) , ( pi . evalf ( ) / 2 ) ) #NEWLINE# assert ( t1 . is_equilateral ( ) is False ) #NEWLINE# assert t2 . is_equilateral ( ) #NEWLINE# assert ( t3 . is_equilateral ( ) is False ) #NEWLINE# assert ( are_similar ( t1 , t2 ) is False ) #NEWLINE# assert are_similar ( t1 , t3 ) #NEWLINE# assert ( are_similar ( t2 , t3 ) is False ) #NEWLINE# assert ( t1 . is_similar ( Point ( 0 , 0 ) ) is False ) #NEWLINE# bisectors = t1 . bisectors ( ) #NEWLINE# assert ( bisectors [ p1 ] == Segment ( p1 , Point ( Rational ( 5 , 2 ) , Rational ( 5 , 2 ) ) ) ) #NEWLINE# ic = ( ( 250 - ( 125 * sqrt ( 2 ) ) ) / 50 ) #NEWLINE# assert ( t1 . incenter == Point ( ic , ic ) ) #NEWLINE# assert ( t1 . inradius == t1 . incircle . radius == ( 5 - ( ( 5 * sqrt ( 2 ) ) / 2 ) ) ) #NEWLINE# assert ( t2 . inradius == t2 . incircle . radius == ( ( 5 * sqrt ( 3 ) ) / 6 ) ) #NEWLINE# assert ( t3 . inradius == t3 . incircle . radius == ( ( x1 ** 2 ) / ( ( 2 + sqrt ( 2 ) ) * Abs ( x1 ) ) ) ) #NEWLINE# assert ( t1 . circumcircle . center == Point ( 2.5 , 2.5 ) ) #NEWLINE# m = t1 . medians #NEWLINE# assert ( t1 . centroid == Point ( Rational ( 5 , 3 ) , Rational ( 5 , 3 ) ) ) #NEWLINE# assert ( m [ p1 ] == Segment ( p1 , Point ( Rational ( 5 , 2 ) , Rational ( 5 , 2 ) ) ) ) #NEWLINE# assert ( t3 . medians [ p1 ] == Segment ( p1 , Point ( ( x1 / 2 ) , ( x1 / 2 ) ) ) ) #NEWLINE# assert ( intersection ( m [ p1 ] , m [ p2 ] , m [ p3 ] ) == [ t1 . centroid ] ) #NEWLINE# assert ( s1 . medial == Triangle ( Point ( 2.5 , 0 ) , Point ( 0 , 2.5 ) , Point ( 2.5 , 2.5 ) ) ) #NEWLINE# assert ( t1 . nine_point_circle == Circle ( Point ( 2.5 , 0 ) , Point ( 0 , 2.5 ) , Point ( 2.5 , 2.5 ) ) ) #NEWLINE# assert ( t1 . nine_point_circle == Circle ( Point ( 0 , 0 ) , Point ( 0 , 2.5 ) , Point ( 2.5 , 2.5 ) ) ) #NEWLINE# altitudes = t1 . altitudes #NEWLINE# assert ( altitudes [ p1 ] == Segment ( p1 , Point ( Rational ( 5 , 2 ) , Rational ( 5 , 2 ) ) ) ) #NEWLINE# assert ( altitudes [ p2 ] == s1 [ 0 ] ) #NEWLINE# assert ( altitudes [ p3 ] == s1 [ 2 ] ) #NEWLINE# assert ( t1 . orthocenter == p1 ) #NEWLINE# t = S ( 'Triangle(\n    Point(100080156402737/5000000000000, 79782624633431/500000000000),\n    Point(39223884078253/2000000000000, 156345163124289/1000000000000),\n    Point(31241359188437/1250000000000, 338338270939941/1000000000000000))' ) #NEWLINE# assert ( t . orthocenter == S ( 'Point(-78066086905059984021699779471538701955848721853/80368430960602242240789074233100000000000000,20151573611150265741278060334545897615974257/160736861921204484481578148466200000000000)' ) ) #NEWLINE# assert ( len ( intersection ( * bisectors . values ( ) ) ) == 1 ) #NEWLINE# assert ( len ( intersection ( * altitudes . values ( ) ) ) == 1 ) #NEWLINE# assert ( len ( intersection ( * m . values ( ) ) ) == 1 ) #NEWLINE# p1 = Polygon ( Point ( 0 , 0 ) , Point ( 1 , 0 ) , Point ( 1 , 1 ) , Point ( 0 , 1 ) ) #NEWLINE# p2 = Polygon ( Point ( 0 , ( Rational ( 5 ) / 4 ) ) , Point ( 1 , ( Rational ( 5 ) / 4 ) ) , Point ( 1 , ( Rational ( 9 ) / 4 ) ) , Point ( 0 , ( Rational ( 9 ) / 4 ) ) ) #NEWLINE# p3 = Polygon ( Point ( 1 , 2 ) , Point ( 2 , 2 ) , Point ( 2 , 1 ) ) #NEWLINE# p4 = Polygon ( Point ( 1 , 1 ) , Point ( ( Rational ( 6 ) / 5 ) , 1 ) , Point ( 1 , ( Rational ( 6 ) / 5 ) ) ) #NEWLINE# pt1 = Point ( half , half ) #NEWLINE# pt2 = Point ( 1 , 1 ) #NEWLINE# 'Polygon to Point' #NEWLINE# assert ( p1 . distance ( pt1 ) == half ) #NEWLINE# assert ( p1 . distance ( pt2 ) == 0 ) #NEWLINE# assert ( p2 . distance ( pt1 ) == ( Rational ( 3 ) / 4 ) ) #NEWLINE# assert ( p3 . distance ( pt2 ) == ( sqrt ( 2 ) / 2 ) ) #NEWLINE# 'Polygon to Polygon' #NEWLINE# warnings . filterwarnings ( 'error' , message = 'Polygons may intersect producing erroneous output' ) #NEWLINE# raises ( UserWarning , ( lambda : p1 . distance ( p2 ) ) ) #NEWLINE# warnings . filterwarnings ( 'ignore' , message = 'Polygons may intersect producing erroneous output' ) #NEWLINE# assert ( p1 . distance ( p2 ) == ( half / 2 ) ) #NEWLINE# assert ( p1 . distance ( p3 ) == ( sqrt ( 2 ) / 2 ) ) #NEWLINE# assert ( p3 . distance ( p4 ) == ( ( sqrt ( 2 ) / 2 ) - ( sqrt ( ( Rational ( 2 ) / 25 ) ) / 2 ) ) )