indexing description: "[ A line going through several points. ]" date: "$Date$" revision: "$Revision$" class EM_POLYLINE inherit EM_MULTI_POINTED_FIGURE redefine draw, publish_mouse_event end create make_empty, make_from_array, make_from_list feature -- Drawing draw (surface: EM_SURFACE) is -- Draw `Current' onto `surface'. do if is_visible then surface.set_drawing_color (line_color) surface.set_line_width (line_width) surface.draw_polyline (Current) end end feature -- Mouse Events is_on_border_line (a_point: EM_VECTOR_2D): BOOLEAN is -- Is `a_point' on boundary line of `Current'? local px, py: DOUBLE p1x, p1y, p2x, p2y: DOUBLE lw: DOUBLE p1, p2: EM_VECTOR_2D dist, dir, p: EM_VECTOR_2D cursor: DS_LINKED_LIST_CURSOR [EM_VECTOR_2D] do if bounding_box.has (a_point) then px := a_point.x py := a_point.y lw := (line_width / 2).max (0.001) from cursor := new_cursor cursor.start p1 := cursor.item p1x := p1.x p1y := p1.y cursor.forth until cursor.after or else Result loop p2 := cursor.item p2x := p2.x p2y := p2.y -- Calculate rectangular projection on line. dir := p2 - p1 dist := dir.standard_twin dist.rotate_rectangularly p := a_point.straight_line_intersection_point (dist, p1, dir) -- Is distance inside line width if p.distance (a_point) <= lw then -- only on line segment, if invbetween points. if p1x <= p2x and then p1x - lw <= p.x and then p.x <= p2x + lw then Result := True elseif p2x - lw <= p.x and then p.x <= p1x + lw then Result := True end end p1 := p2 p1x := p2x p1y := p2y cursor.forth end end end publish_mouse_event (a_mouse_event: EM_MOUSE_EVENT) is -- Publish mouse event when `a_mouse_event' occured on `Current'. -- Only publish mouse event, if `proportional_point' lies on `Current'. do if is_on_border_line (a_mouse_event.proportional_position) then dispatch_mouse_event (a_mouse_event) a_mouse_event.set_caught (True) end end end