<s> import math <EOL> import re <EOL> from pint import UnitRegistry <EOL> units = UnitRegistry ( ) <EOL> units . define ( '<STR_LIT>' ) <EOL> units . define ( '<STR_LIT>' ) <EOL> def steps ( val ) : <EOL> val = unit ( val , unit = None ) <EOL> return int ( val . to ( "<STR_LIT>" ) . magnitude ) <EOL> DEFAULT_UNIT = "<STR_LIT>" <EOL> def unit ( val , ** kw ) : <EOL> _unit = kw . get ( "<STR_LIT>" , DEFAULT_UNIT ) <EOL> if _unit != None : <EOL> _unit = units . parse_expression ( _unit ) <EOL> if type ( val ) != units . Quantity : <EOL> if type ( val ) in ( int , float ) : <EOL> assert _unit , "<STR_LIT>" % ( val , type ( val ) ) <EOL> val = val * _unit <EOL> elif type ( val ) in ( str , unicode ) : <EOL> val = units . parse_expression ( val ) <EOL> else : <EOL> raise TypeError , "<STR_LIT>" % str ( type ( val ) ) <EOL> assert type ( val ) == units . Quantity , "<STR_LIT>" % ( type ( val ) , units . Quantity ) <EOL> if _unit : <EOL> val = val . to ( _unit ) <EOL> return val <EOL> def inch2mm ( inches ) : <EOL> inches = unit ( inches , unit = "<STR_LIT>" ) <EOL> return inches . to ( units . mm ) . magnitude <EOL> def mm2inch ( mm ) : <EOL> mm = unit ( mm , unit = "<STR_LIT>" ) <EOL> return mm . to ( units . inch ) . magnitude <EOL> def circle ( ** kw ) : <EOL> assert "<STR_LIT>" in kw , "<STR_LIT>" <EOL> defs = { "<STR_LIT>" : <NUM_LIT:20> , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:0> } <EOL> _kw = defs . copy ( ) <EOL> _kw . update ( kw ) <EOL> _steps = int ( _kw [ "<STR_LIT>" ] ) <EOL> radius = unit ( _kw [ "<STR_LIT>" ] ) <EOL> center_x = unit ( _kw [ "<STR_LIT>" ] ) <EOL> center_y = unit ( _kw [ "<STR_LIT>" ] ) <EOL> phase = float ( _kw [ "<STR_LIT>" ] ) <EOL> if steps < <NUM_LIT:2> : <EOL> raise ValueError , "<STR_LIT>" <EOL> radstep = ( <NUM_LIT:2> * math . pi ) / float ( _steps - <NUM_LIT:1> ) <EOL> for rad in range ( int ( _steps ) ) : <EOL> x = math . cos ( rad * radstep + phase ) * radius + center_x <EOL> y = math . sin ( rad * radstep + phase ) * radius + center_y <EOL> yield ( steps ( x ) , steps ( y ) ) </s>
