indexing description: "[ Representation of a circle ]" date: "$Date$" revision: "$Revision$" class CIRCLE inherit OBJECT undefine copy, is_equal, default_create redefine set_true_x_y end EM_CIRCLE create make_obj feature -- Access make_obj (a_center: EM_VECTOR_2D; a_radius: DOUBLE; a_scene: SCENE) is -- Make circle with `a_center' and `a_radius'. require a_center_not_void: a_center /= Void a_scene_not_void: a_scene /= Void a_radius_is_positiive: a_radius > 0 do make (a_center, a_radius) true_x := a_center.x true_y := a_center.y x := true_x.rounded y := true_y.rounded true_radius := a_radius create collidable.make (center, radius) scene := a_scene scene.collision_detector.add (current) collidable.set_holder (current) -- set vertexes create resizer.make (create {EM_VECTOR_2D}.make (0,0), current) create center_vertex.make (create {EM_VECTOR_2D}.make (true_x, true_y), current) set_changed ensure scene_set: scene = a_scene end collidable: EM_CIRCLE_COLLIDABLE -- returns a collidable circle resizer: CIRCLE_RESIZE_VERTEX -- the screen position of the resizer. center_vertex: CIRCLE_CENTER_VERTEX -- screen pos of the center true_radius: DOUBLE -- backed up radius vertex_list: DS_LINKED_LIST [VERTEX] is -- a list of vertexes that the object has do Create Result.make Result.force_last (resizer) Result.force_last (center_vertex) end feature -- Element Change move_by (an_x, a_y: DOUBLE) is -- sets `x' and `y'. do x := (center.x + an_x / scene.scale).rounded y := (center.y + a_y / scene.scale).rounded center.set_x (x.to_double) center.set_y (y.to_double) end set_true_radius (r: DOUBLE) is -- sets `true_radius' do radius := r true_radius := r set_changed end set_true_x_y (an_x, a_y: DOUBLE) is -- sets `true_x' and `true_y' do true_x := an_x true_y := a_y x := true_x.rounded y := true_y.rounded center.set_x (true_x) center.set_y (true_y) set_changed end feature -- Computation set_changed is -- generate `collidable' and update vertexes local v: EM_VECTOR_2D do -- update vertices v := scene.screen_position_from_coordinates (center.x, center.y) center_vertex.set_vector (v) v.set_x (v.x + radius * scene.scale) v.set_y (center_vertex.vector.y) resizer.set_vector (v) end set_vertexes_updated is -- update state from vertexes local v, center_movement: EM_VECTOR_2D do -- update from center_vertex v := scene.coordinates_from_screen_position (center_vertex.vector.x, center_vertex.vector.y) center_movement := v - center center := v x := center.x.rounded y := center.y.rounded radius := scene.coordinates_from_screen_position (resizer.vector.x + center_movement.x * scene.scale, center_vertex.vector.y).distance (center) -- set_changed set_changed end recreate_collidable is -- recreates `collidable' do collidable.set_center (create {EM_VECTOR_2D}.make (true_x, true_y)) collidable.set_radius (radius) end end