|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://angg.twu.net/LUA/DFSTriangle.lua.html
-- http://angg.twu.net/LUA/DFSTriangle.lua
-- (find-angg "LUA/DFSTriangle.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- dofile "DFS.lua"
DFSTriangle = Class {
type = "DFSTriangle",
from = function (dfs) return DFSTriangle { dfs = dfs } end,
__index = {
kinfo = function (dfst, k) return dfst.dfs:kinfo(k) end,
knode = function (dfst, k) return dfst:kinfo(k).node end,
kname = function (dfst, k) return dfst:kinfo(k).name end,
--
drawdiagonal = function (dfst)
local maxk = dfst.dfs:maxk()
dfst.maxk = maxk
dfst.r = Rect.rep("", maxk)
for i=1,maxk do
dfst.r[i] = dfst.r[i]:replace(i-1, dfst:kname(i))
end
return dfst
end,
--
arrownames = function (dfst, k1, k2)
local node1 = dfst.dfs:kinfo(k1).node
local node2 = dfst.dfs:kinfo(k2).node
local arrownames = dfs.arrownames[node1] and dfs.arrownames[node1][node2]
return arrownames
end,
setgridchar = function (dfst, k1, k2, c)
dfst.r[k2] = dfst.r[k2]:replace(k1-1, c)
end,
setgrid0 = function (dfst)
dfst.grid = {}
for i=1,dfst.maxk do
dfst.grid[i] = {}
for j=i+1,dfst.maxk do
dfst.grid[i][j] = {}
end
end
end,
setgrid1 = function (dfst)
for i=1,dfst.maxk do
for j=i+1,dfst.maxk do
if dfst:arrownames(i, j) then dfst:setgridchar(i, j, ">") end
end
end
end,
setgrid2 = function (dfst)
for i=1,dfst.maxk do
for j=i+1,dfst.maxk do
local c = dfst.grid[i][j].char
if c then dfst.r[j] = dfst.r[j]:replace(i-1, c) end
end
end
end,
},
}