start drawing edges
But this only draws one edge and crashes on the second.
This commit is contained in:
parent
770ab80074
commit
103cad29a0
3
0028-A
3
0028-A
|
@ -5,6 +5,9 @@ A = function(preserve_screen_top_of_cursor_node)
|
|||
for key,node in pairs(Nodes) do
|
||||
node.id = key
|
||||
compute_layout(node, node.x,node.y, Surface, preserve_screen_top_of_cursor_node)
|
||||
for _,d in ipairs(node.outgoing_edges) do
|
||||
compute_layout_for_edge(key, d)
|
||||
end
|
||||
end
|
||||
-- continue the pipeline
|
||||
B(preserve_screen_top_of_cursor_node)
|
||||
|
|
|
@ -1,33 +1,23 @@
|
|||
intersect_with_centroid = function(node, sx,sy)
|
||||
local h = node_height(Edge.source)
|
||||
local c = {
|
||||
sx=Edge.source.x + Edge.source.w/2,
|
||||
sy=Edge.source.y + h/2
|
||||
}
|
||||
if c.sx == sx then
|
||||
if sy > c.sy then
|
||||
return {sx=sx, sy=Edge.source.y + h + 10}
|
||||
else
|
||||
return {sx=sx, sy=Edge.source.y - 10}
|
||||
end
|
||||
end
|
||||
local h = node_height(node)
|
||||
local c = centroid(node)
|
||||
-- collect nearest intersection with all 4 boundaries
|
||||
local candidates = {}
|
||||
local y = y_at_x(sx,sy, c.sx,c.sy, Edge.source.x-10)
|
||||
if y and y >= Edge.source.y-10 and y < Edge.source.x+h+10 then
|
||||
table.insert(candidates, {sx=Edge.source.x-10, sy=y})
|
||||
local y = y_at_x(sx,sy, c.sx,c.sy, node.x-10)
|
||||
if y and y >= node.y-10 and y < node.x+h+10 then
|
||||
table.insert(candidates, {sx=node.x-10, sy=y})
|
||||
end
|
||||
y = y_at_x(sx,sy, c.sx,c.sy, Edge.source.x + Edge.source.w + 10)
|
||||
if y and y >= Edge.source.y-10 and y < Edge.source.x+h+10 then
|
||||
table.insert(candidates, {sx=Edge.source.x+Edge.source.w+10, sy=y})
|
||||
y = y_at_x(sx,sy, c.sx,c.sy, node.x+node.w+10)
|
||||
if y and y >= node.y-10 and y < node.x+h+10 then
|
||||
table.insert(candidates, {sx=node.x+node.w+10, sy=y})
|
||||
end
|
||||
local x = x_at_y(sx,sy, c.sx,c.sy, Edge.source.y-10)
|
||||
if x and x >= Edge.source.x-10 and x < Edge.source.x + Edge.source.w + 10 then
|
||||
table.insert(candidates, {sx=x, sy=Edge.source.y-10})
|
||||
local x = x_at_y(sx,sy, c.sx,c.sy, node.y-10)
|
||||
if x and x >= node.x-10 and x < node.x+node.w+10 then
|
||||
table.insert(candidates, {sx=x, sy=node.y-10})
|
||||
end
|
||||
x = x_at_y(sx,sy, c.sx,c.sy, Edge.source.y+h+10)
|
||||
if x and x >= Edge.source.x-10 and x < Edge.source.x + Edge.source.w + 10 then
|
||||
table.insert(candidates, {sx=x, sy=Edge.source.y+h+10})
|
||||
x = x_at_y(sx,sy, c.sx,c.sy, node.y+h+10)
|
||||
if x and x >= node.x-10 and x < node.x+node.w+10 then
|
||||
table.insert(candidates, {sx=x, sy=node.y+h+10})
|
||||
end
|
||||
if #candidates == 0 then
|
||||
-- no intersection; just return the same point
|
||||
|
@ -36,10 +26,9 @@ intersect_with_centroid = function(node, sx,sy)
|
|||
if #candidates == 1 then
|
||||
return candidates[1]
|
||||
end
|
||||
assert(#candidates == 2)
|
||||
if distance_sq(sx,sy, candidates[1].sx, candidates[1].sy) < distance_sq(sx,sy, candidates[2].sx, candidates[2].sy) then
|
||||
return candidates[1]
|
||||
else
|
||||
return candidates[2]
|
||||
end
|
||||
table.sort(candidates,
|
||||
function(a, b)
|
||||
return distance_sq(sx,sy, a.sx,a.sy) < distance_sq(sx,sy, b.sx,b.sy)
|
||||
end)
|
||||
return candidates[1]
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
centroid = function(node)
|
||||
return {
|
||||
sx=node.x + node.width/2,
|
||||
sy=node.y + node_height(node)/2
|
||||
}
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
compute_layout_for_edge = function(s, e)
|
||||
local cs = centroid(Nodes[s])
|
||||
local ce = centroid(Nodes[e])
|
||||
local s = intersect_with_centroid(Nodes[s], ce.sx,ce.sy)
|
||||
local e = intersect_with_centroid(Nodes[e], s.sx,s.sy)
|
||||
table.insert(Surface, {type='line', r=0,g=0,b=0, data={s.sx,s.sy, e.sx,e.sy}})
|
||||
end
|
Loading…
Reference in New Issue