summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-ext/tikzlibrarytopaths.arcthrough.code.tex
blob: d90a2edc787173259dc246d155c1835e35994581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% 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}%
  }%
}