% 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.
%
\def\pgftransformxmirror#1{
  \pgfmathparse{#1}%
  \ifpgfmathunitsdeclared
    \pgf@xa\pgfmathresult pt\relax
    \multiply\pgf@xa2 
    \pgftransformcm{-1}{0}{0}{1}{\pgfqpoint{\pgf@xa}{0pt}}%
  \else
    \pgftransformmirror{\pgfqpointxy{\pgfmathresult}{0}}{\pgfpointadd{\pgfqpointxy{\pgfmathresult}{0}}{\pgfqpointxy{0}{1}}}%
  \fi
}
\def\pgftransformymirror#1{
  \pgfmathparse{#1}%
  \ifpgfmathunitsdeclared
    \pgf@ya\pgfmathresult pt\relax
    \multiply\pgf@ya2
    \pgftransformcm{1}{0}{0}{-1}{\pgfqpoint{0pt}{\pgf@ya}}%
  \else
    \edef\pgf@marshal{\noexpand\pgftransformmirror{\noexpand\pgfqpointxy{0}{\pgfmathresult}}%
                                                  {\noexpand\pgfpointadd{\noexpand\pgfqpointxy{0}{\pgfmathresult}}{\noexpand\pgfqpointxy{1}{0}}}}%
    \pgf@marshal
  \fi}
\def\pgftransformmirror#1#2{%
  \pgfextract@process\pgf@tempa{#1}%
  \pgfpointnormalised{\pgfpointdiff{\pgf@tempa}{#2}}%
  \pgf@xa=\pgf@sys@tonumber\pgf@y\pgf@x
  \pgf@xb=\pgf@sys@tonumber\pgf@x\pgf@x
  \pgf@yb=\pgf@sys@tonumber\pgf@y\pgf@y
  \multiply\pgf@xa2
  \pgf@xc=-\pgf@yb\advance\pgf@xc\pgf@xb
  \pgf@yc=-\pgf@xb\advance\pgf@yc\pgf@yb
  \edef\pgf@temp{{\the\pgf@xc}{+\the\pgf@xa}{+\the\pgf@xa}{+\the\pgf@yc}}%
  \expandafter\pgf@transformcm\pgf@temp{\pgf@tempa}%
  \pgftransformshift{\pgfpointscale{-1}{\pgf@tempa}}%
}

\def\pgfqtransformmirror#1{%
  \pgfpointnormalised{#1}%
  \pgf@xa=\pgf@sys@tonumber\pgf@y\pgf@x
  \pgf@xb=\pgf@sys@tonumber\pgf@x\pgf@x
  \pgf@yb=\pgf@sys@tonumber\pgf@y\pgf@y
  \multiply\pgf@xa2
  \pgf@xc=-\pgf@yb\advance\pgf@xc\pgf@xb
  \pgf@yc=-\pgf@xb\advance\pgf@yc\pgf@yb
  \edef\pgf@temp{{\the\pgf@xc}{+\the\pgf@xa}{+\the\pgf@xa}{+\the\pgf@yc}}%
  \expandafter\pgf@transformcm\pgf@temp{\pgfpointorigin}%
}

% Using existant transformation (shift, rotate, yscale=-1, rotate back, shift back)
\def\pgftransformxMirror#1{
  \pgfmathparse{#1}%
  \ifpgfmathunitsdeclared
    \pgf@xa\pgfmathresult pt\relax
    \multiply\pgf@xa2 
    \pgftransformcm{-1}{0}{0}{1}{\pgfqpoint{\pgf@xa}{0pt}}%
  \else
    \pgftransformMirror{\pgfqpointxy{\pgfmathresult}{0}}{\pgfpointadd{\pgfqpointxy{\pgfmathresult}{0}}{\pgfqpointxy{0}{1}}}%
  \fi
}
\def\pgftransformyMirror#1{
  \pgfmathparse{#1}%
  \ifpgfmathunitsdeclared
    \pgf@ya\pgfmathresult pt\relax
    \multiply\pgf@ya2
    \pgftransformcm{1}{0}{0}{-1}{\pgfqpoint{0pt}{\pgf@ya}}%
  \else
    \edef\pgf@marshal{\noexpand\pgftransformMirror{\noexpand\pgfqpointxy{0}{\pgfmathresult}}%
                                                  {\noexpand\pgfpointadd{\noexpand\pgfqpointxy{0}{\pgfmathresult}}{\noexpand\pgfqpointxy{1}{0}}}}%
    \pgf@marshal
  \fi}

\def\pgftransformMirror#1#2{%
  \pgfextract@process\pgf@tempa{#1}%
  \pgfmathanglebetweenpoints{\pgf@tempa}{#2}%
  \let\pgf@temp\pgfmathresult
  \pgftransformshift{\pgf@tempa}%
  \pgftransformrotate{\pgf@temp}%
  \pgftransformyscale{-1}%
  \pgftransformrotate{-\pgf@temp}%
  \pgftransformshift{\pgfqpointscale{-1}{\pgf@tempa}}%
}

\def\pgfqtransformMirror#1{%
  \pgfmathanglebetweenpoints{\pgfpointorigin}{#1}%
  \let\pgf@temp\pgfmathresult
  \pgftransformrotate{\pgf@temp}%
  \pgftransformyscale{-1}%
  \pgftransformrotate{-\pgf@temp}%
}
\endinput