% 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

\tikzextset{
  arc through/.unknown/.code=\pgfkeyssetevalue{/tikz/ext/arc through/through}{\pgfkeyscurrentname},
  arc through/through/.initial={(0,0)},
  arc through/center suffix/.initial=,
  arc through/clockwise/.code=%
    \def\tikz@arcthrough@clockwise{%
      \pgfmathsubtract@{\pgfkeysvalueof{/tikz/end angle}}{360}%
      \pgfkeyssetevalue{/tikz/end angle}{+\pgfmathresult}},
  arc through/counter clockwise/.code=\let\tikz@arcthrough@clockwise\relax,
  arc through/clockwise/.value forbidden,
  arc through/counter clockwise/.value forbidden,
  arc through/counter clockwise,
  arc through/.code={% \tikzset{every arc/.try,ext/every arc to/.try,ext/arc to/.expand once=\tikzext@arcto@options@}%
    \tikzset{ext/every arc through/.try}%
    \pgfqkeys{/tikz/ext/arc through}{#1}%
    \pgfkeysgetvalue{/tikz/ext/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/ext/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}%
  }%
}

%%% Compatibility
\tikzextset{
  /tikz-ext/compat/add library={topaths.arcthrough}{pre 0.6},
  compat/topaths.arcthrough/warn/.append code=%
    \tikzextutil@compatwarning@key{topaths.arcthrough}{pre 0.6}{/tikz/arc through}{/tikz/ext/arc through},
  compat/topaths.arcthrough/pre 0.6/.append code=%
    \pgfkeysdef{/tikz/arc through}{\pgfkeysvalueof{/tikz/ext/arc through/.@cmd}##1\pgfeov},
  compat/topaths.arcthrough/\pgfkeysvalueof{/tikz/ext/compat/topaths.arcthrough}%
}
\endinput