summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-nfold/pgflibrarynfold.code.tex
blob: f593c787b420fc1f4dba983d00edeba1576016d0 (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
82
83
84
85
86
87
88
%% pgflibrarynfold.code.tex
%% Copyright 2023 Jonathan Schulz
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008-05-04 or later.
%
% This work has the LPPL maintenance status 'maintained'.
%
% The Current Maintainer of this work is Jonathan Schulz.
%
% This work consists of the files
% pgflibrarybezieroffset.code.tex, pgflibrarynfold.code.tex, pgflibraryoffsetpath.code.tex, tikz-nfold-doc.tex, tikzlibrarynfold.code.tex, tikz-nfold-doc.tex, and tikz-nfold-doc.pdf.
%
%
% A commented version of this file can be found on https://github.com/jonschz/tikz-nfold .
%


\usepgflibrary{offsetpath}


\newcount\pgf@nfold@index
\def\pgf@nfold@run@loop{%
  \pgf@nfold@index=\pgf@nfold@order%
  \pgf@nfold@run@loop@%
}

\def\pgf@nfold@run@loop@{%
  \pgf@nfold@loop@inner%
  \advance\pgf@nfold@index by -1\relax
  \ifnum\pgf@nfold@index>0\relax%
    \pgf@nfold@run@loop@%
  \fi%
}

\def\pgf@nfold@loop@inner{%
  \pgfmathsetmacro{\pgf@nfold@shift@fraction}%
    {-1+2*(\pgf@nfold@index-1)/(\pgf@nfold@order-1)}%
  \pgfmathsetmacro{\pgf@nfold@shiftamount}{\pgf@nfold@hwidth*\pgf@nfold@shift@fraction}
  \pgftransformreset%
  \parsedpath%
  \pgfsyssoftpath@flushcurrentpath%
  \pgf@up@action%
}

\def\pgf@nfold@compute@widths@from@double{
    \pgf@x=\pgflinewidth\relax%
    \pgf@y=\pgf@x\relax%
    \advance\pgf@x-\pgfinnerlinewidth\relax%
    \advance\pgf@y+\pgfinnerlinewidth\relax%
    \pgf@x=.5\pgf@x\relax%
    \pgf@y=.25\pgf@y\relax%
}

\def\pgf@nfold@render@cached@softpath{%
  \pgfscope%
    \pgf@nfold@compute@widths@from@double%
    \pgfsetlinewidth\pgf@x%
    \edef\pgf@nfold@hwidth{\the\pgf@y}%
    \pgfprocessround{\pgf@nfold@cachedpath}{\pgf@nfold@cachedpath}%
    \pgf@nfold@parsearrows%
    \pgf@nfold@parsesoftpath{\pgf@nfold@cachedpath}{\parsedpath}%
    \pgf@nfold@run@loop%
  \endpgfscope%
}


\pgfkeys{
  /pgf/nfold/.code={%
    \pgf@nfold@order=#1\relax%
    \ifnum\pgf@nfold@order<1\relax%
      \pgfutil@packageerror{tikz-nfold}{The key /pgf/nfold must take a value of at least 1, got \the\pgf@nfold@order}{}%
    \fi%
    \ifnum\pgf@nfold@order>\pgf@nfold@intersec@numcached\relax
      \ifdefined\pgfintersectionofpaths\else
        \pgf@nfold@intersectionsnotloadedtrue
      \fi
    \fi
  },
  /pgf/nfold/.default=2
}

\endinput