%% tikzlibrarynfold.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{nfold}
\usetikzlibrary{arrows.meta}

\tikzset{
  nfold/.code={
    \edef\pgf@tmp{\noexpand\pgfkeys{/pgf/nfold=#1}}
    \expandafter\expandafter\expandafter\def%
      \expandafter\expandafter\expandafter\tikz@double@setup%
      \expandafter\expandafter\expandafter{\expandafter\tikz@double@setup\pgf@tmp}
  },
  nfold/.default=2,
  scaling nfold/.code={%
    \pgfscope%
      \tikz@double@setup
      \pgf@nfold@compute@widths@from@double
      \pgf@y=2\pgf@y
      \c@pgf@counta=#1
      \advance\c@pgf@counta by -1\relax
      \global\pgf@y=\c@pgf@counta\pgf@y
    \endpgfscope
    \tikzset{
      double distance between line centers=\pgf@y,
      nfold=#1
    }
  },
  scaling nfold/.default=2,
  commutative diagrams/scaling nfold/.code={
    \pgfscope%
      \tikz@double@setup
      \pgf@nfold@compute@widths@from@double
      \c@pgf@counta=#1
      \advance\c@pgf@counta by -1\relax
      \pgf@ya=\c@pgf@counta\pgf@y
      \advance\c@pgf@counta by -1\relax
      \pgf@xa=\c@pgf@counta\pgf@y
      \advance\pgf@xa by .5\pgf@x
      \global\pgf@x=\pgf@xa
      \global\pgf@y=2\pgf@ya
    \endpgfscope
    \tikzset{
      commutative diagrams/every label/.append style/.expanded={outer sep=\the\pgf@x},
      double distance between line centers=\pgf@y,
      nfold=#1
    }
  },
  commutative diagrams/scaling nfold/.default=2
}

\endinput
