summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarylindenmayersystems.code.tex
blob: 6763c733e9e05fe8df1e3939a4830f241d93ad1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
% Copyright 2018 by Mark Wibrow
%
% This file may be distributed and/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 details.

\usepgflibrary{lindenmayersystems}%

\def\tikz@@lsystem-system{%
    \pgfutil@ifnextchar[{\tikz@lsystem@options}{\tikz@lsystem@options[]}}%

\def\tikz@lsystem indenmayer system{%
    \pgfutil@ifnextchar[{\tikz@lsystem@options}{\tikz@lsystem@options[]}}%

\def\tikz@lsystem@options[#1]{%
    \tikzset{#1}%
    \ifx\tikz@lsystem@rules\pgfutil@empty%
    \else%
        \tikz@lsystem@declare%
        \def\tikz@lsystem@name{tikz@temp}%
    \fi%
    \ifx\tikz@lsystem@anchor\pgfutil@empty%
        \pgfpathmoveto{\pgfqpoint{\tikz@lastxsaved}{\tikz@lastysaved}}%
        \pgflindenmayersystem{\tikz@lsystem@name}{\tikz@lsystem@axiom}{\tikz@lsystem@order}%
    \else%
        \pgfextract@process\tikz@lsystem@pos{\pgfqpoint{\tikz@lastxsaved}{\tikz@lastysaved}}%
        \setbox\pgfnodeparttextbox=\hbox{%
            \pgfinterruptpicture%
            \pgfpicture%
                \pgfpathmoveto{\pgfpointorigin}%
                \pgflindenmayersystem{\tikz@lsystem@name}{\tikz@lsystem@axiom}{\tikz@lsystem@order}%
                \begingroup%
                    \tikz@finish%
            \endpgfpicture%
            \endpgfinterruptpicture%
        }%
        {%
            \pgftransformshift{\tikz@lsystem@pos}%
            \tikzset{inner sep=0pt, outer sep=0pt, minimum size=0pt}%
            \pgfmultipartnode{rectangle}{\tikz@lsystem@anchor}{lindenmayer system}{\pgfusepath{discard}}%
        }%
    \fi%
    \tikz@scan@next@command}%

\tikzset{%
    lindenmayer system/.style={/pgf/lindenmayer system/.cd, #1,/tikz/.cd},
    l-system/.style={lindenmayer system={#1}},
}%
\pgfkeys{/pgf/lindenmayer system/.cd,
    name/.code=\edef\tikz@lsystem@name{#1}\let\tikz@lsystem@rules=\pgfutil@empty,%
    axiom/.store in=\tikz@lsystem@axiom,%
    order/.store in=\tikz@lsystem@order,
    .unknown/.code={%
        \pgfutil@ifundefined{pgf@lsystem@\pgfkeyscurrentname}{%
            \pgfkeys{/errors/unknown key={/pgf/lindenmayer system/\pgfkeyscurrentname}{#1}}%
            \let\tikz@lsystem@name=\pgfutil@empty%
        }%
        {\edef\tikz@lsystem@name{\pgfkeyscurrentname}}
    },%
    anchor/.store in=\tikz@lsystem@anchor,%
    rule set/.store in=\tikz@lsystem@rules
}%
\let\tikz@lsystem@anchor=\pgfutil@empty%
\let\tikz@lsystem@rules=\pgfutil@empty%

\def\tikz@lsystem@declare{%
    \expandafter\let\csname pgf@lsystem@tikz@temp\endcsname=\relax%
    \pgfdeclarelindenmayersystem{tikz@temp}{%
        \expandafter\tikz@lsystem@parse@rules\tikz@lsystem@rules,\tikz@stop,%
    }%
}%
\def\tikz@lsystem@parse@rules#1,{%
    \ifx#1\tikz@stop%
    \else%
        \rule{#1}%
        \expandafter\tikz@lsystem@parse@rules%
    \fi%
}%