diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/model/Arc.lua')
-rw-r--r-- | Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/model/Arc.lua | 265 |
1 files changed, 133 insertions, 132 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/model/Arc.lua b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/model/Arc.lua index e007e9b59b7..997a452399f 100644 --- a/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/model/Arc.lua +++ b/Master/texmf-dist/tex/generic/pgf/graphdrawing/lua/pgf/gd/model/Arc.lua @@ -14,10 +14,10 @@ -- An arc is a light-weight object representing an arc from a vertex -- in a graph to another vertex. You may not create an |Arc| by -- yourself, which is why there is no |new| method, arc creation is --- done by the Digraph class. +-- done by the Digraph class. -- -- Every arc belongs to exactly one graph. If you want the same arc in --- another graph, you need to newly connect two vertices in the other graph. +-- another graph, you need to newly connect two vertices in the other graph. -- -- You may read the |head| and |tail| fields, but you may not write -- them. In order to store data for an arc, use |Storage| objects. @@ -28,7 +28,7 @@ -- be multiple edges between two vertices. This means, in particular, -- that an arc has no |options| field. Rather, it has several -- |optionsXxxx| functions, that will search for options in all of the --- syntactic edges that ``belong'' to an edge. +-- synactic edges that ``belong'' to an edge. -- -- In order to \emph{set} options of the edges, you can set the -- |generated_options| field of an arc (which is |nil| by default), see @@ -72,7 +72,7 @@ -- @field animations If non-nil, some animations to be passed back -- to the original syntactic edges. See the description of the -- |animations| field for |Vertex| for details on the syntax. --- @field syntactic_edges In case this arc is an arc in the syntactic +-- @field syntactic_edges In case this arc is an arc in the syntatic -- digraph (and only then), this field contains an array containing -- syntactic edges (``real'' edges in the syntactic digraph) that -- underly this arc. Otherwise, the field will be empty or |nil|. @@ -106,17 +106,15 @@ local lib = require 'pgf.gd.lib' -- If your algorithm gets confused by multiple edges, try saying -- |a:options(your_option)|. This will always give the ``most -- sensible'' choice of the option if there are multiple edges --- corresponding to the same arc. +-- corresponding to the same arc. -- -- @param option A string option like |"length"|. -- --- @return A table with the following contents: --- % +-- @return A table with the following contents: -- \begin{enumerate} --- \item It is an array of all values the option has for edges --- corresponding to |self| in the syntactic digraph. Suppose, for --- instance, you write the following: --- % +-- \item It is an array of all values the option has for edges +-- corresponding to |self| in the syntactic digraph. Suppose, for +-- instance, you write the following: --\begin{codeexample}[code only] --graph { -- tail -- [length=1] head, % multi edge 1 @@ -127,32 +125,31 @@ local lib = require 'pgf.gd.lib' -- tail -- [length=2] head, % multi edge 6 --} --\end{codeexample} --- % --- Suppose, furthermore, that |length| has been setup as an edge --- option. Now suppose that |a| is the arc from the vertex |tail| to --- the vertex |head|. Calling |a:optionsArray('length')| will --- yield the array part |{1,3,2,8,7}|. The reason for the ordering is --- as follows: First come all values |length| had for syntactic edges --- going from |self.tail| to |self.head| in the order they appear in the --- graph description. Then come all values the options has for syntactic --- edges going from |self.head| to |self.tail|. The reason for this --- slightly strange behavior is that many algorithms do not really --- care whether someone writes |a --[length=1] b| or --- |b --[length=1] a|; in both cases they would ``just'' like to know --- that the length is~|1|. --- --- \item There is field called |aligned|, which is an array storing --- the actual syntactic edge objects whose values can be found in the --- array part of the returned table. However, |aligned| contains only --- the syntactic edges pointing ``in the same direction'' as the arc, --- that is, the tail and head of the syntactic edge are the same as --- those of the arc. In the above example, this array would contain --- the edges with the comment numbers |1|, |2|, and |6|. --- --- Using the length of this array and the fact that the ``aligned'' --- values come first in the table, you can easily iterate over the --- |option|'s values of only those edges that are aligned with the arc: --- % +-- Suppose, furthermore, that |length| has been setup as an edge +-- option. Now suppose that |a| is the arc from the vertex |tail| to +-- the vertex |head|. Calling |a:optionsArray('length')| will +-- yield the array part |{1,3,2,8,7}|. The reason for the ordering is +-- as follows: First come all values |length| had for syntactic edges +-- going from |self.tail| to |self.head| in the order they appear in the graph +-- description. Then come all values the options has for syntactic +-- edges going from |self.head| to |self.tail|. The reason for this +-- slightly strange behaviour is that many algorithms do not really +-- care whether someone writes |a --[length=1] b| or +-- |b --[length=1] a|; in both cases they would ``just'' like to know +-- that the length is~|1|. +-- +-- \item There is field called |aligned|, which is an array storing +-- the actual syntactic edge objects whose values can be found in the +-- array part of the returned table. However, |aligned| contains only +-- the syntactic edges pointing ``in the same direction'' as the arc, +-- that is, the tail and head of the syntactic edge are the same as +-- those of the arc. In the above example, this array would contain +-- the edges with the comment numbers |1|, |2|, and |6|. +-- +-- Using the length of this array and the fact that the ``aligned'' +-- values come first in the table, you can easily iterate over the +-- |option|'s values of only those edges that are aligned with the arc: +-- --\begin{codeexample}[code only, tikz syntax=false] --local a = g:arc(tail.head) -- some arc --local opt = a:optionsArray('length') @@ -161,16 +158,17 @@ local lib = require 'pgf.gd.lib' -- sum = sum + opt[i] --end --\end{codeexample} --- % --- \item There is a field called |anti_aligned|, which is an array --- containing exactly the edges in the array part of the table not --- aligned with the arc. The numbering start at |1| as usual, so the --- $i$th entry of this table corresponds to the entry at position $i + --- \verb!#opt.aligned!$ of the table. --- \end{enumerate} +-- +--\item There is a field called |anti_aligned|, which is an array +-- containing exactly the edges in the array part of the table not +-- aligned with the arc. The numbering start at |1| as usual, so the +-- $i$th entry of this table corresponds to the entry at position $i + +-- \verb!#opt.aligned!$ of the table. +-- +--\end{enumerate} -- function Arc:optionsArray(option) - + local cache = self.option_cache local t = cache[option] if t then @@ -187,23 +185,23 @@ function Arc:optionsArray(option) if arc then for _,m in ipairs(arc.syntactic_edges) do if m.options[option] ~= nil then - aligned[#aligned + 1] = m + aligned[#aligned + 1] = m end end table.sort(aligned, function (a,b) return a.event.index < b.event.index end) end - + local arc = head ~= tail and s_graph:arc(head, tail) local anti_aligned = {} if arc then for _,m in ipairs(arc.syntactic_edges) do if m.options[option] ~= nil then - anti_aligned[#anti_aligned + 1] = m + anti_aligned[#anti_aligned + 1] = m end end table.sort(anti_aligned, function (a,b) return a.event.index < b.event.index end) end - + -- Now merge them together local t = { aligned = aligned, anti_aligned = anti_aligned } for i=1,#aligned do @@ -213,7 +211,7 @@ function Arc:optionsArray(option) t[#t+1] = anti_aligned[i].options[option] end cache[option] = t - + return t end @@ -223,11 +221,11 @@ end -- Returns the first option, that is, the first entry of -- |Arc:optionsArray(option)|. However, if the |only_aligned| -- parameter is set to true and there is no option with any aligned --- syntactic edge, |nil| is returned. +-- synactic edge, |nil| is returned. -- -- @param option An option -- @param only_aligned If true, only aligned syntactic edges will be --- considered. +-- considered. -- @return The first entry of the |optionsArray| function Arc:options(option, only_aligned) if only_aligned then @@ -258,7 +256,7 @@ end -- edges will be considered. -- -- @return If the option is not set for any (aligned) syntactic edges --- corresponding to |self|, |nil| is returned. If there is exactly one +-- corresponding to |self|, |nil| is returned. If there is exectly one -- edge, the value of this edge is returned. Otherwise, the result of -- repeatedly applying the |accumulator| function as described -- above. @@ -267,7 +265,6 @@ end -- |accumulator| function again. -- -- @usage Here is typical usage: --- % --\begin{codeexample}[code only, tikz syntax=false] --local total_length = a:optionsAccumulated('length', function (a,b) return a+b end) or 0 --\end{codeexample} @@ -280,7 +277,7 @@ function Arc:optionsAccumulated(option, accumulator, only_aligned) if v == nil then v = opt[1] for i=2,#aligned do - v = accumulator(v, opt[i]) + v = accumulator(v, opt[i]) end align[accumulator] = v end @@ -290,7 +287,7 @@ function Arc:optionsAccumulated(option, accumulator, only_aligned) if v == nil then v = opt[1] for i=2,#opt do - v = accumulator(v, opt[i]) + v = accumulator(v, opt[i]) end opt[accumulator] = v end @@ -304,7 +301,7 @@ end -- Compute the syntactic head and tail of an arc. For this, we have a -- look at the syntactic digraph underlying the arc. If there is at -- least once syntactic edge going from the arc's tail to the arc's --- head, the arc's tail and head are returned. Otherwise, we test +-- head, the arc's tail and head are returned. Otherweise, we test -- whether there is a syntactic edge in the other direction and, if -- so, return head and tail in reverse order. Finally, if there is no -- syntactic edge at all corresponding to the arc in either direction, @@ -341,15 +338,15 @@ function Arc:pointCloud () if a then for _,e in ipairs(a.syntactic_edges) do for _,p in ipairs(e.path) do - if type(p) == "table" then - cloud[#cloud + 1] = p - end + if type(p) == "table" then + cloud[#cloud + 1] = p + end end end end self.cached_point_cloud = cloud return cloud -end +end @@ -380,7 +377,7 @@ function Arc:eventIndex () end self.cached_event_index = e return e -end +end @@ -392,16 +389,21 @@ end -- edge involved in the arc. -- -- The priority of an edge is computed as follows: --- % +-- -- \begin{enumerate} --- \item If the option |"span priority"| is set, this number --- will be used. --- \item If the edge has the same head as the arc, we lookup the key\\ --- |"span priority " .. edge.direction|. If set, we use this value. --- \item If the edge has a different head from the arc (the arc is --- ``reversed'' with respect to the syntactic edge), we lookup the key --- |"span priority reversed " .. edge.direction|. If set, we use this value. --- \item Otherwise, we use priority 5. +-- \item If the option |"span priority"| is set, this number +-- will be used. +-- +-- \item If the edge has the same head as the arc, we lookup the key\\ +-- |"span priority " .. edge.direction|. If set, we use +-- this value. +-- +-- \item If the edge has a different head from the arc (the arc is +-- ``reversed'' with respect to the syntactic edge), we lookup the key +-- |"span priority reversed " .. edge.direction|. If set, +-- we use this value. +-- +-- \item Otherwise, we use priority 5. -- \end{enumerate} -- -- @return The priority of the arc, as described above. @@ -410,7 +412,7 @@ function Arc:spanPriority() if self.cached_span_priority then return self.cached_span_priority end - + local head = self.head local tail = self.tail local min @@ -420,8 +422,8 @@ function Arc:spanPriority() if a then for _,m in ipairs(a.syntactic_edges) do local p = - m.options["span priority"] or - lib.lookup_option("span priority " .. m.direction, m, g) + m.options["span priority"] or + lib.lookup_option("span priority " .. m.direction, m, g) min = math.min(p or 5, min or math.huge) end @@ -431,15 +433,15 @@ function Arc:spanPriority() if a then for _,m in ipairs(a.syntactic_edges) do local p = - m.options["span priority"] or - lib.lookup_option("span priority reversed " .. m.direction, m, g) - + m.options["span priority"] or + lib.lookup_option("span priority reversed " .. m.direction, m, g) + min = math.min(p or 5, min or math.huge) end end - + self.cached_span_priority = min or 5 - + return min or 5 end @@ -459,7 +461,6 @@ end -- which will replace the function in the |Path|. -- -- You use this method like this: --- % --\begin{codeexample}[code only, tikz syntax=false] --... --local arc = g:connect(s,t) @@ -484,34 +485,34 @@ function Arc:sync() local a = self.syntactic_digraph:arc(tail,head) if a and #a.syntactic_edges>0 then for _,e in ipairs(a.syntactic_edges) do - local clone = path:clone() - for i=1,#clone do - local p = clone[i] - if type(p) == "function" then - clone[i] = p(e) - if type(clone[i]) == "table" then - clone[i] = clone[i]:clone() - end - end - end - e.path = clone + local clone = path:clone() + for i=1,#clone do + local p = clone[i] + if type(p) == "function" then + clone[i] = p(e) + if type(clone[i]) == "table" then + clone[i] = clone[i]:clone() + end + end + end + e.path = clone end end local a = head ~= tail and self.syntactic_digraph:arc(head,tail) if a and #a.syntactic_edges>0 then for _,e in ipairs(a.syntactic_edges) do - local clone = path:reversed() - for i=1,#clone do - local p = clone[i] - if type(p) == "function" then - clone[i] = p(e) - if type(clone[i]) == "table" then - clone[i] = clone[i]:clone() - end - end - end - e.path = clone - end + local clone = path:reversed() + for i=1,#clone do + local p = clone[i] + if type(p) == "function" then + clone[i] = p(e) + if type(clone[i]) == "table" then + clone[i] = clone[i]:clone() + end + end + end + e.path = clone + end end end if self.generated_options then @@ -520,19 +521,19 @@ function Arc:sync() local a = self.syntactic_digraph:arc(tail,head) if a and #a.syntactic_edges>0 then for _,e in ipairs(a.syntactic_edges) do - for _,o in ipairs(self.generated_options) do - e.generated_options[#e.generated_options+1] = o - end + for _,o in ipairs(self.generated_options) do + e.generated_options[#e.generated_options+1] = o + end end end local a = head ~= tail and self.syntactic_digraph:arc(head,tail) if a and #a.syntactic_edges>0 then for _,e in ipairs(a.syntactic_edges) do - for _,o in ipairs(self.generated_options) do - e.generated_options[#e.generated_options+1] = o - end + for _,o in ipairs(self.generated_options) do + e.generated_options[#e.generated_options+1] = o + end end - end + end end if self.animations then local head = self.head @@ -540,17 +541,17 @@ function Arc:sync() local a = self.syntactic_digraph:arc(tail,head) if a and #a.syntactic_edges>0 then for _,e in ipairs(a.syntactic_edges) do - for _,o in ipairs(self.animations) do - e.animations[#e.animations+1] = o - end + for _,o in ipairs(self.animations) do + e.animations[#e.animations+1] = o + end end end local a = head ~= tail and self.syntactic_digraph:arc(head,tail) if a and #a.syntactic_edges>0 then for _,e in ipairs(a.syntactic_edges) do - for _,o in ipairs(self.animations) do - e.animations[#e.animations+1] = o - end + for _,o in ipairs(self.animations) do + e.animations[#e.animations+1] = o + end end end end @@ -571,8 +572,8 @@ end -- method to get a function that will, later on, compute the correct -- position of the anchor as needed. -- --- Here is the code you would use to create the above-mentioned path: --- % +-- Here is the code you would use to create the abovementioned path: +-- --\begin{codeexample}[code only, tikz syntax=false] --local a = g:connect(tail,head) --... @@ -584,19 +585,19 @@ end -- -- Normally, however, you will not write code as detailed as the above -- and you would just write instead of the last three lines: --- % +-- --\begin{codeexample}[code only, tikz syntax=false] --arc:setPolylinePath { Coordinate.new (10, 10) } --\end{codeexample} function Arc:tailAnchorForArcPath() return function (edge) - local a = edge.options['tail anchor'] - if a == "" then - a = "center" - end - return self.tail:anchor(a) + self.tail.pos - end + local a = edge.options['tail anchor'] + if a == "" then + a = "center" + end + return self.tail:anchor(a) + self.tail.pos + end end --- @@ -604,12 +605,12 @@ end function Arc:headAnchorForArcPath() return function (edge) - local a = edge.options['head anchor'] - if a == "" then - a = "center" - end - return self.head:anchor(a) + self.head.pos - end + local a = edge.options['head anchor'] + if a == "" then + a = "center" + end + return self.head:anchor(a) + self.head.pos + end end @@ -632,7 +633,7 @@ function Arc:setPolylinePath(coordinates) end p:appendLineto(self:headAnchorForArcPath()) - + self.path = p end |