summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/tikz-bbox/pgflibrarybbox.code.tex
blob: a9e887f809ea70c30d5ff7c761a18a11630a9887 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
% Copyright 2021 by marmotghost
% v0.1
%
% This file may be distributed and/or modified under the 
% LaTeX project public license (LPPL), version 1.3c
% see
% https://www.latex-project.org/lppl/lppl-1-3c/


\usepgflibrary{fpu}
\global\let\pgf@bbox@lt@curveto@normal\pgf@lt@curveto
\global\let\pgf@bbox@nlt@curveto@normal\pgf@nlt@curveto

\pgfqkeys{/pgf}{bezier bounding box/.is if=pgf@bbox@switch@}


\def\pgf@bbox@switch@false{%
  \let\pgf@lt@curveto \pgf@bbox@lt@curveto@normal
  \let\pgf@nlt@curveto\pgf@bbox@nlt@curveto@normal
}

\def\pgf@bbox@switch@true{%
  \let\pgf@lt@curveto \pgf@bbox@curveto
  \let\pgf@nlt@curveto\pgf@bbox@curveto
}
\def\pgf@bbox@curveto#1#2#3#4#5#6{%
\begingroup
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
  % extrema in x
  % first discriminant d1, must be \ne 0
  \pgfmathsetmacro{\pgf@temp@a}{(\pgf@path@lastx)-(#5)-3*(#1)+3*(#3)}%
  \pgfmathtruncatemacro{\pgf@temp@c}{(abs(\pgf@temp@a)>0.1?1:0)}%
  \ifnum\pgf@temp@c=1\relax
	% second discriminant d2, must be \ge 0
	\pgfmathsetmacro{\pgf@temp@b}{(\pgf@path@lastx)*(#5)-(#5)*(#1)+(#1)*(#1)-(\pgf@path@lastx)*(#3)-(#1)*(#3)+(#3)*(#3)}%
	\pgfmathtruncatemacro{\pgf@temp@c}{sign(\pgf@temp@b)}%
	\ifnum\pgf@temp@c<0
	\else
	  \pgfmathsetmacro{\pgf@temp@b}{sqrt(abs(\pgf@temp@b))}%
	  \pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((\pgf@path@lastx)-2*(#1)+(#3)-\pgf@temp@b)/\pgf@temp@a))}%	 
	  \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}%
	  \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{\pgfutil@tempdimb}{\pgf@path@lasty}%
	  \pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((\pgf@path@lastx)-2*(#1)+(#3)+\pgf@temp@b)/\pgf@temp@a))}%	 
	  \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}%
	  \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{\pgfutil@tempdimb}{\pgf@path@lasty}%
	\fi
  \else
    % third discriminant d3, must be \ne 0
    \pgfmathsetmacro{\pgf@temp@b}{abs((#5)+(#1)-2*(#3))}%
	\pgfmathtruncatemacro{\pgf@temp@c}{(abs(\pgf@temp@b)>0.1?1:0)}%
	\ifnum\pgf@temp@c=1\relax
	  \pgfmathsetmacro{\pgf@temp@c}{((#5)+2*(#1)-3*(#3))/((#5)+(#1)-2*(#3))}%
	  \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}%
	  \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{\pgfutil@tempdimb}{\pgf@path@lasty}%
	\fi
  \fi
  % 0/0
  \pgfmathsetmacro{\pgf@temp@a}{(#5)+(#1)-2*(#3)}%
  \pgfmathtruncatemacro{\pgf@temp@b}{(abs(\pgf@temp@a)>0.1?1:0)}%
  \ifnum\pgf@temp@b=1\relax
    \pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((#5)+2*(#1)-3*(#3))/(2*\pgf@temp@a)))}%
  \else	
    \pgfmathsetmacro{\pgf@temp@c}{0.5}%
  \fi	
  \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}%
  \pgfutil@tempdimb=\pgfmathresult pt\relax%
  \pgf@protocolsizes{\pgfutil@tempdimb}{\pgf@path@lasty}%
%  
% y code
  % first discriminant d1, must be \ne 0
  \pgfmathsetmacro{\pgf@temp@a}{(\pgf@path@lasty)-(#6)-3*(#2)+3*(#4)}%
  \pgfmathtruncatemacro{\pgf@temp@c}{(abs(\pgf@temp@a)>0.1?1:0)}%
  \ifnum\pgf@temp@c=1\relax
	% second discriminant d2, must be \ge 0
	\pgfmathsetmacro{\pgf@temp@b}{(\pgf@path@lasty)*(#6)-(#6)*(#2)+(#2)*(#2)-(\pgf@path@lasty)*(#4)-(#2)*(#4)+(#4)*(#4)}%
	\pgfmathtruncatemacro{\pgf@temp@c}{sign(\pgf@temp@b)}%
	\ifnum\pgf@temp@c<0
	\else
	  \pgfmathsetmacro{\pgf@temp@b}{sqrt(abs(\pgf@temp@b))}%
	  \pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((\pgf@path@lasty)-2*(#2)+(#4)-\pgf@temp@b)/\pgf@temp@a))}%	 
	  \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}%
	  \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{\pgf@path@lastx}{\pgfutil@tempdimb}%
	  \pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((\pgf@path@lasty)-2*(#2)+(#4)+\pgf@temp@b)/\pgf@temp@a))}%	 
	  \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}%
	  \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{\pgf@path@lastx}{\pgfutil@tempdimb}%
	\fi
  \else
    % third discriminant d3, must be \ne 0
    \pgfmathsetmacro{\pgf@temp@b}{abs((#6)+(#2)-2*(#4))}%
	\pgfmathtruncatemacro{\pgf@temp@c}{(abs(\pgf@temp@b)>0.1?1:0)}%
	\ifnum\pgf@temp@c=1\relax
	  \pgfmathsetmacro{\pgf@temp@c}{((#6)+2*(#2)-3*(#4))/((#6)+(#2)-2*(#4))}%
	  \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}%
	  \pgfutil@tempdimb=\pgfmathresult pt\relax%
      \pgf@protocolsizes{\pgf@path@lastx}{\pgfutil@tempdimb}%
	\fi
  \fi
  % 0/0
  \pgfmathsetmacro{\pgf@temp@a}{(#6)+(#2)-2*(#4)}%
  \pgfmathtruncatemacro{\pgf@temp@b}{(abs(\pgf@temp@a)>0.1?1:0)}%
  \ifnum\pgf@temp@b=1\relax
    \pgfmathsetmacro{\pgf@temp@c}{max(0,min(1,((#6)+2*(#2)-3*(#4))/(2*\pgf@temp@a)))}%
  \else	
    \pgfmathsetmacro{\pgf@temp@c}{0.5}%
  \fi	
  \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}%
  \pgfutil@tempdimb=\pgfmathresult pt\relax%
  \pgf@protocolsizes{\pgf@path@lastx}{\pgfutil@tempdimb}%
%  
  \pgf@protocolsizes{\pgf@path@lastx}{\pgf@path@lasty}%
  \pgf@protocolsizes{#5}{#6}%
  \endgroup
  \pgfsyssoftpath@curveto{\the#1}{\the#2}{\the#3}{\the#4}{\the#5}{\the#6}%
}
\endinput