% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
\unless\ifcsname tikzextset\endcsname
  \input tikzext-util.tex
\fi
\usepgflibrary{ext.transformations.mirror}
\tikzextset{
  mirror/.code={%
    \pgfutil@in@{--}{#1}%
    \ifpgfutil@in@
      \tikzext@trans@mirror#1\tikz@stop
    \else
      \tikz@addtransform{\tikz@scan@one@point\pgfqtransformmirror#1\relax}%
    \fi},
  ymirror/.code={\pgfutil@ifnextchar(\tikzext@trans@ymirror@coordinate\tikzext@trans@ymirror@simple#1\tikz@stop},
  xmirror/.code={\pgfutil@ifnextchar(\tikzext@trans@xmirror@coordinate\tikzext@trans@xmirror@simple#1\tikz@stop},
  mirror x/.code={%
    \pgfextract@process\tikz@temp{\tikz@scan@one@point\pgfutil@firstofone#1\relax}%
    \edef\tikz@marshal{%
      \noexpand\tikz@addtransform{%
        \noexpand\pgfexttransformmirror
          {\expandafter\noexpand\tikz@temp}
          {\noexpand\pgfpointadd{\expandafter\noexpand\tikz@temp}
                                {\noexpand\pgfqpointxy{0}{1}}}}}%
    \tikz@marshal
  },
  mirror y/.code={%
    \pgfextract@process\tikz@temp{\tikz@scan@one@point\pgfutil@firstofone#1\relax}%
    \edef\tikz@marshal{%
    \noexpand\tikz@addtransform{%
      \noexpand\pgfexttransformmirror
        {\expandafter\noexpand\tikz@temp}
        {\noexpand\pgfpointadd{\expandafter\noexpand\tikz@temp}
                              {\noexpand\pgfqpointxy{1}{0}}}}}%
    \tikz@marshal
  },
  mirror/.value required,
  ymirror/.default=+0pt,
  xmirror/.default=+0pt,
  mirror x/.default={(0,0)},
  mirror y/.default={(0,0)}%
}
\def\tikzext@trans@mirror#1--#2\tikz@stop{%
  \tikz@addtransform{%
    \pgfexttransformmirror{\tikz@scan@one@point\pgfutil@firstofone#1\relax}
                          {\tikz@scan@one@point\pgfutil@firstofone#2\relax}}}
\def\tikzext@trans@xmirror@simple#1\tikz@stop{\tikz@addtransform{\pgfexttransformxmirror{#1}}}
\def\tikzext@trans@ymirror@simple#1\tikz@stop{\tikz@addtransform{\pgfexttransformymirror{#1}}}
\def\tikzext@trans@xmirror@coordinate#1\tikz@stop{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef\tikz@marshal{%
    \noexpand\tikz@addtransform{%
      \noexpand\pgfexttransformxmirror{+\the\pgf@x}%
    }%
  }%
  \tikz@marshal
}
\def\tikzext@trans@ymirror@coordinate#1\tikz@stop{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef\tikz@marshal{%
    \noexpand\tikz@addtransform{%
      \noexpand\pgfexttransformymirror{+\the\pgf@y}%
    }%
  }%
  \tikz@marshal
}

\tikzextset{
  Mirror/.code={%
    \pgfutil@in@{--}{#1}%
    \ifpgfutil@in@
      \tikzext@trans@Mirror#1\tikz@stop
    \else
      \tikz@addtransform{\tikz@scan@one@point\pgfqtransformMirror#1\relax}%
    \fi},
  yMirror/.code={\pgfutil@ifnextchar(\tikzext@trans@yMirror@coordinate\tikzext@trans@yMirror@simple#1\tikz@stop},
  xMirror/.code={\pgfutil@ifnextchar(\tikzext@trans@xMirror@coordinate\tikzext@trans@xMirror@simple#1\tikz@stop},
  Mirror x/.code={%
    \pgfextract@process\tikz@temp{\tikz@scan@one@point\pgfutil@firstofone#1\relax}%
    \edef\tikz@marshal{%
      \noexpand\tikz@addtransform{%
        \noexpand\pgfexttransformMirror
          {\expandafter\noexpand\tikz@temp}
          {\noexpand\pgfpointadd{\expandafter\noexpand\tikz@temp}
                                {\noexpand\pgfqpointxy{0}{1}}}}}%
    \tikz@marshal
  },
  Mirror y/.code={%
    \pgfextract@process\tikz@temp{\tikz@scan@one@point\pgfutil@firstofone#1\relax}%
    \edef\tikz@marshal{%
    \noexpand\tikz@addtransform{%
      \noexpand\pgfexttransformMirror
        {\expandafter\noexpand\tikz@temp}
        {\noexpand\pgfpointadd{\expandafter\noexpand\tikz@temp}
                              {\noexpand\pgfqpointxy{1}{0}}}}}%
    \tikz@marshal
  },
  Mirror/.value required,
  yMirror/.default=+0pt,
  xMirror/.default=+0pt,
  Mirror x/.default={(0,0)},
  Mirror y/.default={(0,0)}%
}
\def\tikzext@trans@Mirror#1--#2\tikz@stop{%
  \tikz@addtransform{%
    \pgfexttransformMirror{\tikz@scan@one@point\pgfutil@firstofone#1\relax}
                          {\tikz@scan@one@point\pgfutil@firstofone#2\relax}}}
\def\tikzext@trans@xMirror@simple#1\tikz@stop{\tikz@addtransform{\pgfexttransformxMirror{#1}}}
\def\tikzext@trans@yMirror@simple#1\tikz@stop{\tikz@addtransform{\pgfexttransformyMirror{#1}}}
\def\tikzext@trans@xMirror@coordinate#1\tikz@stop{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef\tikz@marshal{%
    \noexpand\tikz@addtransform{%
      \noexpand\pgfexttransformxMirror{+\the\pgf@x}%
    }%
  }%
  \tikz@marshal
}
\def\tikzext@trans@yMirror@coordinate#1\tikz@stop{%
  \tikz@scan@one@point\pgfutil@firstofone#1\relax
  \edef\tikz@marshal{%
    \noexpand\tikz@addtransform{%
      \noexpand\pgfexttransformyMirror{+\the\pgf@y}%
    }%
  }%
  \tikz@marshal
}

%%% Compatibility
\tikzextset{
  compat/transformations.mirror/warn/.append code=%
    \pgfkeyssetvalue{/tikz/ext/compat/transformations.mirror@}{3}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/xmirror} {/tikz/ext/xmirror}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/ymirror} {/tikz/ext/ymirror}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/mirror x}{/tikz/ext/mirror x}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/mirror y}{/tikz/ext/mirror y}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/mirror}  {/tikz/ext/mirror}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/xMirror} {/tikz/ext/xMirror}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/yMirror} {/tikz/ext/yMirror}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/Mirror x}{/tikz/ext/Mirror x}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/Mirror y}{/tikz/ext/Mirror y}%
    \tikzextutil@compatwarning@key{transformations.mirror}{pre 0.6}{/tikz/Mirror}  {/tikz/ext/Mirror},
  compat/transformations.mirror/pre 0.6/.append code=%
    \pgfkeyssetvalue{/tikz/ext/compat/transformations.mirror@}{2}%
    \pgfkeysdef{/tikz/xmirror} {\pgfkeysvalueof{/tikz/ext/xmirror/.@cmd}##1\pgfeov}%
    \pgfkeysdef{/tikz/ymirror} {\pgfkeysvalueof{/tikz/ext/ymirror/.@cmd}##1\pgfeov}%
    \pgfkeysdef{/tikz/mirror x}{\pgfkeysvalueof{/tikz/ext/mirror x/.@cmd}##1\pgfeov}%  
    \pgfkeysdef{/tikz/mirror y}{\pgfkeysvalueof{/tikz/ext/mirror y/.@cmd}##1\pgfeov}%  
    \pgfkeysdef{/tikz/mirror}  {\pgfkeysvalueof{/tikz/ext/mirror/.@cmd}##1\pgfeov}%
    \pgfkeysdef{/tikz/xMirror} {\pgfkeysvalueof{/tikz/ext/xMirror/.@cmd}##1\pgfeov}%
    \pgfkeysdef{/tikz/yMirror} {\pgfkeysvalueof{/tikz/ext/yMirror/.@cmd}##1\pgfeov}%
    \pgfkeysdef{/tikz/Mirror x}{\pgfkeysvalueof{/tikz/ext/Mirror x/.@cmd}##1\pgfeov}%  
    \pgfkeysdef{/tikz/Mirror y}{\pgfkeysvalueof{/tikz/ext/Mirror y/.@cmd}##1\pgfeov}%  
    \pgfkeysdef{/tikz/Mirror}  {\pgfkeysvalueof{/tikz/ext/Mirror/.@cmd}##1\pgfeov},
  compat/transformations.mirror/0.6/.append code=\pgfkeyssetvalue{/tikz/ext/compat/transformations.mirror@}{1},
  compat/transformations.mirror/newest/.append code=\pgfkeyssetvalue{/tikz/ext/compat/transformations.mirror@}{0},
  compat/transformations.mirror/\pgfkeysvalueof{/tikz/ext/compat/transformations.mirror}
}
\endinput