This wasn't my original plan; I wanted to detach/reattach edges, but that seems more complicated now when I consider the possibility of detaching the source of an edge.
I think I'm not going to bother with a mechanic for deleting nodes. Just disconnect edges and repurpose them. That way the number of widges per node doesn't get worse, and I also don't have to worry about undoing deletion.
ABGMV7IIOMBXK56LS5CJPNN7JGT252FXSGFZG5I7BWARS6EL2MHQC
KDIC32VKQ4Z7UAWIJBTUNXZWKJIZ4FTGUN5TCILOLIC5LYWQZEOQC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
7UWLGLA6FAO42YN6IBEFAKMTDUY26IJAQDBHGHHH55OK2SHUIZHAC
ZQMQVMFWZIGWBRCB455IKHPTAOUYPLYCSC44NBPPET557RGVRX3AC
B3ZC44KYSYCCNVPNA7UZL6XFCD27O37PNHZ2SS45Q6V6UXHDW5IAC
FBDRJ53NJ5BWDQGU2GWZ6NEYHKCCRD7RODMIG7QQZBRFUB4HR7OAC
7OUKVXJTWEJBYNBPB2SBXJ4ADFZ7OV4SJEG4K2A3J4D7FSJAJ52QC
test_remove_value = function()
local h = {1,2,3}
table.remove_value(h, 1)
check_eq(h, {2,3}, "a")
local h = {1,2,3}
table.remove_value(h, 2)
check_eq(h, {1,3}, "b")
local h = {1,2,3}
table.remove_value(h, 3)
check_eq(h, {1,2}, "b")
local h = {1,2,3}
table.remove_value(h, 4)
check_eq(h, {1,2,3}, "b")
end
table.remove_value = function(h, val)
local i = table.find(h, val)
if i then
table.remove(h, i)
end
end
detach_edge = function(edge)
local src, dest = edge[1], edge[2]
table.remove_value(Nodes[src].outgoing_edges, dest)
table.remove_value(Nodes[dest].incoming_edges, src)
end
on_edge = function(sx,sy)
-- check if mouse is on the border of a node and also on an edge to another node.
-- reading from Surface; I'm going to regret this.
for _,shape in ipairs(Surface) do
if shape.type == 'line' then
if shape.keys then
-- it's an edge; assuming keys are in a specific, brittle order
if distance_sq(sx,sy, shape.data[1], shape.data[2]) < 5*5 then
return shape.keys
end
if distance_sq(sx,sy, shape.data[3], shape.data[4]) < 5*5 then
return shape.keys
end
end
end
end
end