| 1 |
% Copyright 2021 by marmotghost |
| 2 |
% v0.1 |
| 3 |
% |
| 4 |
% This file may be distributed and/or modified under the |
| 5 |
% LaTeX project public license (LPPL), version 1.3c |
| 6 |
% see |
| 7 |
% https://www.latex-project.org/lppl/lppl-1-3c/ |
| 8 |
|
| 9 |
|
| 10 |
\usepgflibrary{fpu} |
| 11 |
\global\let\pgf@bbox@lt@curveto@normal\pgf@lt@curveto |
| 12 |
\global\let\pgf@bbox@nlt@curveto@normal\pgf@nlt@curveto |
| 13 |
|
| 14 |
\pgfqkeys{/pgf}{bezier bounding box/.is if=pgf@bbox@switch@} |
| 15 |
|
| 16 |
|
| 17 |
\def\pgf@bbox@switch@false{% |
| 18 |
\let\pgf@lt@curveto \pgf@bbox@lt@curveto@normal |
| 19 |
\let\pgf@nlt@curveto\pgf@bbox@nlt@curveto@normal |
| 20 |
} |
| 21 |
|
| 22 |
\def\pgf@bbox@switch@true{% |
| 23 |
\let\pgf@lt@curveto \pgf@bbox@curveto |
| 24 |
\let\pgf@nlt@curveto\pgf@bbox@curveto |
| 25 |
} |
| 26 |
\def\pgf@bbox@curveto#1#2#3#4#5#6{% |
| 27 |
\begingroup |
| 28 |
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}% |
| 29 |
% extrema in x |
| 30 |
% first discriminant d1, must be \ne 0 |
| 31 |
\pgfmathsetmacro{\pgf@temp@a}{(\pgf@path@lastx)-(#5)-3*(#1)+3*(#3)}% |
| 32 |
\pgfmathtruncatemacro{\pgf@temp@c}{(abs(\pgf@temp@a)>0.1?1:0)}% |
| 33 |
\ifnum\pgf@temp@c=1\relax |
| 34 |
% second discriminant d2, must be \ge 0 |
| 35 |
\pgfmathsetmacro{\pgf@temp@b}{(\pgf@path@lastx)*(#5)-(#5)*(#1)+(#1)*(#1)-(\pgf@path@lastx)*(#3)-(#1)*(#3)+(#3)*(#3)}% |
| 36 |
\pgfmathtruncatemacro{\pgf@temp@c}{sign(\pgf@temp@b)}% |
| 37 |
\ifnum\pgf@temp@c<0 |
| 38 |
\else |
| 39 |
\pgfmathsetmacro{\pgf@temp@b}{sqrt(abs(\pgf@temp@b))}% |
| 40 |
\pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((\pgf@path@lastx)-2*(#1)+(#3)-\pgf@temp@b)/\pgf@temp@a))}% |
| 41 |
\pgfmathparse{(\pgf@path@lastx)*pow((1-\pgf@temp@c),3)+3*(#1)*pow((1-\pgf@temp@c),2)*\pgf@temp@c+3*(#3)*(1-\pgf@temp@c)*\pgf@temp@c*\pgf@temp@c+(#5)*\pgf@temp@c*\pgf@temp@c*\pgf@temp@c}% |
| 42 |
\pgfutil@tempdimb=\pgfmathresult pt\relax% |
| 43 |
\pgf@protocolsizes{\pgfutil@tempdimb}{\pgf@path@lasty}% |
| 44 |
\pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((\pgf@path@lastx)-2*(#1)+(#3)+\pgf@temp@b)/\pgf@temp@a))}% |
| 45 |
\pgfmathparse{(\pgf@path@lastx)*pow((1-\pgf@temp@c),3)+3*(#1)*pow((1-\pgf@temp@c),2)*\pgf@temp@c+3*(#3)*(1-\pgf@temp@c)*\pgf@temp@c*\pgf@temp@c+(#5)*\pgf@temp@c*\pgf@temp@c*\pgf@temp@c}% |
| 46 |
\pgfutil@tempdimb=\pgfmathresult pt\relax% |
| 47 |
\pgf@protocolsizes{\pgfutil@tempdimb}{\pgf@path@lasty}% |
| 48 |
\fi |
| 49 |
\else |
| 50 |
% third discriminant d3, must be \ne 0 |
| 51 |
\pgfmathsetmacro{\pgf@temp@b}{abs((#5)+(#1)-2*(#3))}% |
| 52 |
\pgfmathtruncatemacro{\pgf@temp@c}{(abs(\pgf@temp@b)>0.1?1:0)}% |
| 53 |
\ifnum\pgf@temp@c=1\relax |
| 54 |
\pgfmathsetmacro{\pgf@temp@c}{((#5)+2*(#1)-3*(#3))/((#5)+(#1)-2*(#3))}% |
| 55 |
\pgfmathparse{(\pgf@path@lastx)*pow((1-\pgf@temp@c),3)+3*(#1)*pow((1-\pgf@temp@c),2)*\pgf@temp@c+3*(#3)*(1-\pgf@temp@c)*\pgf@temp@c*\pgf@temp@c+(#5)*\pgf@temp@c*\pgf@temp@c*\pgf@temp@c}% |
| 56 |
\pgfutil@tempdimb=\pgfmathresult pt\relax% |
| 57 |
\pgf@protocolsizes{\pgfutil@tempdimb}{\pgf@path@lasty}% |
| 58 |
\fi |
| 59 |
\fi |
| 60 |
% 0/0 |
| 61 |
\pgfmathsetmacro{\pgf@temp@a}{(#5)+(#1)-2*(#3)}% |
| 62 |
\pgfmathtruncatemacro{\pgf@temp@b}{(abs(\pgf@temp@a)>0.1?1:0)}% |
| 63 |
\ifnum\pgf@temp@b=1\relax |
| 64 |
\pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((#5)+2*(#1)-3*(#3))/(2*\pgf@temp@a)))}% |
| 65 |
\else |
| 66 |
\pgfmathsetmacro{\pgf@temp@c}{0.5}% |
| 67 |
\fi |
| 68 |
\pgfmathparse{(\pgf@path@lastx)*pow((1-\pgf@temp@c),3)+3*(#1)*pow((1-\pgf@temp@c),2)*\pgf@temp@c+3*(#3)*(1-\pgf@temp@c)*\pgf@temp@c*\pgf@temp@c+(#5)*\pgf@temp@c*\pgf@temp@c*\pgf@temp@c}% |
| 69 |
\pgfutil@tempdimb=\pgfmathresult pt\relax% |
| 70 |
\pgf@protocolsizes{\pgfutil@tempdimb}{\pgf@path@lasty}% |
| 71 |
% |
| 72 |
% y code |
| 73 |
% first discriminant d1, must be \ne 0 |
| 74 |
\pgfmathsetmacro{\pgf@temp@a}{(\pgf@path@lasty)-(#6)-3*(#2)+3*(#4)}% |
| 75 |
\pgfmathtruncatemacro{\pgf@temp@c}{(abs(\pgf@temp@a)>0.1?1:0)}% |
| 76 |
\ifnum\pgf@temp@c=1\relax |
| 77 |
% second discriminant d2, must be \ge 0 |
| 78 |
\pgfmathsetmacro{\pgf@temp@b}{(\pgf@path@lasty)*(#6)-(#6)*(#2)+(#2)*(#2)-(\pgf@path@lasty)*(#4)-(#2)*(#4)+(#4)*(#4)}% |
| 79 |
\pgfmathtruncatemacro{\pgf@temp@c}{sign(\pgf@temp@b)}% |
| 80 |
\ifnum\pgf@temp@c<0 |
| 81 |
\else |
| 82 |
\pgfmathsetmacro{\pgf@temp@b}{sqrt(abs(\pgf@temp@b))}% |
| 83 |
\pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((\pgf@path@lasty)-2*(#2)+(#4)-\pgf@temp@b)/\pgf@temp@a))}% |
| 84 |
\pgfmathparse{(\pgf@path@lasty)*pow((1-\pgf@temp@c),3)+3*(#2)*pow((1-\pgf@temp@c),2)*\pgf@temp@c+3*(#4)*(1-\pgf@temp@c)*\pgf@temp@c*\pgf@temp@c+(#6)*\pgf@temp@c*\pgf@temp@c*\pgf@temp@c}% |
| 85 |
\pgfutil@tempdimb=\pgfmathresult pt\relax% |
| 86 |
\pgf@protocolsizes{\pgf@path@lastx}{\pgfutil@tempdimb}% |
| 87 |
\pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((\pgf@path@lasty)-2*(#2)+(#4)+\pgf@temp@b)/\pgf@temp@a))}% |
| 88 |
\pgfmathparse{(\pgf@path@lasty)*pow((1-\pgf@temp@c),3)+3*(#2)*pow((1-\pgf@temp@c),2)*\pgf@temp@c+3*(#4)*(1-\pgf@temp@c)*\pgf@temp@c*\pgf@temp@c+(#6)*\pgf@temp@c*\pgf@temp@c*\pgf@temp@c}% |
| 89 |
\pgfutil@tempdimb=\pgfmathresult pt\relax% |
| 90 |
\pgf@protocolsizes{\pgf@path@lastx}{\pgfutil@tempdimb}% |
| 91 |
\fi |
| 92 |
\else |
| 93 |
% third discriminant d3, must be \ne 0 |
| 94 |
\pgfmathsetmacro{\pgf@temp@b}{abs((#6)+(#2)-2*(#4))}% |
| 95 |
\pgfmathtruncatemacro{\pgf@temp@c}{(abs(\pgf@temp@b)>0.1?1:0)}% |
| 96 |
\ifnum\pgf@temp@c=1\relax |
| 97 |
\pgfmathsetmacro{\pgf@temp@c}{((#6)+2*(#2)-3*(#4))/((#6)+(#2)-2*(#4))}% |
| 98 |
\pgfmathparse{(\pgf@path@lasty)*pow((1-\pgf@temp@c),3)+3*(#2)*pow((1-\pgf@temp@c),2)*\pgf@temp@c+3*(#4)*(1-\pgf@temp@c)*\pgf@temp@c*\pgf@temp@c+(#6)*\pgf@temp@c*\pgf@temp@c*\pgf@temp@c}% |
| 99 |
\pgfutil@tempdimb=\pgfmathresult pt\relax% |
| 100 |
\pgf@protocolsizes{\pgf@path@lastx}{\pgfutil@tempdimb}% |
| 101 |
\fi |
| 102 |
\fi |
| 103 |
% 0/0 |
| 104 |
\pgfmathsetmacro{\pgf@temp@a}{(#6)+(#2)-2*(#4)}% |
| 105 |
\pgfmathtruncatemacro{\pgf@temp@b}{(abs(\pgf@temp@a)>0.1?1:0)}% |
| 106 |
\ifnum\pgf@temp@b=1\relax |
| 107 |
\pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((#6)+2*(#2)-3*(#4))/(2*\pgf@temp@a)))}% |
| 108 |
\else |
| 109 |
\pgfmathsetmacro{\pgf@temp@c}{0.5}% |
| 110 |
\fi |
| 111 |
\pgfmathparse{(\pgf@path@lasty)*pow((1-\pgf@temp@c),3)+3*(#2)*pow((1-\pgf@temp@c),2)*\pgf@temp@c+3*(#4)*(1-\pgf@temp@c)*\pgf@temp@c*\pgf@temp@c+(#6)*\pgf@temp@c*\pgf@temp@c*\pgf@temp@c}% |
| 112 |
\pgfutil@tempdimb=\pgfmathresult pt\relax% |
| 113 |
\pgf@protocolsizes{\pgf@path@lastx}{\pgfutil@tempdimb}% |
| 114 |
% |
| 115 |
\pgf@protocolsizes{\pgf@path@lastx}{\pgf@path@lasty}% |
| 116 |
\pgf@protocolsizes{#5}{#6}% |
| 117 |
\endgroup |
| 118 |
\pgfsyssoftpath@curveto{\the#1}{\the#2}{\the#3}{\the#4}{\the#5}{\the#6}% |
| 119 |
} |
| 120 |
\endinput |