indexing description: "[ Two collided objects, giving information about collision points and direction ]" date: "$Date$" revision: "$Revision$" class EM_COLLISION [G->EM_COLLIDABLE] create make feature -- Initialization make (a_collidable, b_collidable: G; a_position: EM_VECTOR_2D; a_direction: EM_DIRECTION_2D; a_time: DOUBLE) is -- creates a collision and takes the following arguments -- 2 collidables -- the center position of both (only 2 are looked for, since in most cases there are only 2) intersections -- the tangential direction of the collision -- `a_time' is between 0 and 1, and gives the time of the collision, if a search in depth was done require a_collidable_not_void: a_collidable /= void b_collidable_not_void: b_collidable /= void time_valid: a_time >= 0 and a_time <= 1 do create collidables.make (a_collidable, b_collidable) if a_position /= Void and a_direction /= Void then set_collision_point (a_position, a_direction) end time := a_time ensure time_set: time = a_time collidable_set: collidables.first = a_collidable collidable_set: collidables.second = b_collidable collision_point_set: collision_point = a_position collision_direction_set: collision_direction = a_direction end feature -- Access contains (a_collidable: G): BOOLEAN is -- checks if a collidable is contained in this collision require a_collidable_not_void: a_collidable /= void do Result := collidables.first = a_collidable or collidables.second = a_collidable end collision_point: EM_VECTOR_2D -- the collision point (average of both intersections) collision_direction: EM_DIRECTION_2D -- the tangential direction of the collision collidables: EM_PAIR[G, G] -- both collidables time: DOUBLE -- the time at which the 2 collidables intersect the first time in a frame. -- default is 1 (the end position), if no search in depth was done. feature -- Element Change set_collision_point (a_position: EM_VECTOR_2D; a_direction: EM_DIRECTION_2D) is -- takes the following arguments -- the center position of both (only 2 are looked for, since in most cases there are only 2) intersections -- the tangential direction of the collision require a_position_not_void: a_position /= void a_direction_not_void: a_direction /= void do collision_point := a_position collision_direction := a_direction ensure collision_point_set: collision_point = a_position collision_direction_set: collision_direction = a_direction end set_collidables (a_collidable, b_collidable: G) is -- sets `collidables' require a_collidable_not_void: a_collidable /= void b_collidable_not_void: b_collidable /= void do collidables.put_first (a_collidable) collidables.put_second (b_collidable) ensure collidable_set: collidables.first = a_collidable collidable_set: collidables.second = b_collidable end invariant invariant_clause: True -- Your invariant here end