| 1 |
% Copyright 2022 by Qrrbrbirlbel |
| 2 |
% |
| 3 |
% This file may be distributed and/or modified |
| 4 |
% |
| 5 |
% 1. under the LaTeX Project Public License and/or |
| 6 |
% 2. under the GNU Free Documentation License. |
| 7 |
% |
| 8 |
\usepgfkeyslibrary{ext.pgfkeys-plus}% |
| 9 |
|
| 10 |
%% full arc |
| 11 |
%% https://tex.stackexchange.com/a/144297/16595 |
| 12 |
%% The postfix operator R is added to PGFmath, |
| 13 |
%% it allows the use of angular segments. |
| 14 |
%% full arc = 10 makes it so that |
| 15 |
%% 1R = 36° |
| 16 |
%% 2R = 72° |
| 17 |
%% … |
| 18 |
%% 10R = 360° |
| 19 |
%% Calling the full arc key with an empty value |
| 20 |
%% makes 1R = 1° |
| 21 |
\pgfkeyslet{/pgf/ext/full arc}\pgfutil@empty |
| 22 |
\pgfextset{ |
| 23 |
full arc/.code=% |
| 24 |
\edef\pgf@temp{#1}% |
| 25 |
\ifx\pgfutil@empty\pgf@temp |
| 26 |
\pgfkeyslet{/pgf/ext/full arc}\pgfutil@empty |
| 27 |
\else |
| 28 |
\pgfmathdivide{360}{#1}% |
| 29 |
\pgfkeyslet{/pgf/ext/full arc}\pgfmathresult |
| 30 |
\fi |
| 31 |
} |
| 32 |
\pgfmathdeclareoperator{R}{extfullarc}{1}{postfix}{950} |
| 33 |
\pgfmathdeclarefunction{extfullarc}{1}{% |
| 34 |
\begingroup |
| 35 |
\pgfmath@x=#1pt\relax |
| 36 |
\expandafter\ifx\csname pgfk@/pgf/ext/full arc\endcsname\pgfutil@empty |
| 37 |
\else |
| 38 |
\pgfmath@x\csname pgfk@/pgf/ext/full arc\endcsname\pgfmath@x |
| 39 |
\fi |
| 40 |
\pgfmath@returnone\pgfmath@x |
| 41 |
\endgroup |
| 42 |
} |
| 43 |
|
| 44 |
\unless\ifcsname iftikzext@pgffor@nolist\endcsname |
| 45 |
\input pgffor-ext.code.tex |
| 46 |
\fi |
| 47 |
|
| 48 |
%% PGFmath |
| 49 |
%% strrepeat("x", 5) = "xxxxx" |
| 50 |
\pgfmathdeclarefunction{extstrrepeat}{2}{% |
| 51 |
\begingroup\pgfmathint{#2}\pgfmath@count\pgfmathresult |
| 52 |
\let\pgfmathresult\pgfutil@empty |
| 53 |
\pgfutil@loop\ifnum\pgfmath@count>0\relax |
| 54 |
\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult#1}% |
| 55 |
\advance\pgfmath@count-1\relax |
| 56 |
\pgfutil@repeat\pgfmath@smuggleone\pgfmathresult\endgroup} |
| 57 |
%% isInString("foo", "foobar") = true (= 1) |
| 58 |
%% isInString("boo", "foobar") = false (= 0) |
| 59 |
\pgfmathdeclarefunction{extisInString}{2}{% |
| 60 |
\pgfutil@in@{#1}{#2}% |
| 61 |
\ifpgfutil@in@\def\pgfmathresult{1}\else\def\pgfmathresult{0}\fi} |
| 62 |
|
| 63 |
%% strcat("foo", "bar") = "foobar" (can have more than two parameters) |
| 64 |
\pgfmathdeclarefunction{extstrcat}{...}{% |
| 65 |
\begingroup |
| 66 |
\let\pgfmathresult\pgfutil@empty |
| 67 |
\pgfextmathstrcat@@#1\pgfmath@stop |
| 68 |
} |
| 69 |
\def\pgfextmathstrcat@@#1{% |
| 70 |
\ifx\pgfmath@stop#1% |
| 71 |
\def\pgfmath@next{\pgfmath@smuggleone\pgfmathresult\endgroup}% |
| 72 |
\else |
| 73 |
\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult#1}% |
| 74 |
\let\pgfmath@next\pgfextmathstrcat@@ |
| 75 |
\fi |
| 76 |
\pgfmath@next |
| 77 |
} |
| 78 |
|
| 79 |
% http://tex.stackexchange.com/questions/244569/bounding-lines-around-tax-nodes/244619#244619 |
| 80 |
\pgfmathdeclarefunction{extatanXY}{2}{\pgfmathatantwo@{#2}{#1}} |
| 81 |
\pgfmathdeclarefunction{extatanYX}{2}{\pgfmathatantwo@{#1}{#2}} |
| 82 |
|
| 83 |
\pgfmathdeclarefunction{extdistancebetween}{2}{% only coordinates/nodes |
| 84 |
\begingroup |
| 85 |
\nullfont |
| 86 |
\pgfpointdiff{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}% |
| 87 |
\edef\pgfmath@temp{{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}}% |
| 88 |
\expandafter\pgfmathveclen@\pgfmath@temp |
| 89 |
\pgfmath@smuggleone\pgfmathresult |
| 90 |
\endgroup} |
| 91 |
\pgfmathdeclarefunction{extqdistancebetween}{1}{% only coordinates/nodes |
| 92 |
\begingroup |
| 93 |
\nullfont |
| 94 |
\pgfpointdiff{\pgfpointorigin}{\pgfpointanchor{#1}{center}}% |
| 95 |
\edef\pgfmath@temp{{\pgf@sys@tonumber\pgf@x}{\pgf@sys@tonumber\pgf@y}}% |
| 96 |
\expandafter\pgfmathveclen@\pgfmath@temp |
| 97 |
\pgfmath@smuggleone\pgfmathresult |
| 98 |
\endgroup} |
| 99 |
|
| 100 |
\pgfmathdeclarefunction{extqanglebetween}{1}{% |
| 101 |
\begingroup |
| 102 |
\nullfont |
| 103 |
\pgfmathanglebetweenpoints{\pgfpointorigin}{\pgfpointanchor{#1}{center}}% |
| 104 |
\pgfmath@smuggleone\pgfmathresult |
| 105 |
\endgroup |
| 106 |
} |
| 107 |
|
| 108 |
\pgfmathdeclarefunction{extanglebetween}{2}{% |
| 109 |
\begingroup |
| 110 |
\nullfont |
| 111 |
\pgfmathanglebetweenpoints{\pgfpointanchor{#1}{center}}{\pgfpointanchor{#2}{center}}% |
| 112 |
\pgfmath@smuggleone\pgfmathresult |
| 113 |
\endgroup |
| 114 |
} |
| 115 |
|
| 116 |
\pgfmathdeclarefunction{extisEmpty}{1}{% |
| 117 |
\begingroup |
| 118 |
\def\pgfmath@temp{#1}% |
| 119 |
\pgfutil@ifxempty\pgfmath@temp{\def\pgfmathresult{1}}{\def\pgfmathresult{0}}% |
| 120 |
\pgfmath@smuggleone\pgfmathresult |
| 121 |
\endgroup |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
\pgfextset{ |
| 126 |
declare constant/.code={% |
| 127 |
\let\pgfmathdeclareconstant@@@\pgfutil@empty |
| 128 |
\pgfkeysvalueof{/pgf/declare function/execute at begin function}% |
| 129 |
\pgfmathdeclareconstant@#1@=@;\pgf@stop |
| 130 |
\pgfkeysvalueof{/pgf/declare function/execute at end function}% |
| 131 |
\pgfmathdeclareconstant@@@ |
| 132 |
}} |
| 133 |
\def\pgfmathdeclareconstant@{% |
| 134 |
\pgfutil@ifnextchar x\pgfmathdeclareconstant@@\pgfmathdeclareconstant@@ |
| 135 |
} |
| 136 |
\def\pgfmathdeclareconstant@@#1=#2;#3\pgf@stop{% |
| 137 |
\edef\pgfmath@local@temp{#1}% |
| 138 |
\pgfutil@ifx\pgfmath@local@temp\pgfmath@local@at{}{% |
| 139 |
\pgfutil@g@addto@macro\pgfmathdeclareconstant@@@{\pgfmathdeclarepseudoconstant{#1}{\def\pgfmathresult{#2}}}% |
| 140 |
\pgfmathdeclareconstant@#3\pgf@stop |
| 141 |
}% |
| 142 |
} |
| 143 |
|
| 144 |
%%% Some shape |
| 145 |
|
| 146 |
\tikzextset{% quick versions of reverse clips |
| 147 |
reverse clip/.is choice, |
| 148 |
reverse clip/clockwise/.code={% |
| 149 |
\begingroup |
| 150 |
\pgfsetcornersarced{\pgfpointorigin}% |
| 151 |
\pgfpathqmoveto{16000pt}{16000pt}% |
| 152 |
\pgfpathqlineto{16000pt}{-16000pt}% |
| 153 |
\pgfpathqlineto{-16000pt}{-16000pt}% |
| 154 |
\pgfpathqlineto{-16000pt}{16000pt}% |
| 155 |
\pgfpathclose |
| 156 |
\endgroup |
| 157 |
}, |
| 158 |
reverse clip/counter clockwise/.code={% |
| 159 |
\begingroup |
| 160 |
\pgfsetcornersarced{\pgfpointorigin}% |
| 161 |
\pgfpathqmoveto{16000pt}{16000pt}% |
| 162 |
\pgfpathqlineto{-16000pt}{16000pt}% |
| 163 |
\pgfpathqlineto{-16000pt}{-16000pt}% |
| 164 |
\pgfpathqlineto{16000pt}{-16000pt}% |
| 165 |
\pgfpathclose |
| 166 |
\endgroup |
| 167 |
}, |
| 168 |
clip rule/.is choice, |
| 169 |
clip rule/even odd/.code=\pgfseteorule, |
| 170 |
clip rule/nonzero/.code=\pgfsetnonzerorule, |
| 171 |
reverse clip/.default=counter clockwise, |
| 172 |
} |
| 173 |
%%% Compatibility |
| 174 |
\tikzextset{ |
| 175 |
/tikz-ext/compat/add library={misc}{pre 0.6}, |
| 176 |
compat/misc/warn/.append code={% |
| 177 |
\tikzextutil@compatwarning@key{misc}{pre 0.6}{/pgf/full arc}{/pgf/ext/full arc}% |
| 178 |
\tikzextutil@compatwarning@mathcmdII{misc}{pre 0.6}{strrepeat}{extstrrepeat}% |
| 179 |
\tikzextutil@compatwarning@mathcmdII{misc}{pre 0.6}{isInString}{extisInString}% |
| 180 |
\ifcsname pgfmathstrcat@\endcsname\else |
| 181 |
\let\pgfmathextstrcat@noforest\relax |
| 182 |
\tikzextutil@compatwarning@mathcmdX{misc}{pre 0.6}{strcat}{extstrcat}% |
| 183 |
\fi |
| 184 |
\tikzextutil@compatwarning@mathcmdI{misc}{pre 0.6}{isEmpty}{extisEmpty}% |
| 185 |
\tikzextutil@compatwarning@mathcmdII{misc}{pre 0.6}{atanXY}{extatanXY}% |
| 186 |
\tikzextutil@compatwarning@mathcmdII{misc}{pre 0.6}{atanYX}{extatanYX}% |
| 187 |
\tikzextutil@compatwarning@mathcmdII{misc}{pre 0.6}{anglebetween}{extanglebetween}% |
| 188 |
\tikzextutil@compatwarning@mathcmdII{misc}{pre 0.6}{distancebetween}{extdistancebetween}% |
| 189 |
\tikzextutil@compatwarning@mathcmdI{misc}{pre 0.6}{qanglebetween}{extqanglebetween}% |
| 190 |
\tikzextutil@compatwarning@mathcmdI{misc}{pre 0.6}{qdistancebetween}{extqdistancebetween}% |
| 191 |
}, |
| 192 |
compat/misc/pre 0.6/.append code={% |
| 193 |
\pgfkeysdef{/pgf/full arc}{\pgfkeysvalueof{/pgf/ext/full arc/.@cmd}##1\pgfeov}% |
| 194 |
\pgfmathdeclarefunction*{strrepeat}{2}{\pgfmathextstrrepeat@{##1}{##2}}% |
| 195 |
\pgfmathdeclarefunction*{isInString}{2}{\pgfmathextisInString@{##1}{##2}}% |
| 196 |
\pgfmathdeclarefunction*{isEmpty}{1}{\pgfmathextisEmpty@{##1}}% |
| 197 |
\pgfmathdeclarefunction*{anglebetween}{2}{\pgfmathextanglebetween@{##1}{##2}}% |
| 198 |
\pgfmathdeclarefunction*{qanglebetween}{1}{\pgfmathextqanglebetween@{##1}}% |
| 199 |
\pgfmathdeclarefunction*{distancebetween}{2}{\pgfmathextdistancebetween@{##1}{##2}}% |
| 200 |
\pgfmathdeclarefunction*{qdistancebetween}{1}{\pgfmathextqdistancebetween@{##1}}% |
| 201 |
\pgfmathdeclarefunction*{atanXY}{2}{\pgfmathextatantwo@{##2}{##1}}% |
| 202 |
\pgfmathdeclarefunction*{atanYX}{2}{\pgfmathextatantwo@{##2}{##1}}% |
| 203 |
\ifcsname pgfmathstrcat@\endcsname |
| 204 |
\ifcsname pgfmathextstrcat@noforest\endcsname |
| 205 |
\pgfmathdeclarefunction*{strcat}{...}{\pgfmathextstrcat##1}% |
| 206 |
\fi |
| 207 |
\else |
| 208 |
\let\pgfmathextstrcat@noforest\relax |
| 209 |
\pgfmathdeclarefunction{strcat}{...}{\pgfmathextstrcat##1}% |
| 210 |
\fi |
| 211 |
}, |
| 212 |
compat/misc/\pgfkeysvalueof{/tikz/ext/compat/misc}% |
| 213 |
} |