% 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.
%

\pgfqkeys{/tikz/arc through}{
  .unknown/.code=\pgfkeyssetevalue{/tikz/arc through/through}{\pgfkeyscurrentname},
  through/.initial={(0,0)},
  center suffix/.initial=,
  clockwise/.code=%
    \def\tikz@arcthrough@clockwise{%
      \pgfmathsubtract@{\pgfkeysvalueof{/tikz/end angle}}{360}%
      \pgfkeyssetevalue{/tikz/end angle}{+\pgfmathresult}},
  counter clockwise/.code=\let\tikz@arcthrough@clockwise\relax,
  clockwise/.value forbidden, counter clockwise/.value forbidden, counter clockwise}
\tikzset{
  arc through/.code={%
    \tikzset{every arc through/.try}%
    \pgfqkeys{/tikz/arc through}{#1}%
    \pgfkeysgetvalue{/tikz/arc through/through}\tikz@temp
    \pgfextract@process\pgf@tostart{\tikz@scan@one@point\pgfutil@firstofone(\tikztostart)\relax}%
    \expandafter\pgfextract@process\expandafter\pgf@tothrough\expandafter
      {\expandafter\tikz@scan@one@point\expandafter\pgfutil@firstofone\tikz@temp\relax}%
    \pgfextract@process\pgf@totarget{\tikz@scan@one@point\pgfutil@firstofone(\tikztotarget)\relax}%
    \pgfextract@process\pgf@topointMidA{\pgfpointlineattime{.5}{\pgf@tostart}{\pgf@tothrough}}%
    \pgfextract@process\pgf@topointMidB{\pgfpointlineattime{.5}{\pgf@totarget}{\pgf@tothrough}}%
    \pgfextract@process\pgf@tocenter{%
      \pgfpointintersectionoflines
        {\pgf@topointMidA}{\pgfmathrotatepointaround{\pgf@tothrough}{\pgf@topointMidA}{90}}%
        {\pgf@topointMidB}{\pgfmathrotatepointaround{\pgf@tothrough}{\pgf@topointMidB}{90}}}%
    \pgfcoordinate{arc through center\pgfkeysvalueof{/tikz/arc through/center suffix}}{\pgf@tocenter}%
    \pgfpointdiff{\pgf@tocenter}{\pgf@tostart}%
    \pgfmathveclen@{\pgfmath@tonumber\pgf@x}{\pgfmath@tonumber\pgf@y}%
    \pgfkeyssetevalue{/tikz/x radius}{+\pgfmathresult pt}%
    \pgfkeyssetevalue{/tikz/y radius}{+\pgfmathresult pt}%
    \pgfmathanglebetweenpoints{\pgf@tocenter}{\pgf@totarget}%
    \pgfkeyssetevalue{/tikz/end angle}{+\pgfmathresult}%
    \pgfmathanglebetweenpoints{\pgf@tocenter}{\pgf@tostart}%
    \ifdim\pgfmathresult pt>\pgfkeysvalueof{/tikz/end angle}pt\relax
      \pgfmathsubtract@{\pgfmathresult}{360}%
    \fi
    \pgfkeyssetevalue{/tikz/start angle}{+\pgfmathresult}%
    \tikz@arcthrough@clockwise
    \pgfkeyslet{/tikz/delta angle}\pgfutil@empty
    \def\tikz@to@path{arc[]\tikztonodes}%
  }%
}
