<s> '''<STR_LIT>''' <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> import math <EOL> class Vector ( list ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , * largs ) : <EOL> if len ( largs ) == <NUM_LIT:1> : <EOL> super ( Vector , self ) . __init__ ( largs [ <NUM_LIT:0> ] ) <EOL> elif len ( largs ) == <NUM_LIT:2> : <EOL> super ( Vector , self ) . __init__ ( largs ) <EOL> else : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def _get_x ( self ) : <EOL> return self [ <NUM_LIT:0> ] <EOL> def _set_x ( self , x ) : <EOL> self [ <NUM_LIT:0> ] = x <EOL> x = property ( _get_x , _set_x ) <EOL> '''<STR_LIT>''' <EOL> def _get_y ( self ) : <EOL> return self [ <NUM_LIT:1> ] <EOL> def _set_y ( self , y ) : <EOL> self [ <NUM_LIT:1> ] = y <EOL> y = property ( _get_y , _set_y ) <EOL> '''<STR_LIT>''' <EOL> def __getslice__ ( self , i , j ) : <EOL> try : <EOL> return Vector ( super ( Vector , self ) . __getslice__ ( i , j ) ) <EOL> except Exception : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> def __add__ ( self , val ) : <EOL> return Vector ( list ( map ( lambda x , y : x + y , self , val ) ) ) <EOL> def __iadd__ ( self , val ) : <EOL> if type ( val ) in ( int , float ) : <EOL> self . x += val <EOL> self . y += val <EOL> else : <EOL> self . x += val . x <EOL> self . y += val . y <EOL> return self <EOL> def __neg__ ( self ) : <EOL> return Vector ( [ - x for x in self ] ) <EOL> def __sub__ ( self , val ) : <EOL> return Vector ( list ( map ( lambda x , y : x - y , self , val ) ) ) <EOL> def __isub__ ( self , val ) : <EOL> if type ( val ) in ( int , float ) : <EOL> self . x -= val <EOL> self . y -= val <EOL> else : <EOL> self . x -= val . x <EOL> self . y -= val . y <EOL> return self <EOL> def __mul__ ( self , val ) : <EOL> try : <EOL> return Vector ( list ( map ( lambda x , y : x * y , self , val ) ) ) <EOL> except Exception : <EOL> return Vector ( [ x * val for x in self ] ) <EOL> def __imul__ ( self , val ) : <EOL> if type ( val ) in ( int , float ) : <EOL> self . x *= val <EOL> self . y *= val <EOL> else : <EOL> self . x *= val . x <EOL> self . y *= val . y <EOL> return self <EOL> def __rmul__ ( self , val ) : <EOL> return ( self * val ) <EOL> def __truediv__ ( self , val ) : <EOL> try : <EOL> return Vector ( list ( map ( lambda x , y : x / y , self , val ) ) ) <EOL> except Exception : <EOL> return Vector ( [ x / val for x in self ] ) <EOL> def __div__ ( self , val ) : <EOL> try : <EOL> return Vector ( list ( map ( lambda x , y : x / y , self , val ) ) ) <EOL> except Exception : <EOL> return Vector ( [ x / val for x in self ] ) <EOL> def __rtruediv__ ( self , val ) : <EOL> try : <EOL> return Vector ( * val ) / self <EOL> except Exception : <EOL> return Vector ( val , val ) / self <EOL> def __rdiv__ ( self , val ) : <EOL> try : <EOL> return Vector ( * val ) / self <EOL> except Exception : <EOL> return Vector ( val , val ) / self <EOL> def __idiv__ ( self , val ) : <EOL> if type ( val ) in ( int , float ) : <EOL> self . x /= val <EOL> self . y /= val <EOL> else : <EOL> self . x /= val . x <EOL> self . y /= val . y <EOL> return self <EOL> def length ( self ) : <EOL> '''<STR_LIT>''' <EOL> return math . sqrt ( self [ <NUM_LIT:0> ] ** <NUM_LIT:2> + self [ <NUM_LIT:1> ] ** <NUM_LIT:2> ) <EOL> def length2 ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self [ <NUM_LIT:0> ] ** <NUM_LIT:2> + self [ <NUM_LIT:1> ] ** <NUM_LIT:2> <EOL> def distance ( self , to ) : <EOL> '''<STR_LIT>''' <EOL> return math . sqrt ( ( self [ <NUM_LIT:0> ] - to [ <NUM_LIT:0> ] ) ** <NUM_LIT:2> + ( self [ <NUM_LIT:1> ] - to [ <NUM_LIT:1> ] ) ** <NUM_LIT:2> ) <EOL> def distance2 ( self , to ) : <EOL> '''<STR_LIT>''' <EOL> return ( self [ <NUM_LIT:0> ] - to [ <NUM_LIT:0> ] ) ** <NUM_LIT:2> + ( self [ <NUM_LIT:1> ] - to [ <NUM_LIT:1> ] ) ** <NUM_LIT:2> <EOL> def normalize ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self [ <NUM_LIT:0> ] == <NUM_LIT:0.> and self [ <NUM_LIT:1> ] == <NUM_LIT:0.> : <EOL> return Vector ( <NUM_LIT:0.> , <NUM_LIT:0.> ) <EOL> return self / self . length ( ) <EOL> def dot ( self , a ) : <EOL> '''<STR_LIT>''' <EOL> return self [ <NUM_LIT:0> ] * a [ <NUM_LIT:0> ] + self [ <NUM_LIT:1> ] * a [ <NUM_LIT:1> ] <EOL> def angle ( self , a ) : <EOL> '''<STR_LIT>''' <EOL> angle = - ( <NUM_LIT> / math . pi ) * math . atan2 ( <EOL> self [ <NUM_LIT:0> ] * a [ <NUM_LIT:1> ] - self [ <NUM_LIT:1> ] * a [ <NUM_LIT:0> ] , <EOL> self [ <NUM_LIT:0> ] * a [ <NUM_LIT:0> ] + self [ <NUM_LIT:1> ] * a [ <NUM_LIT:1> ] ) <EOL> return angle <EOL> def rotate ( self , angle ) : <EOL> '''<STR_LIT>''' <EOL> angle = math . radians ( angle ) <EOL> return Vector ( <EOL> ( self [ <NUM_LIT:0> ] * math . cos ( angle ) ) - ( self [ <NUM_LIT:1> ] * math . sin ( angle ) ) , <EOL> ( self [ <NUM_LIT:1> ] * math . cos ( angle ) ) + ( self [ <NUM_LIT:0> ] * math . sin ( angle ) ) ) <EOL> @ staticmethod <EOL> def line_intersection ( v1 , v2 , v3 , v4 ) : <EOL> '''<STR_LIT>''' <EOL> x1 , x2 , x3 , x4 = float ( v1 [ <NUM_LIT:0> ] ) , float ( v2 [ <NUM_LIT:0> ] ) , float ( v3 [ <NUM_LIT:0> ] ) , float ( v4 [ <NUM_LIT:0> ] ) <EOL> y1 , y2 , y3 , y4 = float ( v1 [ <NUM_LIT:1> ] ) , float ( v2 [ <NUM_LIT:1> ] ) , float ( v3 [ <NUM_LIT:1> ] ) , float ( v4 [ <NUM_LIT:1> ] ) <EOL> u = ( x1 * y2 - y1 * x2 ) <EOL> v = ( x3 * y4 - y3 * x4 ) <EOL> denom = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 ) <EOL> if denom == <NUM_LIT:0> : <EOL> return None <EOL> px = ( u * ( x3 - x4 ) - ( x1 - x2 ) * v ) / denom <EOL> py = ( u * ( y3 - y4 ) - ( y1 - y2 ) * v ) / denom <EOL> return Vector ( px , py ) <EOL> @ staticmethod <EOL> def segment_intersection ( v1 , v2 , v3 , v4 ) : <EOL> '''<STR_LIT>''' <EOL> x1 , x2 , x3 , x4 = float ( v1 [ <NUM_LIT:0> ] ) , float ( v2 [ <NUM_LIT:0> ] ) , float ( v3 [ <NUM_LIT:0> ] ) , float ( v4 [ <NUM_LIT:0> ] ) <EOL> y1 , y2 , y3 , y4 = float ( v1 [ <NUM_LIT:1> ] ) , float ( v2 [ <NUM_LIT:1> ] ) , float ( v3 [ <NUM_LIT:1> ] ) , float ( v4 [ <NUM_LIT:1> ] ) <EOL> u = ( x1 * y2 - y1 * x2 ) <EOL> v = ( x3 * y4 - y3 * x4 ) <EOL> denom = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 ) <EOL> if denom == <NUM_LIT:0> : <EOL> return None <EOL> px = ( u * ( x3 - x4 ) - ( x1 - x2 ) * v ) / denom <EOL> py = ( u * ( y3 - y4 ) - ( y1 - y2 ) * v ) / denom <EOL> c1 = ( x1 <= px <= x2 ) or ( x2 <= px <= x1 ) <EOL> c2 = ( y1 <= py <= y2 ) or ( y2 <= py <= y1 ) <EOL> c3 = ( x3 <= px <= x4 ) or ( x4 <= px <= x3 ) <EOL> c4 = ( y3 <= py <= y4 ) or ( y4 <= py <= y3 ) <EOL> if ( c1 and c2 ) and ( c3 and c4 ) : <EOL> return Vector ( px , py ) <EOL> else : <EOL> return None <EOL> @ staticmethod <EOL> def in_bbox ( point , a , b ) : <EOL> '''<STR_LIT>''' <EOL> return ( ( point [ <NUM_LIT:0> ] <= a [ <NUM_LIT:0> ] and point [ <NUM_LIT:0> ] >= b [ <NUM_LIT:0> ] or <EOL> point [ <NUM_LIT:0> ] <= b [ <NUM_LIT:0> ] and point [ <NUM_LIT:0> ] >= a [ <NUM_LIT:0> ] ) and <EOL> ( point [ <NUM_LIT:1> ] <= a [ <NUM_LIT:1> ] and point [ <NUM_LIT:1> ] >= b [ <NUM_LIT:1> ] or <EOL> point [ <NUM_LIT:1> ] <= b [ <NUM_LIT:1> ] and point [ <NUM_LIT:1> ] >= a [ <NUM_LIT:1> ] ) ) </s>
