summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/interface/InterfaceToC.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-02-27 00:01:50 +0000
committerKarl Berry <karl@freefriends.org>2014-02-27 00:01:50 +0000
commit90ae413a94da014dbf7a6a8ab584f7c668483a5a (patch)
tree4e0528a2b2fb2004988e7fc804ea2f1354f1f5d5 /Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/interface/InterfaceToC.lua
parent800cc56380d1edfe567a6a66bef13e8950eb2b0c (diff)
pgf 3.0.0
git-svn-id: svn://tug.org/texlive/trunk@33057 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/interface/InterfaceToC.lua')
-rw-r--r--Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/interface/InterfaceToC.lua77
1 files changed, 77 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/interface/InterfaceToC.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/interface/InterfaceToC.lua
new file mode 100644
index 00000000000..5b220f318bc
--- /dev/null
+++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/interface/InterfaceToC.lua
@@ -0,0 +1,77 @@
+-- Copyright 2012 by Till Tantau
+--
+-- This file may be distributed an/or modified
+--
+-- 1. under the LaTeX Project Public License and/or
+-- 2. under the GNU Public License
+--
+-- See the file doc/generic/pgf/licenses/LICENSE for more information
+
+-- @release $Header: /cvsroot/pgf/pgf/generic/pgf/graphdrawing/lua/pgf/gd/interface/InterfaceToC.lua,v 1.6 2013/05/23 20:01:27 tantau Exp $
+
+
+---
+-- This table contains functions that are used (on the Lua side) to
+-- prepare a graph for use in C and, vice versa, to translate back the
+-- results of C to Lua.
+
+local InterfaceToC = {}
+
+-- Imports
+
+local lib = require "pgf.gd.lib"
+
+
+---
+-- This function is called by |declare| for ``algorithm
+-- keys'' where the algorithm is not written in Lua, but rather in the
+-- programming language C. You do not call this function yourself;
+-- |InterfaceFromC.h| will do it for you. Nevertheless, if you
+-- provide a table to |declare| with the field
+-- |algorithm_written_in_c| set, the following happens: The table's
+-- |algorithm| field is set to an algorithm class object whose |run|
+-- method calls the function passed via the
+-- |algorithm_written_in_c| field. It will be called with the
+-- following parameters (in that order):
+-- \begin{enumerate}
+-- \item The to-be-laid out digraph. This will not be the whole layout
+-- graph (syntactic digraph) if preprocessing like decomposition into
+-- connected components is used.
+-- \item An array of the digraph's vertices, but with the table part
+-- hashing vertex objects to their indices in the array part.
+-- \item An array of the syntactic edges of the digraph. Like the
+-- array, the table part will hash back the indices of the edge objects.
+-- \item The algorithm object.
+-- \end{enumerate}
+--
+-- @param t The table originally passed to |declare|.
+
+function InterfaceToC.declare_algorithm_written_in_c (t)
+ t.algorithm = {
+ run = function (self)
+ local back_table = lib.icopy(self.ugraph.vertices)
+ for i,v in ipairs(self.ugraph.vertices) do
+ back_table[v] = i
+ end
+ local edges = {}
+ for _,a in ipairs(self.ugraph.arcs) do
+ local b = self.layout_graph:arc(a.tail,a.head)
+ if b then
+ lib.icopy(b.syntactic_edges, edges)
+ end
+ end
+ for i=1,#edges do
+ edges[edges[i]] = i
+ end
+ collectgarbage("stop") -- BUG! Remove this when everything is linked against a SINGLE Lua lib at runtime
+ t.algorithm_written_in_c (self.digraph, back_table, edges, self)
+ collectgarbage("restart") -- Remove also!
+ end
+ }
+end
+
+
+
+-- Done
+
+return InterfaceToC \ No newline at end of file