<s> from __future__ import print_function , division <EOL> try : <EOL> from pyglet . gl . gl import c_float <EOL> except ImportError : <EOL> pass <EOL> from pyglet . gl import * <EOL> from sympy . core import S <EOL> from sympy . core . compatibility import range <EOL> def get_model_matrix ( array_type = c_float , glGetMethod = glGetFloatv ) : <EOL> """<STR_LIT>""" <EOL> m = ( array_type * <NUM_LIT:16> ) ( ) <EOL> glGetMethod ( GL_MODELVIEW_MATRIX , m ) <EOL> return m <EOL> def get_projection_matrix ( array_type = c_float , glGetMethod = glGetFloatv ) : <EOL> """<STR_LIT>""" <EOL> m = ( array_type * <NUM_LIT:16> ) ( ) <EOL> glGetMethod ( GL_PROJECTION_MATRIX , m ) <EOL> return m <EOL> def get_viewport ( ) : <EOL> """<STR_LIT>""" <EOL> m = ( c_int * <NUM_LIT:4> ) ( ) <EOL> glGetIntegerv ( GL_VIEWPORT , m ) <EOL> return m <EOL> def get_direction_vectors ( ) : <EOL> m = get_model_matrix ( ) <EOL> return ( ( m [ <NUM_LIT:0> ] , m [ <NUM_LIT:4> ] , m [ <NUM_LIT:8> ] ) , <EOL> ( m [ <NUM_LIT:1> ] , m [ <NUM_LIT:5> ] , m [ <NUM_LIT:9> ] ) , <EOL> ( m [ <NUM_LIT:2> ] , m [ <NUM_LIT:6> ] , m [ <NUM_LIT:10> ] ) ) <EOL> def get_view_direction_vectors ( ) : <EOL> m = get_model_matrix ( ) <EOL> return ( ( m [ <NUM_LIT:0> ] , m [ <NUM_LIT:1> ] , m [ <NUM_LIT:2> ] ) , <EOL> ( m [ <NUM_LIT:4> ] , m [ <NUM_LIT:5> ] , m [ <NUM_LIT:6> ] ) , <EOL> ( m [ <NUM_LIT:8> ] , m [ <NUM_LIT:9> ] , m [ <NUM_LIT:10> ] ) ) <EOL> def get_basis_vectors ( ) : <EOL> return ( ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ) ) <EOL> def screen_to_model ( x , y , z ) : <EOL> m = get_model_matrix ( c_double , glGetDoublev ) <EOL> p = get_projection_matrix ( c_double , glGetDoublev ) <EOL> w = get_viewport ( ) <EOL> mx , my , mz = c_double ( ) , c_double ( ) , c_double ( ) <EOL> gluUnProject ( x , y , z , m , p , w , mx , my , mz ) <EOL> return float ( mx . value ) , float ( my . value ) , float ( mz . value ) <EOL> def model_to_screen ( x , y , z ) : <EOL> m = get_model_matrix ( c_double , glGetDoublev ) <EOL> p = get_projection_matrix ( c_double , glGetDoublev ) <EOL> w = get_viewport ( ) <EOL> mx , my , mz = c_double ( ) , c_double ( ) , c_double ( ) <EOL> gluProject ( x , y , z , m , p , w , mx , my , mz ) <EOL> return float ( mx . value ) , float ( my . value ) , float ( mz . value ) <EOL> def vec_subs ( a , b ) : <EOL> return tuple ( a [ i ] - b [ i ] for i in range ( len ( a ) ) ) <EOL> def billboard_matrix ( ) : <EOL> """<STR_LIT>""" <EOL> m = get_model_matrix ( ) <EOL> m [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> m [ <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> m [ <NUM_LIT:2> ] = <NUM_LIT:0> <EOL> m [ <NUM_LIT:4> ] = <NUM_LIT:0> <EOL> m [ <NUM_LIT:5> ] = <NUM_LIT:1> <EOL> m [ <NUM_LIT:6> ] = <NUM_LIT:0> <EOL> m [ <NUM_LIT:8> ] = <NUM_LIT:0> <EOL> m [ <NUM_LIT:9> ] = <NUM_LIT:0> <EOL> m [ <NUM_LIT:10> ] = <NUM_LIT:1> <EOL> glLoadMatrixf ( m ) <EOL> def create_bounds ( ) : <EOL> return [ [ S . Infinity , - S . Infinity , <NUM_LIT:0> ] , <EOL> [ S . Infinity , - S . Infinity , <NUM_LIT:0> ] , <EOL> [ S . Infinity , - S . Infinity , <NUM_LIT:0> ] ] <EOL> def update_bounds ( b , v ) : <EOL> if v is None : <EOL> return <EOL> for axis in range ( <NUM_LIT:3> ) : <EOL> b [ axis ] [ <NUM_LIT:0> ] = min ( [ b [ axis ] [ <NUM_LIT:0> ] , v [ axis ] ] ) <EOL> b [ axis ] [ <NUM_LIT:1> ] = max ( [ b [ axis ] [ <NUM_LIT:1> ] , v [ axis ] ] ) <EOL> def interpolate ( a_min , a_max , a_ratio ) : <EOL> return a_min + a_ratio * ( a_max - a_min ) <EOL> def rinterpolate ( a_min , a_max , a_value ) : <EOL> a_range = a_max - a_min <EOL> if a_range == <NUM_LIT:0> : <EOL> a_range = <NUM_LIT:1.0> <EOL> return ( a_value - a_min ) / float ( a_range ) <EOL> def interpolate_color ( color1 , color2 , ratio ) : <EOL> return tuple ( interpolate ( color1 [ i ] , color2 [ i ] , ratio ) for i in range ( <NUM_LIT:3> ) ) <EOL> def scale_value ( v , v_min , v_len ) : <EOL> return ( v - v_min ) / v_len <EOL> def scale_value_list ( flist ) : <EOL> v_min , v_max = min ( flist ) , max ( flist ) <EOL> v_len = v_max - v_min <EOL> return list ( scale_value ( f , v_min , v_len ) for f in flist ) <EOL> def strided_range ( r_min , r_max , stride , max_steps = <NUM_LIT:50> ) : <EOL> o_min , o_max = r_min , r_max <EOL> if abs ( r_min - r_max ) < <NUM_LIT> : <EOL> return [ ] <EOL> try : <EOL> range ( int ( r_min - r_max ) ) <EOL> except TypeError : <EOL> return [ ] <EOL> if r_min > r_max : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> r_min_s = ( r_min % stride ) <EOL> r_max_s = stride - ( r_max % stride ) <EOL> if abs ( r_max_s - stride ) < <NUM_LIT> : <EOL> r_max_s = <NUM_LIT:0.0> <EOL> r_min -= r_min_s <EOL> r_max += r_max_s <EOL> r_steps = int ( ( r_max - r_min ) / stride ) <EOL> if max_steps and r_steps > max_steps : <EOL> return strided_range ( o_min , o_max , stride * <NUM_LIT:2> ) <EOL> return [ r_min ] + list ( r_min + e * stride for e in range ( <NUM_LIT:1> , r_steps + <NUM_LIT:1> ) ) + [ r_max ] <EOL> def parse_option_string ( s ) : <EOL> if not isinstance ( s , str ) : <EOL> return None <EOL> options = { } <EOL> for token in s . split ( '<STR_LIT:;>' ) : <EOL> pieces = token . split ( '<STR_LIT:=>' ) <EOL> if len ( pieces ) == <NUM_LIT:1> : <EOL> option , value = pieces [ <NUM_LIT:0> ] , "<STR_LIT>" <EOL> elif len ( pieces ) == <NUM_LIT:2> : <EOL> option , value = pieces <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % ( s ) ) <EOL> options [ option . strip ( ) ] = value . strip ( ) <EOL> return options <EOL> def dot_product ( v1 , v2 ) : <EOL> return sum ( v1 [ i ] * v2 [ i ] for i in range ( <NUM_LIT:3> ) ) <EOL> def vec_sub ( v1 , v2 ) : <EOL> return tuple ( v1 [ i ] - v2 [ i ] for i in range ( <NUM_LIT:3> ) ) <EOL> def vec_mag ( v ) : <EOL> return sum ( v [ i ] ** <NUM_LIT:2> for i in range ( <NUM_LIT:3> ) ) ** ( <NUM_LIT:0.5> ) </s>
