| 1 |
% tkz-tools-eu-utilities |
| 2 |
% Copyright 2024 Alain Matthes |
| 3 |
% This work may be distributed and/or modified under the |
| 4 |
% conditions of the LaTeX Project Public License, either version 1.3 |
| 5 |
% of this license or (at your option) any later version. |
| 6 |
% The latest version of this license is in |
| 7 |
% http://www.latex-project.org/lppl.txt |
| 8 |
% and version 1.3 or later is part of all distributions of LaTeX |
| 9 |
% version 2005/12/01 or later. |
| 10 |
% This work has the LPPL maintenance status “maintained”. |
| 11 |
% The Current Maintainer of this work is Alain Matthes. |
| 12 |
|
| 13 |
\def\fileversion{4.21c} |
| 14 |
\def\filedate{2024/01/16} |
| 15 |
\typeout{2024/01/16 4.21c tkz-tools-utilities.tex} |
| 16 |
\makeatletter |
| 17 |
\pgfkeys{/tkzClip/.cd, |
| 18 |
space/.store in = {\tkz@CLI@space}, |
| 19 |
space = {}} |
| 20 |
|
| 21 |
\def\tkzClip{\pgfutil@ifnextchar[{\tkz@Clip}{\tkz@Clip[]}} |
| 22 |
\def\tkz@Clip[#1]{% |
| 23 |
|
| 24 |
\pgfqkeys{/tkzClip}{#1} |
| 25 |
\ifx\tkzutil@empty\tkz@CLI@space |
| 26 |
\clip (\tkz@xa,\tkz@ya) rectangle (\tkz@xb,\tkz@yb); |
| 27 |
\else |
| 28 |
\edef\tkz@xxa{\fpeval{\tkz@xa-\tkz@CLI@space}} |
| 29 |
\edef\tkz@yya{\fpeval{\tkz@ya-\tkz@CLI@space}} |
| 30 |
\edef\tkz@xxb{\fpeval{\tkz@xb+\tkz@CLI@space}} % correction bug 2020 |
| 31 |
\edef\tkz@yyb{\fpeval{\tkz@yb+\tkz@CLI@space}} |
| 32 |
\clip (\tkz@xxa,\tkz@yya) rectangle (\tkz@xxb,\tkz@yyb); |
| 33 |
\fi |
| 34 |
} |
| 35 |
|
| 36 |
% for testing results |
| 37 |
\def\extractxy#1{% |
| 38 |
\pgfextractx{\pgf@x}{\pgfpointanchor{#1}{center}} |
| 39 |
\pgfextracty{\pgf@y}{\pgfpointanchor{#1}{center}} |
| 40 |
\typeout{#1 \the\pgf@x,\the\pgf@y} |
| 41 |
} |
| 42 |
%<-------------- some tools -------------------------------------------------> |
| 43 |
\def\tkzutil@empty{} |
| 44 |
\def\tkzutil@firstofone#1{#1} |
| 45 |
\def\tkzutil@firstoftwo#1#2{#1} |
| 46 |
\def\tkzutil@secondoftwo#1#2{#2} |
| 47 |
%<--------------------------------------------------------------------------–> |
| 48 |
\long\def\tkzutil@ifundefined#1{% |
| 49 |
\expandafter\ifx\csname#1\endcsname\relax |
| 50 |
\expandafter\tkzutil@firstoftwo |
| 51 |
\else |
| 52 |
\expandafter\tkzutil@secondoftwo |
| 53 |
\fi} |
| 54 |
%<--------------------------------------------------------------------------–> |
| 55 |
\long\def\iftkznodedefined#1#2#3{% |
| 56 |
\tkzutil@ifundefined{pgf@sh@ns@#1}{#3}{#2}% |
| 57 |
} |
| 58 |
%<--------------------------------------------------------------------------–> |
| 59 |
\gdef\tkzActivOff{% |
| 60 |
\edef\tkzTwoPtCode{\the\catcode`\:} |
| 61 |
\edef\tkzPtExCode{\the\catcode`\!} |
| 62 |
\edef\tkzPtVirCode{\the\catcode`\;} |
| 63 |
\catcode`\:=12 \catcode`\!=12 \catcode`\;=12 |
| 64 |
}% |
| 65 |
\gdef\tkzActivOn{% |
| 66 |
\catcode`\:=\tkzTwoPtCode\relax |
| 67 |
\catcode`\!=\tkzPtExCode\relax |
| 68 |
\catcode`\;=\tkzPtVirCode\relax |
| 69 |
}% |
| 70 |
%<--------------------------------------------------------------------------–> |
| 71 |
% Pour savoir le nombre de décimales d'un nombre |
| 72 |
% le nombre dans #1 et le résultat dans \c@pgfmath@countb |
| 73 |
%<--------------------------------------------------------------------------–> |
| 74 |
\newcommand\tkz@getdecimal[1]{\expandafter\@getdecimal#1.\@nil} |
| 75 |
\def\@getdecimal#1.#2\@nil{% |
| 76 |
\ifx\empty#2\empty |
| 77 |
% Si #2 est vide, c'est qu'il n'y avait pas de point |
| 78 |
% dans la chaîne initiale |
| 79 |
\c@pgfmath@countb0 % |
| 80 |
\gdef\tkz@decpart{}% |
| 81 |
\else |
| 82 |
% sinon c'est la chaîne qui suit le point décimal... |
| 83 |
\CountToken{#2}% |
| 84 |
% ... y compris le point en trop ajouté par \tkz@getdecimal :-) |
| 85 |
\advance\c@pgfmath@countb by-1 % |
| 86 |
\@@getdecimal#2\@nil |
| 87 |
\fi |
| 88 |
} |
| 89 |
\def\@@getdecimal#1.\@nil{\gdef\tkz@decpart{#1}} |
| 90 |
%<---------------------------------------------------------–> |
| 91 |
% code from JCC modifi |
| 92 |
\newcommand\CountToken[1]{% |
| 93 |
\c@pgfmath@countb0 % |
| 94 |
\expandafter\C@untToken#1\@nil |
| 95 |
%modifi ajout du expandafter |
| 96 |
} |
| 97 |
\newcommand\C@untToken{% |
| 98 |
\afterassignment\C@untT@ken\let\CurrT@ken= |
| 99 |
} |
| 100 |
\newcommand\C@untT@ken{% |
| 101 |
\ifx\CurrT@ken\@nil \else |
| 102 |
\advance\c@pgfmath@countb by1 % |
| 103 |
\expandafter\C@untToken |
| 104 |
\fi |
| 105 |
} |
| 106 |
%<---------------------------------------------------------–> |
| 107 |
\def\tkz@recuplast(#1,#2){\def\tkz@last{#1}} |
| 108 |
\def\tkz@stop{\tkz@stop} |
| 109 |
% end code from JCC |
| 110 |
%<---------------------------------------------------------–> |
| 111 |
% Tools |
| 112 |
%<---------------------------------------------------------–> |
| 113 |
%<–––––––– code from TeX in Practice ––––––––> |
| 114 |
\def\SubStringConditional #1#2{% |
| 115 |
TT\fi |
| 116 |
\edef\@MainString{#1}% |
| 117 |
\edef\@SubStringConditionalTemp{{#1}{#2}}% |
| 118 |
\expandafter\@SubStringConditional\@SubStringConditionalTemp |
| 119 |
} |
| 120 |
\def\@SubStringConditional #1#2{% |
| 121 |
\def\@TestSubS ##1#2##2\\{% |
| 122 |
\def\@TestTemp{##1}% |
| 123 |
}% |
| 124 |
\@TestSubS #1#2\\ |
| 125 |
\ifx\@MainString\@TestTemp |
| 126 |
\tkz@TestSubStringfalse |
| 127 |
\else |
| 128 |
\tkz@TestSubStringtrue |
| 129 |
\fi |
| 130 |
\iftkz@TestSubString |
| 131 |
} |
| 132 |
\def\RecursionMacroEnd #1#2#3{% |
| 133 |
#1\relax |
| 134 |
\def\@RecursionMacroEndNext{#2}% |
| 135 |
\else |
| 136 |
\def\@RecursionMacroEndNext{#3}% |
| 137 |
\fi |
| 138 |
\@RecursionMacroEndNext |
| 139 |
} |
| 140 |
\def\ReplaceSubStrings #1#2#3#4{% |
| 141 |
\def\@ReplaceResult{#1}% |
| 142 |
\edef\@ReplaceMain{#2}% |
| 143 |
\edef\@ReplaceSub{#3}% |
| 144 |
\edef\@ReplaceSubRep{#4}% |
| 145 |
\@ReplaceSubStrings |
| 146 |
} |
| 147 |
\def\@ReplaceSubStrings{% |
| 148 |
\RecursionMacroEnd |
| 149 |
{\if\SubStringConditional{\@ReplaceMain}{\@ReplaceSub}}% |
| 150 |
{\@ReplaceSubStringsDo}{\expandafter\edef\@ReplaceResult{\@ReplaceMain}}% |
| 151 |
} |
| 152 |
\def\@ReplaceSubStringsDoX{% |
| 153 |
\def\@ReplaceSubStringsDoA ##1% |
| 154 |
}% |
| 155 |
\def\@ReplaceSubStringsDo{% |
| 156 |
\expandafter\@ReplaceSubStringsDoX \@ReplaceSub |
| 157 |
##2\@EndReplaceSubStrings{% |
| 158 |
\edef\@ReplaceMain{##1\@ReplaceSubRep ##2}% |
| 159 |
}% |
| 160 |
\expandafter\@ReplaceSubStringsDoA\@ReplaceMain |
| 161 |
\@EndReplaceSubStrings |
| 162 |
\@ReplaceSubStrings |
| 163 |
} |
| 164 |
%<---------------------------------------------------------–> |
| 165 |
\def\DisabledNumprint{% |
| 166 |
\let\tkz@numprint\numprint |
| 167 |
\let\numprint\relax |
| 168 |
} |
| 169 |
\def\EnabledNumprint{\let\numprint\tkz@numprint} |
| 170 |
%<---------------------------------------------------------–> |
| 171 |
\def\tkzSwapPoints(#1,#2){ |
| 172 |
\pgfnodealias{tkzPointTmp}{#2} |
| 173 |
\pgfnodealias{#2}{#1} |
| 174 |
\pgfnodealias{#1}{tkzPointTmp}} |
| 175 |
%<---------------------------------------------------------–> |
| 176 |
\def\tkzPermute(#1,#2,#3){ |
| 177 |
\tkzURotateWithNodes(#1,#3,#2)(#3) \tkzGetPoint{tkzpt} |
| 178 |
\tkzURotateWithNodes(#1,#2,#3)(#2) \tkzGetPoint{#2} |
| 179 |
\tkzSwapPoints(tkzpt,#3)} |
| 180 |
%<---------------------------------------------------------–> |
| 181 |
\def\tkzDotProduct(#1,#2,#3){% |
| 182 |
\begingroup |
| 183 |
\pgfextractx{\pgf@x}{\pgfpointanchor{#1}{center}}% |
| 184 |
\pgfextracty{\pgf@y}{\pgfpointanchor{#1}{center}}% |
| 185 |
\tkz@ax\pgf@x% |
| 186 |
\tkz@ay\pgf@y% |
| 187 |
\pgfextractx{\pgf@x}{\pgfpointanchor{#2}{center}}% |
| 188 |
\pgfextracty{\pgf@y}{\pgfpointanchor{#2}{center}} |
| 189 |
\tkz@bx\pgf@x% |
| 190 |
\tkz@by\pgf@y% |
| 191 |
\pgfextractx{\pgf@x}{\pgfpointanchor{#3}{center}}% |
| 192 |
\pgfextracty{\pgf@y}{\pgfpointanchor{#3}{center}}% |
| 193 |
\tkz@cx\pgf@x% |
| 194 |
\tkz@cy\pgf@y% |
| 195 |
\edef\tkz@dotprod{\fpeval{round(((\tkz@bx-\tkz@ax)*(\tkz@cx-\tkz@ax)+(\tkz@by-\tkz@ay)*(\tkz@cy-\tkz@ay))/(809.55841),5)}} |
| 196 |
\global\let\tkzMathResult\tkz@dotprod |
| 197 |
\endgroup} |
| 198 |
%<---------------------------------------------------------–> |
| 199 |
\def\tkzGetResult#1{% |
| 200 |
\global\expandafter\edef\csname #1\endcsname{\tkzMathResult}} |
| 201 |
%<---------------------------------------------------------–> |
| 202 |
% #1,#2 and #3 aligned |
| 203 |
\def\tkzIsLinear(#1,#2,#3){% |
| 204 |
\begingroup |
| 205 |
\tkz@@CalcLengthcm(#1,#2){tkz@la} |
| 206 |
\tkz@@CalcLengthcm(#1,#3){tkz@lb} |
| 207 |
\tkzDotProduct(#1,#2,#3) |
| 208 |
\edef\tkzMathResult{\fpeval{abs(abs(\tkzMathResult)-(\tkz@la)*(\tkz@lb))}} |
| 209 |
\ifdim \tkzMathResult pt < 0.0001 pt\relax% |
| 210 |
\global\tkzLineartrue |
| 211 |
\else |
| 212 |
\global\tkzLinearfalse |
| 213 |
\fi |
| 214 |
\endgroup |
| 215 |
} |
| 216 |
%<---------------------------------------------------------–> |
| 217 |
% syntax : vec(#2,#1) ortho vec(#3,#1) |
| 218 |
\def\tkzIsOrtho(#1,#2,#3){% |
| 219 |
\begingroup |
| 220 |
\tkzDotProduct(#1,#2,#3) |
| 221 |
\edef\tkzMathResult{\fpeval{abs(\tkzMathResult)}} |
| 222 |
\ifdim \tkzMathResult pt < 0.0001 pt\relax% |
| 223 |
\global\tkzOrthotrue |
| 224 |
\else |
| 225 |
\global\tkzOrthofalse |
| 226 |
\fi |
| 227 |
\endgroup |
| 228 |
} |
| 229 |
%<---------------------------------------------------------–> |
| 230 |
\def\tkzHelpGrid{% |
| 231 |
\draw[help lines] (current bounding box.south west) grid |
| 232 |
(current bounding box.north east); |
| 233 |
} |
| 234 |
|
| 235 |
\makeatother |
| 236 |
\endinput |