skip reflexive or duplicate edges

This commit is contained in:
Kartik K. Agaram 2023-12-13 17:17:05 -08:00
parent 9362c8ea96
commit 3d09b0c5a4
1 changed files with 10 additions and 3 deletions

View File

@ -8,11 +8,18 @@ on.mouse_release = function(x,y, mouse_button)
if dest == nil then
local line_height = src.editor.line_height
dest = {id=next_key(), type='text', x=sx-60,y=sy-1.5*line_height, margin=0, width=120, outgoing_edges={}, incoming_edges={src.id}}
table.insert(Nodes[src.id].outgoing_edges, dest.id)
else
table.insert(dest.incoming_edges, src.id)
if src.id == dest.id then
-- avoid edge to self for now; there's no way to delete it
elseif array.find(dest.incoming_edges, src.id) then
-- no duplicate edges
else
table.insert(dest.incoming_edges, src.id)
table.insert(Nodes[src.id].outgoing_edges, dest.id)
end
end
Nodes[dest.id] = dest
table.insert(Nodes[src.id].outgoing_edges, dest.id)
Global_next_save = Current_time + 3
Edge = nil
A()
@ -29,4 +36,4 @@ on.mouse_release = function(x,y, mouse_button)
Cursor_node.show_cursor = true
edit.mouse_release(Cursor_node.editor, x,y, mouse_button)
end
end
end