<s> """<STR_LIT>""" <EOL> __version__ = "<STR_LIT>" <EOL> __docformat__ = "<STR_LIT>" <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT:version>" , "<STR_LIT>" <EOL> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> , "<STR_LIT>" , "<STR_LIT>" <EOL> , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> import ctypes as ct <EOL> import weakref <EOL> try : <EOL> from weakref import WeakSet <EOL> except ImportError : <EOL> from . weakrefset import WeakSet <EOL> from . import _chipmunk as cp <EOL> from . import _chipmunk_ffi as cpffi <EOL> from . import util as u <EOL> from . vec2d import Vec2d <EOL> from pymunk . constraint import * <EOL> version = "<STR_LIT>" <EOL> """<STR_LIT>""" <EOL> chipmunk_version = "<STR_LIT>" % ( cp . cpVersionString . value . decode ( ) , '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> inf = <NUM_LIT> <EOL> """<STR_LIT>""" <EOL> cp . cpEnableSegmentToSegmentCollisions ( ) <EOL> class Space ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , iterations = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> self . _space = cp . cpSpaceNew ( ) <EOL> self . _space . contents . iterations = iterations <EOL> self . _static_body = Body ( ) <EOL> self . _handlers = { } <EOL> self . _default_handler = None <EOL> self . _post_step_callbacks = { } <EOL> self . _post_callback_keys = { } <EOL> self . _post_last_callback_key = <NUM_LIT:0> <EOL> self . _removed_shapes = { } <EOL> self . _shapes = { } <EOL> self . _bodies = set ( ) <EOL> self . _constraints = set ( ) <EOL> self . _locked = False <EOL> self . _add_later = set ( ) <EOL> self . _remove_later = set ( ) <EOL> def _get_shapes ( self ) : <EOL> return list ( self . _shapes . values ( ) ) <EOL> shapes = property ( _get_shapes , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_bodies ( self ) : <EOL> return list ( self . _bodies ) <EOL> bodies = property ( _get_bodies , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_constraints ( self ) : <EOL> return list ( self . _constraints ) <EOL> constraints = property ( _get_constraints , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_static_body ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _static_body <EOL> static_body = property ( _get_static_body , doc = _get_static_body . __doc__ ) <EOL> def __del__ ( self ) : <EOL> try : <EOL> cp . cpSpaceFree ( self . _space ) <EOL> except : <EOL> pass <EOL> def _set_iterations ( self , iterations ) : <EOL> self . _space . contents . iterations = iterations <EOL> def _get_iterations ( self ) : <EOL> return self . _space . contents . iterations <EOL> iterations = property ( _get_iterations , _set_iterations <EOL> , doc = """<STR_LIT>""" ) <EOL> def _set_gravity ( self , gravity_vec ) : <EOL> self . _space . contents . gravity = gravity_vec <EOL> def _get_gravity ( self ) : <EOL> return self . _space . contents . gravity <EOL> gravity = property ( _get_gravity , _set_gravity <EOL> , doc = """<STR_LIT>""" ) <EOL> def _set_damping ( self , damping ) : <EOL> self . _space . contents . damping = damping <EOL> def _get_damping ( self ) : <EOL> return self . _space . contents . damping <EOL> damping = property ( _get_damping , _set_damping <EOL> , doc = """<STR_LIT>""" ) <EOL> def _set_idle_speed_threshold ( self , idle_speed_threshold ) : <EOL> self . _space . contents . idleSpeedThreshold = idle_speed_threshold <EOL> def _get_idle_speed_threshold ( self ) : <EOL> return self . _space . contents . idleSpeedThreshold <EOL> idle_speed_threshold = property ( _get_idle_speed_threshold <EOL> , _set_idle_speed_threshold <EOL> , doc = """<STR_LIT>""" ) <EOL> def _set_sleep_time_threshold ( self , sleep_time_threshold ) : <EOL> self . _space . contents . sleepTimeThreshold = sleep_time_threshold <EOL> def _get_sleep_time_threshold ( self ) : <EOL> return self . _space . contents . sleepTimeThreshold <EOL> sleep_time_threshold = property ( _get_sleep_time_threshold <EOL> , _set_sleep_time_threshold <EOL> , doc = """<STR_LIT>""" ) <EOL> def _set_collision_slop ( self , collision_slop ) : <EOL> self . _space . contents . collisionSlop = collision_slop <EOL> def _get_collision_slop ( self ) : <EOL> return self . _space . contents . collisionSlop <EOL> collision_slop = property ( _get_collision_slop <EOL> , _set_collision_slop <EOL> , doc = """<STR_LIT>""" ) <EOL> def _set_collision_bias ( self , collision_bias ) : <EOL> self . _space . contents . collisionBias = collision_bias <EOL> def _get_collision_bias ( self ) : <EOL> return self . _space . contents . collisionBias <EOL> collision_bias = property ( _get_collision_bias <EOL> , _set_collision_bias <EOL> , doc = """<STR_LIT>""" ) <EOL> def _set_collision_persistence ( self , collision_persistence ) : <EOL> self . _space . contents . collisionPersistence = collision_persistence <EOL> def _get_collision_persistence ( self ) : <EOL> return self . _space . contents . collisionPersistence <EOL> collision_persistence = property ( _get_collision_persistence <EOL> , _set_collision_persistence <EOL> , doc = """<STR_LIT>""" ) <EOL> def _set_enable_contact_graph ( self , enable_contact_graph ) : <EOL> self . _space . contents . enableContactGraph = enable_contact_graph <EOL> def _get_enable_contact_graph ( self ) : <EOL> return self . _space . contents . enableContactGraph <EOL> enable_contact_graph = property ( _get_enable_contact_graph <EOL> , _set_enable_contact_graph <EOL> , doc = """<STR_LIT>""" ) <EOL> def add ( self , * objs ) : <EOL> """<STR_LIT>""" <EOL> if self . _locked : <EOL> self . _add_later . add ( objs ) <EOL> return <EOL> for o in objs : <EOL> if isinstance ( o , Body ) : <EOL> self . _add_body ( o ) <EOL> elif isinstance ( o , Shape ) : <EOL> self . _add_shape ( o ) <EOL> elif isinstance ( o , Constraint ) : <EOL> self . _add_constraint ( o ) <EOL> else : <EOL> for oo in o : <EOL> self . add ( oo ) <EOL> def remove ( self , * objs ) : <EOL> """<STR_LIT>""" <EOL> if self . _locked : <EOL> self . _remove_later . add ( objs ) <EOL> return <EOL> for o in objs : <EOL> if isinstance ( o , Body ) : <EOL> self . _remove_body ( o ) <EOL> elif isinstance ( o , Shape ) : <EOL> self . _remove_shape ( o ) <EOL> elif isinstance ( o , Constraint ) : <EOL> self . _remove_constraint ( o ) <EOL> else : <EOL> for oo in o : <EOL> self . remove ( oo ) <EOL> def _add_shape ( self , shape ) : <EOL> """<STR_LIT>""" <EOL> assert shape . _hashid_private not in self . _shapes , "<STR_LIT>" <EOL> self . _shapes [ shape . _hashid_private ] = shape <EOL> cp . cpSpaceAddShape ( self . _space , shape . _shape ) <EOL> def _add_body ( self , body ) : <EOL> """<STR_LIT>""" <EOL> assert body not in self . _bodies , "<STR_LIT>" <EOL> body . _space = weakref . proxy ( self ) <EOL> self . _bodies . add ( body ) <EOL> cp . cpSpaceAddBody ( self . _space , body . _body ) <EOL> def _add_constraint ( self , constraint ) : <EOL> """<STR_LIT>""" <EOL> assert constraint not in self . _constraints , "<STR_LIT>" <EOL> self . _constraints . add ( constraint ) <EOL> cp . cpSpaceAddConstraint ( self . _space , constraint . _constraint ) <EOL> def _remove_shape ( self , shape ) : <EOL> """<STR_LIT>""" <EOL> self . _removed_shapes [ shape . _hashid_private ] = shape <EOL> del self . _shapes [ shape . _hashid_private ] <EOL> cp . cpSpaceRemoveShape ( self . _space , shape . _shape ) <EOL> def _remove_body ( self , body ) : <EOL> """<STR_LIT>""" <EOL> body . _space = None <EOL> self . _bodies . remove ( body ) <EOL> cp . cpSpaceRemoveBody ( self . _space , body . _body ) <EOL> def _remove_constraint ( self , constraint ) : <EOL> """<STR_LIT>""" <EOL> self . _constraints . remove ( constraint ) <EOL> cp . cpSpaceRemoveConstraint ( self . _space , constraint . _constraint ) <EOL> def reindex_static ( self ) : <EOL> """<STR_LIT>""" <EOL> cp . cpSpaceReindexStatic ( self . _space ) <EOL> def reindex_shape ( self , shape ) : <EOL> """<STR_LIT>""" <EOL> cp . cpSpaceReindexShape ( self . _space , shape . _shape ) <EOL> def step ( self , dt ) : <EOL> """<STR_LIT>""" <EOL> self . _locked = True <EOL> cp . cpSpaceStep ( self . _space , dt ) <EOL> self . _removed_shapes = { } <EOL> self . _post_step_callbacks = { } <EOL> self . _post_callback_keys = { } <EOL> self . _post_last_callback_key = <NUM_LIT:0> <EOL> self . _locked = False <EOL> for objs in self . _add_later : <EOL> self . add ( objs ) <EOL> self . _add_later . clear ( ) <EOL> for objs in self . _remove_later : <EOL> self . remove ( objs ) <EOL> self . _remove_later . clear ( ) <EOL> def add_collision_handler ( self , a , b , begin = None , pre_solve = None , post_solve = None , separate = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _functions = self . _collision_function_helper ( begin , pre_solve , post_solve , separate , * args , ** kwargs ) <EOL> self . _handlers [ ( a , b ) ] = _functions <EOL> cp . cpSpaceAddCollisionHandler ( self . _space , a , b , <EOL> _functions [ <NUM_LIT:0> ] , _functions [ <NUM_LIT:1> ] , _functions [ <NUM_LIT:2> ] , _functions [ <NUM_LIT:3> ] , None ) <EOL> def set_default_collision_handler ( self , begin = None , pre_solve = None , post_solve = None , separate = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _functions = self . _collision_function_helper ( <EOL> begin , pre_solve , post_solve , separate , * args , ** kwargs <EOL> ) <EOL> self . _default_handler = _functions <EOL> cp . cpSpaceSetDefaultCollisionHandler ( self . _space , <EOL> _functions [ <NUM_LIT:0> ] , _functions [ <NUM_LIT:1> ] , _functions [ <NUM_LIT:2> ] , _functions [ <NUM_LIT:3> ] , None ) <EOL> def _collision_function_helper ( self , begin , pre_solve , post_solve , separate , * args , ** kwargs ) : <EOL> functions = [ ( begin , cp . cpCollisionBeginFunc ) <EOL> , ( pre_solve , cp . cpCollisionPreSolveFunc ) <EOL> , ( post_solve , cp . cpCollisionPostSolveFunc ) <EOL> , ( separate , cp . cpCollisionSeparateFunc ) ] <EOL> _functions = [ ] <EOL> for func , func_type in functions : <EOL> if func is None : <EOL> _f = ct . cast ( ct . POINTER ( ct . c_int ) ( ) , func_type ) <EOL> else : <EOL> _f = self . _get_cf1 ( func , func_type , * args , ** kwargs ) <EOL> _functions . append ( _f ) <EOL> return _functions <EOL> def remove_collision_handler ( self , a , b ) : <EOL> """<STR_LIT>""" <EOL> if ( a , b ) in self . _handlers : <EOL> del self . _handlers [ ( a , b ) ] <EOL> cp . cpSpaceRemoveCollisionHandler ( self . _space , a , b ) <EOL> def _get_cf1 ( self , func , function_type , * args , ** kwargs ) : <EOL> def cf ( _arbiter , _space , _data ) : <EOL> arbiter = Arbiter ( _arbiter , self ) <EOL> return func ( self , arbiter , * args , ** kwargs ) <EOL> return function_type ( cf ) <EOL> def add_post_step_callback ( self , callback_function , obj , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if obj in self . _post_callback_keys : <EOL> return False <EOL> def cf ( _space , key , data ) : <EOL> callback_function ( obj , * args , ** kwargs ) <EOL> f = cp . cpPostStepFunc ( cf ) <EOL> self . _post_last_callback_key += <NUM_LIT:1> <EOL> self . _post_callback_keys [ obj ] = self . _post_last_callback_key <EOL> self . _post_step_callbacks [ obj ] = f <EOL> key = self . _post_callback_keys [ obj ] <EOL> return bool ( cp . cpSpaceAddPostStepCallback ( self . _space , f , key , None ) ) <EOL> def point_query ( self , point , layers = - <NUM_LIT:1> , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . __query_hits = [ ] <EOL> def cf ( _shape , data ) : <EOL> shape = self . _get_shape ( _shape ) <EOL> self . __query_hits . append ( shape ) <EOL> f = cp . cpSpacePointQueryFunc ( cf ) <EOL> cp . cpSpacePointQuery ( self . _space , point , layers , group , f , None ) <EOL> return self . __query_hits <EOL> def point_query_first ( self , point , layers = - <NUM_LIT:1> , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> _shape = cp . cpSpacePointQueryFirst ( self . _space , point , layers , group ) <EOL> return self . _get_shape ( _shape ) <EOL> def _get_shape ( self , _shape ) : <EOL> if not bool ( _shape ) : <EOL> return None <EOL> hashid_private = _shape . contents . hashid_private <EOL> if hashid_private in self . _shapes : <EOL> shape = self . _shapes [ hashid_private ] <EOL> elif hashid_private in self . _removed_shapes : <EOL> shape = self . _removed_shapes [ hashid_private ] <EOL> return shape <EOL> def nearest_point_query ( self , point , max_distance , layers = - <NUM_LIT:1> , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . __query_hits = [ ] <EOL> def cf ( _shape , distance , point , data ) : <EOL> shape = self . _get_shape ( _shape ) <EOL> self . __query_hits . append ( dict ( shape = shape , distance = distance , point = Vec2d ( point ) ) ) <EOL> f = cp . cpSpaceNearestPointQueryFunc ( cf ) <EOL> cp . cpSpaceNearestPointQuery ( self . _space , point , max_distance , layers , group , f , None ) <EOL> return self . __query_hits <EOL> def nearest_point_query_nearest ( self , point , max_distance , layers = - <NUM_LIT:1> , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> info = cp . cpNearestPointQueryInfo ( ) <EOL> info_p = ct . POINTER ( cp . cpNearestPointQueryInfo ) ( info ) <EOL> _shape = cp . cpSpaceNearestPointQueryNearest ( self . _space , point , max_distance , layers , group , info_p ) <EOL> shape = self . _get_shape ( _shape ) <EOL> if shape != None : <EOL> return dict ( shape = shape , point = info . p , distance = info . d ) <EOL> return None <EOL> def segment_query ( self , start , end , layers = - <NUM_LIT:1> , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . __query_hits = [ ] <EOL> def cf ( _shape , t , n , data ) : <EOL> shape = self . _get_shape ( _shape ) <EOL> info = SegmentQueryInfo ( shape , start , end , t , n ) <EOL> self . __query_hits . append ( info ) <EOL> f = cp . cpSpaceSegmentQueryFunc ( cf ) <EOL> cp . cpSpaceSegmentQuery ( self . _space , start , end , layers , group , f , None ) <EOL> return self . __query_hits <EOL> def segment_query_first ( self , start , end , layers = - <NUM_LIT:1> , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> info = cp . cpSegmentQueryInfo ( ) <EOL> info_p = ct . POINTER ( cp . cpSegmentQueryInfo ) ( info ) <EOL> _shape = cp . cpSpaceSegmentQueryFirst ( self . _space , start , end , layers , group , info_p ) <EOL> shape = self . _get_shape ( _shape ) <EOL> if shape != None : <EOL> return SegmentQueryInfo ( shape , start , end , info . t , info . n ) <EOL> return None <EOL> def bb_query ( self , bb , layers = - <NUM_LIT:1> , group = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . __query_hits = [ ] <EOL> def cf ( _shape , data ) : <EOL> shape = self . _get_shape ( _shape ) <EOL> self . __query_hits . append ( shape ) <EOL> f = cp . cpSpaceBBQueryFunc ( cf ) <EOL> cp . cpSpaceBBQuery ( self . _space , bb . _bb , layers , group , f , None ) <EOL> return self . __query_hits <EOL> def shape_query ( self , shape ) : <EOL> """<STR_LIT>""" <EOL> self . __query_hits = [ ] <EOL> def cf ( _shape , points , data ) : <EOL> shape = self . _get_shape ( _shape ) <EOL> self . __query_hits . append ( shape ) <EOL> f = cp . cpSpaceShapeQueryFunc ( cf ) <EOL> cp . cpSpaceShapeQuery ( self . _space , shape . _shape , f , None ) <EOL> return self . __query_hits <EOL> class Body ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , mass = None , moment = None ) : <EOL> """<STR_LIT>""" <EOL> if mass == None and moment == None : <EOL> self . _body = cp . cpBodyNewStatic ( ) <EOL> else : <EOL> self . _body = cp . cpBodyNew ( mass , moment ) <EOL> self . _bodycontents = self . _body . contents <EOL> self . _position_callback = None <EOL> self . _velocity_callback = None <EOL> self . _space = None <EOL> self . _constraints = WeakSet ( ) <EOL> self . _shapes = WeakSet ( ) <EOL> def __del__ ( self ) : <EOL> try : <EOL> cp . cpBodyFree ( self . _body ) <EOL> except : <EOL> pass <EOL> def _set_mass ( self , mass ) : <EOL> cp . cpBodySetMass ( self . _body , mass ) <EOL> def _get_mass ( self ) : <EOL> return self . _bodycontents . m <EOL> mass = property ( _get_mass , _set_mass ) <EOL> def _set_moment ( self , moment ) : <EOL> cp . cpBodySetMoment ( self . _body , moment ) <EOL> def _get_moment ( self ) : <EOL> return self . _bodycontents . i <EOL> moment = property ( _get_moment , _set_moment ) <EOL> def _set_angle ( self , angle ) : <EOL> cp . cpBodySetAngle ( self . _body , angle ) <EOL> def _get_angle ( self ) : <EOL> return self . _bodycontents . a <EOL> angle = property ( _get_angle , _set_angle , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_rotation_vector ( self ) : <EOL> return self . _bodycontents . rot <EOL> rotation_vector = property ( _get_rotation_vector ) <EOL> def _set_torque ( self , t ) : <EOL> self . _bodycontents . t = t <EOL> def _get_torque ( self ) : <EOL> return self . _bodycontents . t <EOL> torque = property ( _get_torque , _set_torque ) <EOL> def _set_position ( self , pos ) : <EOL> self . _bodycontents . p = pos <EOL> def _get_position ( self ) : <EOL> return self . _bodycontents . p <EOL> position = property ( _get_position , _set_position ) <EOL> def _set_velocity ( self , vel ) : <EOL> self . _bodycontents . v = vel <EOL> def _get_velocity ( self ) : <EOL> return self . _bodycontents . v <EOL> velocity = property ( _get_velocity , _set_velocity ) <EOL> def _set_velocity_limit ( self , vel ) : <EOL> self . _bodycontents . v_limit = vel <EOL> def _get_velocity_limit ( self ) : <EOL> return self . _bodycontents . v_limit <EOL> velocity_limit = property ( _get_velocity_limit , _set_velocity_limit ) <EOL> def _set_angular_velocity ( self , w ) : <EOL> self . _bodycontents . w = w <EOL> def _get_angular_velocity ( self ) : <EOL> return self . _bodycontents . w <EOL> angular_velocity = property ( _get_angular_velocity , _set_angular_velocity ) <EOL> def _set_angular_velocity_limit ( self , w ) : <EOL> self . _bodycontents . w_limit = w <EOL> def _get_angular_velocity_limit ( self ) : <EOL> return self . _bodycontents . w_limit <EOL> angular_velocity_limit = property ( _get_angular_velocity_limit , _set_angular_velocity_limit ) <EOL> def _set_force ( self , f ) : <EOL> self . _bodycontents . f = f <EOL> def _get_force ( self ) : <EOL> return self . _bodycontents . f <EOL> force = property ( _get_force , _set_force ) <EOL> def _set_velocity_func ( self , func ) : <EOL> """<STR_LIT>""" <EOL> def _impl ( _ , gravity , damping , dt ) : <EOL> return func ( self , gravity , damping , dt ) <EOL> self . _velocity_callback = cp . cpBodyVelocityFunc ( _impl ) <EOL> self . _bodycontents . velocity_func = self . _velocity_callback <EOL> velocity_func = property ( fset = _set_velocity_func , <EOL> doc = _set_velocity_func . __doc__ ) <EOL> def _set_position_func ( self , func ) : <EOL> """<STR_LIT>""" <EOL> def _impl ( _ , dt ) : <EOL> func ( self , dt ) <EOL> return <NUM_LIT:0> <EOL> self . _position_callback = cp . cpBodyPositionFunc ( _impl ) <EOL> self . _bodycontents . position_func = self . _position_callback <EOL> position_func = property ( fset = _set_position_func , <EOL> doc = _set_position_func . __doc__ ) <EOL> def _get_kinetic_energy ( self ) : <EOL> vsq = self . velocity . dot ( self . velocity ) <EOL> wsq = self . angular_velocity * self . angular_velocity <EOL> return ( vsq * self . mass if vsq else <NUM_LIT:0.> ) + ( wsq * self . moment if wsq else <NUM_LIT:0.> ) <EOL> kinetic_energy = property ( _get_kinetic_energy , <EOL> doc = """<STR_LIT>""" ) <EOL> @ staticmethod <EOL> def update_velocity ( body , gravity , damping , dt ) : <EOL> """<STR_LIT>""" <EOL> cp . cpBodyUpdateVelocity ( body . _body , gravity , damping , dt ) <EOL> @ staticmethod <EOL> def update_position ( body , dt ) : <EOL> """<STR_LIT>""" <EOL> cp . cpBodyUpdatePosition ( body . _body , dt ) <EOL> def apply_impulse ( self , j , r = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> """<STR_LIT>""" <EOL> cp . cpBodyApplyImpulse ( self . _body , j , r ) <EOL> def reset_forces ( self ) : <EOL> """<STR_LIT>""" <EOL> cp . cpBodyResetForces ( self . _body ) <EOL> def apply_force ( self , f , r = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> """<STR_LIT>""" <EOL> cp . cpBodyApplyForce ( self . _body , f , r ) <EOL> def activate ( self ) : <EOL> """<STR_LIT>""" <EOL> cp . cpBodyActivate ( self . _body ) <EOL> def sleep ( self ) : <EOL> """<STR_LIT>""" <EOL> cp . cpBodySleep ( self . _body ) <EOL> def sleep_with_group ( self , body ) : <EOL> """<STR_LIT>""" <EOL> cp . cpBodySleepWithGroup ( self . _body , body . _body ) <EOL> def _is_sleeping ( self ) : <EOL> return cpffi . cpBodyIsSleeping ( self . _body ) <EOL> is_sleeping = property ( _is_sleeping , <EOL> doc = """<STR_LIT>""" ) <EOL> def _is_rogue ( self ) : <EOL> return cpffi . cpBodyIsRogue ( self . _body ) <EOL> is_rogue = property ( _is_rogue , <EOL> doc = """<STR_LIT>""" ) <EOL> def _is_static ( self ) : <EOL> return cpffi . cpBodyIsStatic ( self . _body ) <EOL> is_static = property ( _is_static , <EOL> doc = """<STR_LIT>""" ) <EOL> def each_arbiter ( self , func , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def impl ( body , _arbiter , _ ) : <EOL> arbiter = Arbiter ( _arbiter , self . _space ) <EOL> func ( arbiter , * args , ** kwargs ) <EOL> return <NUM_LIT:0> <EOL> f = cp . cpBodyArbiterIteratorFunc ( impl ) <EOL> cp . cpBodyEachArbiter ( self . _body , f , None ) <EOL> def _get_constraints ( self ) : <EOL> return set ( self . _constraints ) <EOL> constraints = property ( _get_constraints , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_shapes ( self ) : <EOL> return set ( self . _shapes ) <EOL> shapes = property ( _get_shapes , <EOL> doc = """<STR_LIT>""" ) <EOL> def local_to_world ( self , v ) : <EOL> """<STR_LIT>""" <EOL> return cpffi . cpBodyLocal2World ( self . _body , v ) <EOL> def world_to_local ( self , v ) : <EOL> """<STR_LIT>""" <EOL> return cpffi . cpBodyWorld2Local ( self . _body , v ) <EOL> class Shape ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , shape = None ) : <EOL> self . _shape = shape <EOL> self . _shapecontents = self . _shape . contents <EOL> self . _body = shape . body <EOL> self . data = None <EOL> def __del__ ( self ) : <EOL> try : <EOL> cp . cpShapeFree ( self . _shape ) <EOL> except : <EOL> pass <EOL> def _get_hashid_private ( self ) : <EOL> return self . _shapecontents . hashid_private <EOL> _hashid_private = property ( _get_hashid_private ) <EOL> def _get_sensor ( self ) : <EOL> return bool ( self . _shapecontents . sensor ) <EOL> def _set_sensor ( self , is_sensor ) : <EOL> self . _shapecontents . sensor = is_sensor <EOL> sensor = property ( _get_sensor , _set_sensor , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_collision_type ( self ) : <EOL> return self . _shapecontents . collision_type <EOL> def _set_collision_type ( self , t ) : <EOL> self . _shapecontents . collision_type = t <EOL> collision_type = property ( _get_collision_type , _set_collision_type , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_group ( self ) : <EOL> return self . _shapecontents . group <EOL> def _set_group ( self , group ) : <EOL> self . _shapecontents . group = group <EOL> group = property ( _get_group , _set_group , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_layers ( self ) : <EOL> return self . _shapecontents . layers <EOL> def _set_layers ( self , layers ) : <EOL> self . _shapecontents . layers = layers <EOL> layers = property ( _get_layers , _set_layers , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_elasticity ( self ) : <EOL> return self . _shapecontents . e <EOL> def _set_elasticity ( self , e ) : <EOL> self . _shapecontents . e = e <EOL> elasticity = property ( _get_elasticity , _set_elasticity , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_friction ( self ) : <EOL> return self . _shapecontents . u <EOL> def _set_friction ( self , u ) : <EOL> self . _shapecontents . u = u <EOL> friction = property ( _get_friction , _set_friction , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_surface_velocity ( self ) : <EOL> return self . _shapecontents . surface_v <EOL> def _set_surface_velocity ( self , surface_v ) : <EOL> self . _shapecontents . surface_v = surface_v <EOL> surface_velocity = property ( _get_surface_velocity , _set_surface_velocity , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_body ( self ) : <EOL> return self . _body <EOL> def _set_body ( self , body ) : <EOL> if self . _body != None : <EOL> self . _body . _shapes . remove ( self ) <EOL> if body != None : <EOL> body . _shapes . add ( self ) <EOL> self . _shapecontents . body = body . _body <EOL> else : <EOL> self . _shapecontents . body = None <EOL> self . _body = body <EOL> body = property ( _get_body , _set_body , <EOL> doc = """<STR_LIT>""" ) <EOL> def update ( self , position , rotation_vector ) : <EOL> """<STR_LIT>""" <EOL> return BB ( cp . cpShapeUpdate ( self . _shape , position , rotation_vector ) ) <EOL> def cache_bb ( self ) : <EOL> """<STR_LIT>""" <EOL> return BB ( cp . cpShapeCacheBB ( self . _shape ) ) <EOL> def _get_bb ( self ) : <EOL> return BB ( cpffi . cpShapeGetBB ( self . _shape ) ) <EOL> bb = property ( _get_bb , doc = """<STR_LIT>""" ) <EOL> def point_query ( self , p ) : <EOL> """<STR_LIT>""" <EOL> return bool ( cp . cpShapePointQuery ( self . _shape , p ) ) <EOL> def segment_query ( self , start , end ) : <EOL> """<STR_LIT>""" <EOL> info = cp . cpSegmentQueryInfo ( ) <EOL> info_p = ct . POINTER ( cp . cpSegmentQueryInfo ) ( info ) <EOL> r = cp . cpShapeSegmentQuery ( self . _shape , start , end , info_p ) <EOL> if bool ( r ) : <EOL> return SegmentQueryInfo ( self , start , end , info . t , info . n ) <EOL> else : <EOL> return None <EOL> class Circle ( Shape ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , body , radius , offset = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> """<STR_LIT>""" <EOL> self . _body = body <EOL> body_body = None if body is None else body . _body <EOL> if body != None : <EOL> body . _shapes . add ( self ) <EOL> self . _shape = cp . cpCircleShapeNew ( body_body , radius , offset ) <EOL> self . _shapecontents = self . _shape . contents <EOL> self . _cs = ct . cast ( self . _shape , ct . POINTER ( cp . cpCircleShape ) ) <EOL> def unsafe_set_radius ( self , r ) : <EOL> """<STR_LIT>""" <EOL> cp . cpCircleShapeSetRadius ( self . _shape , r ) <EOL> def _get_radius ( self ) : <EOL> return cp . cpCircleShapeGetRadius ( self . _shape ) <EOL> radius = property ( _get_radius , doc = """<STR_LIT>""" ) <EOL> def unsafe_set_offset ( self , o ) : <EOL> """<STR_LIT>""" <EOL> cp . cpCircleShapeSetOffset ( self . _shape , o ) <EOL> def _get_offset ( self ) : <EOL> return cp . cpCircleShapeGetOffset ( self . _shape ) <EOL> offset = property ( _get_offset , doc = """<STR_LIT>""" ) <EOL> class Segment ( Shape ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , body , a , b , radius ) : <EOL> """<STR_LIT>""" <EOL> self . _body = body <EOL> body_body = None if body is None else body . _body <EOL> if body != None : <EOL> body . _shapes . add ( self ) <EOL> self . _shape = cp . cpSegmentShapeNew ( body_body , a , b , radius ) <EOL> self . _shapecontents = self . _shape . contents <EOL> def unsafe_set_a ( self , a ) : <EOL> """<STR_LIT>""" <EOL> ct . cast ( self . _shape , ct . POINTER ( cp . cpSegmentShape ) ) . contents . a = a <EOL> def _get_a ( self ) : <EOL> return ct . cast ( self . _shape , ct . POINTER ( cp . cpSegmentShape ) ) . contents . a <EOL> a = property ( _get_a , <EOL> doc = """<STR_LIT>""" ) <EOL> def unsafe_set_b ( self , b ) : <EOL> """<STR_LIT>""" <EOL> ct . cast ( self . _shape , ct . POINTER ( cp . cpSegmentShape ) ) . contents . b = b <EOL> def _get_b ( self ) : <EOL> return ct . cast ( self . _shape , ct . POINTER ( cp . cpSegmentShape ) ) . contents . b <EOL> b = property ( _get_b , <EOL> doc = """<STR_LIT>""" ) <EOL> def unsafe_set_radius ( self , r ) : <EOL> """<STR_LIT>""" <EOL> ct . cast ( self . _shape , ct . POINTER ( cp . cpSegmentShape ) ) . contents . r = r <EOL> def _get_radius ( self ) : <EOL> return ct . cast ( self . _shape , ct . POINTER ( cp . cpSegmentShape ) ) . contents . r <EOL> radius = property ( _get_radius , <EOL> doc = """<STR_LIT>""" ) <EOL> class Poly ( Shape ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , body , vertices , offset = ( <NUM_LIT:0> , <NUM_LIT:0> ) , radius = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . _body = body <EOL> self . offset = offset <EOL> self . _set_verts ( vertices ) <EOL> body_body = None if body is None else body . _body <EOL> if body != None : <EOL> body . _shapes . add ( self ) <EOL> self . _shape = cp . cpPolyShapeNew2 ( body_body , len ( vertices ) , self . verts , offset , radius ) <EOL> self . _shapecontents = self . _shape . contents <EOL> def unsafe_set_radius ( self , radius ) : <EOL> """<STR_LIT>""" <EOL> cp . cpPolyShapeSetRadius ( self . _shape , radius ) <EOL> def _get_radius ( self ) : <EOL> return cp . cpPolyShapeGetRadius ( self . _shape ) <EOL> radius = property ( _get_radius , <EOL> doc = """<STR_LIT>""" ) <EOL> def _set_verts ( self , vertices ) : <EOL> auto_order_vertices = True <EOL> self . verts = ( Vec2d * len ( vertices ) ) <EOL> self . verts = self . verts ( Vec2d ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> i_vs = enumerate ( vertices ) <EOL> if auto_order_vertices and not u . is_clockwise ( vertices ) : <EOL> i_vs = zip ( range ( len ( vertices ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) , vertices ) <EOL> for ( i , vertex ) in i_vs : <EOL> self . verts [ i ] . x = vertex [ <NUM_LIT:0> ] <EOL> self . verts [ i ] . y = vertex [ <NUM_LIT:1> ] <EOL> @ staticmethod <EOL> def create_box ( body , size = ( <NUM_LIT:10> , <NUM_LIT:10> ) , offset = ( <NUM_LIT:0> , <NUM_LIT:0> ) , radius = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> x , y = size [ <NUM_LIT:0> ] * <NUM_LIT> , size [ <NUM_LIT:1> ] * <NUM_LIT> <EOL> vs = [ ( - x , - y ) , ( - x , y ) , ( x , y ) , ( x , - y ) ] <EOL> return Poly ( body , vs , offset , radius ) <EOL> def get_vertices ( self ) : <EOL> """<STR_LIT>""" <EOL> points = [ ] <EOL> rv = self . _body . rotation_vector <EOL> bp = self . _body . position <EOL> vs = self . verts <EOL> o = self . offset <EOL> for i in range ( len ( vs ) ) : <EOL> p = ( vs [ i ] + o ) . cpvrotate ( rv ) + bp <EOL> points . append ( Vec2d ( p ) ) <EOL> return points <EOL> def unsafe_set_vertices ( self , vertices , offset = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> """<STR_LIT>""" <EOL> self . _set_verts ( vertices ) <EOL> cp . cpPolyShapeSetVerts ( self . _shape , len ( vertices ) , self . verts , offset ) <EOL> class SegmentQueryInfo ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , shape , start , end , t , n ) : <EOL> """<STR_LIT>""" <EOL> self . _shape = shape <EOL> self . _t = t <EOL> self . _n = n <EOL> self . _start = start <EOL> self . _end = end <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . shape , self . _start , self . _end , self . t , self . n ) <EOL> shape = property ( lambda self : self . _shape <EOL> , doc = """<STR_LIT>""" ) <EOL> t = property ( lambda self : self . _t <EOL> , doc = """<STR_LIT>""" ) <EOL> n = property ( lambda self : self . _n <EOL> , doc = """<STR_LIT>""" ) <EOL> def get_hit_point ( self ) : <EOL> """<STR_LIT>""" <EOL> return Vec2d ( self . _start ) . interpolate_to ( self . _end , self . t ) <EOL> def get_hit_distance ( self ) : <EOL> """<STR_LIT>""" <EOL> return Vec2d ( self . _start ) . get_distance ( self . _end ) * self . t <EOL> def moment_for_circle ( mass , inner_radius , outer_radius , offset = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> """<STR_LIT>""" <EOL> return cp . cpMomentForCircle ( mass , inner_radius , outer_radius , offset ) <EOL> def moment_for_segment ( mass , a , b ) : <EOL> """<STR_LIT>""" <EOL> return cp . cpMomentForSegment ( mass , a , b ) <EOL> def moment_for_poly ( mass , vertices , offset = ( <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> """<STR_LIT>""" <EOL> verts = ( Vec2d * len ( vertices ) ) <EOL> verts = verts ( Vec2d ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> for ( i , vertex ) in enumerate ( vertices ) : <EOL> verts [ i ] . x = vertex [ <NUM_LIT:0> ] <EOL> verts [ i ] . y = vertex [ <NUM_LIT:1> ] <EOL> return cp . cpMomentForPoly ( mass , len ( verts ) , verts , offset ) <EOL> def moment_for_box ( mass , width , height ) : <EOL> """<STR_LIT>""" <EOL> return cp . cpMomentForBox ( mass , width , height ) <EOL> def reset_shapeid_counter ( ) : <EOL> """<STR_LIT>""" <EOL> cp . cpResetShapeIdCounter ( ) <EOL> class Contact ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , _contact ) : <EOL> """<STR_LIT>""" <EOL> self . _point = _contact . point <EOL> self . _normal = _contact . normal <EOL> self . _dist = _contact . dist <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . position , self . normal , self . distance ) <EOL> def _get_position ( self ) : <EOL> return self . _point <EOL> position = property ( _get_position , doc = """<STR_LIT>""" ) <EOL> def _get_normal ( self ) : <EOL> return self . _normal <EOL> normal = property ( _get_normal , doc = """<STR_LIT>""" ) <EOL> def _get_distance ( self ) : <EOL> return self . _dist <EOL> distance = property ( _get_distance , doc = """<STR_LIT>""" ) <EOL> class Arbiter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , _arbiter , space ) : <EOL> """<STR_LIT>""" <EOL> self . _arbiter = _arbiter <EOL> self . _arbitercontents = self . _arbiter . contents <EOL> self . _space = space <EOL> self . _contacts = None <EOL> def _get_contacts ( self ) : <EOL> point_set = cp . cpArbiterGetContactPointSet ( self . _arbiter ) <EOL> if self . _contacts is None : <EOL> self . _contacts = [ ] <EOL> for i in range ( point_set . count ) : <EOL> self . contacts . append ( Contact ( point_set . points [ i ] ) ) <EOL> return self . _contacts <EOL> contacts = property ( _get_contacts , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_shapes ( self ) : <EOL> shapeA_p = ct . POINTER ( cp . cpShape ) ( ) <EOL> shapeB_p = ct . POINTER ( cp . cpShape ) ( ) <EOL> cpffi . cpArbiterGetShapes ( self . _arbiter , shapeA_p , shapeB_p ) <EOL> a , b = self . _space . _get_shape ( shapeA_p ) , self . _space . _get_shape ( shapeB_p ) <EOL> return a , b <EOL> shapes = property ( _get_shapes , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_elasticity ( self ) : <EOL> return self . _arbiter . contents . e <EOL> def _set_elasticity ( self , elasticity ) : <EOL> self . _arbiter . contents . e = elasticity <EOL> elasticity = property ( _get_elasticity , _set_elasticity , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_friction ( self ) : <EOL> return self . _arbiter . contents . u <EOL> def _set_friction ( self , friction ) : <EOL> self . _arbiter . contents . u = friction <EOL> friction = property ( _get_friction , _set_friction , doc = """<STR_LIT>""" ) <EOL> def _get_surface_velocity ( self ) : <EOL> return self . _arbiter . contents . surface_vr <EOL> surface_velocity = property ( _get_surface_velocity , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_total_impulse ( self ) : <EOL> return cp . cpArbiterTotalImpulse ( self . _arbiter ) <EOL> total_impulse = property ( _get_total_impulse , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_total_impulse_with_friction ( self ) : <EOL> return cp . cpArbiterTotalImpulseWithFriction ( self . _arbiter ) <EOL> total_impulse_with_friction = property ( _get_total_impulse_with_friction , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_total_ke ( self ) : <EOL> return cp . cpArbiterTotalKE ( self . _arbiter ) <EOL> total_ke = property ( _get_total_ke , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_stamp ( self ) : <EOL> return self . _arbiter . contents . stamp <EOL> stamp = property ( _get_stamp , <EOL> doc = """<STR_LIT>""" ) <EOL> def _get_is_first_contact ( self ) : <EOL> return bool ( cpffi . cpArbiterIsFirstContact ( self . _arbiter ) ) <EOL> is_first_contact = property ( _get_is_first_contact , <EOL> doc = """<STR_LIT>""" ) <EOL> class BB ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args ) : <EOL> """<STR_LIT>""" <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> self . _bb = cp . cpBB ( ) <EOL> elif len ( args ) == <NUM_LIT:1> : <EOL> self . _bb = args [ <NUM_LIT:0> ] <EOL> else : <EOL> self . _bb = cpffi . cpBBNew ( args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> ] , args [ <NUM_LIT:2> ] , args [ <NUM_LIT:3> ] ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . left , self . bottom , self . right , self . top ) <EOL> def __eq__ ( self , other ) : <EOL> return self . left == other . left and self . bottom == other . bottom and self . right == other . right and self . top == other . top <EOL> def __ne__ ( self , other ) : <EOL> return not self . __eq__ ( other ) <EOL> def intersects ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return bool ( cpffi . cpBBIntersects ( self . _bb , other . _bb ) ) <EOL> def contains ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return bool ( cpffi . cpBBContainsBB ( self . _bb , other . _bb ) ) <EOL> def contains_vect ( self , v ) : <EOL> """<STR_LIT>""" <EOL> return bool ( cpffi . cpBBContainsVect ( self . _bb , v ) ) <EOL> def merge ( self , other ) : <EOL> """<STR_LIT>""" <EOL> return BB ( cpffi . cpBBMerge ( self . _bb , other . _bb ) ) <EOL> def expand ( self , v ) : <EOL> """<STR_LIT>""" <EOL> return BB ( cpffi . cpBBExpand ( self . _bb , v ) ) <EOL> left = property ( lambda self : self . _bb . l ) <EOL> bottom = property ( lambda self : self . _bb . b ) <EOL> right = property ( lambda self : self . _bb . r ) <EOL> top = property ( lambda self : self . _bb . t ) <EOL> def clamp_vect ( self , v ) : <EOL> """<STR_LIT>""" <EOL> return cpffi . cpBBClampVect ( self . _bb , v ) <EOL> def wrap_vect ( self , v ) : <EOL> """<STR_LIT>""" <EOL> return cp . cpBBWrapVect ( self . _bb , v ) </s>
