<s> import math <EOL> def getPos ( bbox , pos = ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) ) : <EOL> return ( bbox [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] + pos [ <NUM_LIT:0> ] * ( bbox [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] - bbox [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) , bbox [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] + pos [ <NUM_LIT:1> ] * ( bbox [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] - bbox [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) ) <EOL> def getClockwiseArcAngle ( arcAngle = <NUM_LIT> ) : <EOL> return abs ( arcAngle ) <EOL> def getCounterclockwiseArcAngle ( arcAngle = <NUM_LIT> ) : <EOL> return - abs ( arcAngle ) <EOL> def _maxDistInDirection ( area , beginPos , angle ) : <EOL> angle = angle % <NUM_LIT> <EOL> rad = math . radians ( angle ) <EOL> x , y = beginPos <EOL> top = area . getBbox ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> left = area . getBbox ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> bottom = area . getBbox ( ) [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] <EOL> right = area . getBbox ( ) [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> if <NUM_LIT:0> < angle < <NUM_LIT> : <EOL> maxDistY = ( bottom - y ) / math . sin ( rad ) <EOL> elif <NUM_LIT> < angle < <NUM_LIT> : <EOL> maxDistY = ( top - y ) / math . sin ( rad ) <EOL> else : <EOL> maxDistY = float ( '<STR_LIT>' ) <EOL> if <NUM_LIT> < angle < <NUM_LIT> : <EOL> maxDistX = ( left - x ) / math . cos ( rad ) <EOL> elif <NUM_LIT> < angle or angle < <NUM_LIT> : <EOL> maxDistX = ( right - x ) / math . cos ( rad ) <EOL> else : <EOL> maxDistX = float ( '<STR_LIT>' ) <EOL> return min ( maxDistX , maxDistY ) <EOL> def angleDistToPos ( area , beginPos , angle , distance ) : <EOL> distanceToEdge = _maxDistInDirection ( area , beginPos , angle ) <EOL> rad = math . radians ( angle ) <EOL> endPosX = beginPos [ <NUM_LIT:0> ] + math . cos ( rad ) * distanceToEdge * distance <EOL> endPosY = beginPos [ <NUM_LIT:1> ] + math . sin ( rad ) * distanceToEdge * distance <EOL> return ( endPosX , endPosY ) <EOL> class Element ( object ) : <EOL> def __init__ ( self ) : <EOL> super ( Element , self ) . __init__ ( ) <EOL> def getPos ( self , pos = ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) ) : <EOL> raise NotImplementedError <EOL> def getBbox ( self ) : <EOL> raise NotImplementedError <EOL> class Location ( Element ) : <EOL> def __init__ ( self , pos ) : <EOL> super ( Location , self ) . __init__ ( ) <EOL> self . _pos = pos <EOL> def getPos ( self , pos = ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) ) : <EOL> return self . _pos <EOL> def getBbox ( self ) : <EOL> return ( self . _pos , self . _pos ) <EOL> class Rectangle ( Element ) : <EOL> def __init__ ( self , upperLeftPos , lowerRightPos ) : <EOL> super ( Rectangle , self ) . __init__ ( ) <EOL> self . _bbox = ( upperLeftPos , lowerRightPos ) <EOL> def getPos ( self , pos = ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) ) : <EOL> return getPos ( self . _bbox , pos ) <EOL> def getBbox ( self ) : <EOL> return self . _bbox <EOL> class ImageRectangle ( Rectangle ) : <EOL> def __init__ ( self , upperLeftPos , lowerRightPos , imageUri ) : <EOL> super ( ImageRectangle , self ) . __init__ ( upperLeftPos , lowerRightPos ) <EOL> self . _imageUri = imageUri <EOL> def getImageUri ( self ) : <EOL> return self . _imageUri <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> ( self . __class__ . __name__ , ) + self . getBbox ( ) + ( repr ( self . _imageUri ) , ) ) <EOL> class TextRectangle ( Rectangle ) : <EOL> def __init__ ( self , upperLeftPos , lowerRightPos , text ) : <EOL> super ( TextRectangle , self ) . __init__ ( upperLeftPos , lowerRightPos ) <EOL> self . _text = text <EOL> def getText ( self ) : <EOL> return self . _text <EOL> def getWords ( self ) : <EOL> pass <EOL> class Word ( TextRectangle ) : <EOL> def __init__ ( self , upperLeftPos , lowerRightPos , word ) : <EOL> super ( Word , self ) . __init__ ( upperLeftPos , lowerRightPos , word ) <EOL> def getWords ( self ) : <EOL> return ( self , ) </s>
