% Copyright 2011 by Alain Matthes
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.


\def\fileversion{1.16 c}
\def\filedate{2011/06/01}


%<--------------------------------------------------------------------------–>
%                             init def point 
%<--------------------------------------------------------------------------–>
\newif\iftkz@polar\tkz@polarfalse
\newif\iftkz@pt@polar 
\newif\iftkz@pt@show 
\newif\iftkz@pt@noname

  
%<--------------------------------------------------------------------------–>
\pgfdeclareshape{cross}
{%
  \inheritsavedanchors[from=rectangle] % this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}
  \inheritanchor[from=rectangle]{mid}
  \inheritanchor[from=rectangle]{mid west}
  \inheritanchor[from=rectangle]{mid east}
  \inheritanchor[from=rectangle]{base}
  \inheritanchor[from=rectangle]{base west}
  \inheritanchor[from=rectangle]{base east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \foregroundpath{
% store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfpathmoveto{\pgfqpoint{0 pt}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{0 pt}{\pgf@yb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{0 pt}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{0 pt}}
 }
}
%<--------------------------------------------------------------------------–>
%                            tkzDefPoint
%<--------------------------------------------------------------------------–>

%<--------------------------------------------------------------------------–>
%                     macros complémentaires  pour def point
%<--------------------------------------------------------------------------–>
\def\tkz@parsecoordinate#1{%
\tkz@getseparator#1,\@nil
\iftkz@polar 
   \tkz@getfrompolar#1\@nil
\else
  \tkz@getfromcart#1\@nil
\fi
}
\def\tkz@getseparator#1,#2\@nil{%
\ifx\tkzempty#2\tkzempty%
   \tkz@polartrue
\else
   \tkz@polarfalse
\fi
}      
\def\tkz@getfrompolar#1:#2\@nil{
  \FPeval\tkz@a{(#1)}
  \FPeval\tkz@r{(#2)} 
\global\edef\tkz@polarrad{\tkz@r}
\global\edef\tkz@polarangle{\tkz@a}
} 
\def\tkz@getfromcart#1,#2\@nil{
  \FPeval\tkz@x{(#1)}
  \FPeval\tkz@y{(#2)}
\global\edef\tkz@absc{\tkz@x}
\global\edef\tkz@ord{\tkz@y}
}
%<--------------------------------------------------------------------------–>
% la macro defpoint les coordonnées cartésiennes ou polaires sont  traitées
% afin de pouvoir adaptées avec les unités choisies
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzDefPoint{\pgfutil@ifnextchar[{\tkzActivOff\tkz@DefPoint}{%
                                      \tkzActivOff\tkz@DefPoint[]}}

\def\tkz@DefPoint[#1](#2)#{% 
\tkz@parsecoordinate{#2}
\iftkz@polar
 \tkz@ptStar[polar](\tkz@polarangle,\tkz@polarrad){tkz@coord@temp}
 \else  
     \tkz@ptStar[](#2){tkz@coord@temp}
 \fi
\tkz@DefPointEnd[#1]}% 
\def\tkz@DefPointEnd[#1]#2{% 
 \coordinate[#1] (#2) at (tkz@coord@temp);
}
%<--------------------------------------------------------------------------–>
%                            tkzDefPoints
%<--------------------------------------------------------------------------–>
\def\tkzDefPoints{\pgfutil@ifnextchar[{\tkz@DefPoints}{%
                                       \tkz@DefPoints[]}}

\def\tkz@DefPoints[#1]#2{%
\begingroup
   \foreach \ptx/\pty/\name in {#2}{\tkzDefPoint[#1](\ptx,\pty){\name}}%
\endgroup
} %<--------------------------------------------------------------------------–>
%                Init pour Draw
%<--------------------------------------------------------------------------–>
\pgfkeys{%
setuppt/.cd,
size/.code    =  {\global\edef\tkz@pt@size{#1}},
color/.code   =  {\global\edef\tkz@pt@color{#1}},
fill/.code    =  {\global\edef\tkz@pt@fill{#1}}, 
shape/.code   =  {\global\edef\tkz@pt@shape{#1}}
} 
%<--------------------------------------------------------------------------–>
%                    tkzSetUpPoint  définit la forme d'un point
%<--------------------------------------------------------------------------–>
\def\tkzSetUpPoint{\pgfutil@ifnextchar[{\tkzActivOff\tkz@SetUpPoint}{%
                                         \tkzActivOff\tkz@SetUpPoint[]}}

\def\tkz@SetUpPoint[#1]{%
\pgfkeys{%
/setuppt/.cd,
size    =  \tkz@euc@pointsize,
color   =  \tkz@euc@pointcolor,
fill    =  \tkz@euc@pointcolor!50,
shape   =  \tkz@euc@pointshape}
\pgfqkeys{/setuppt}{#1}
\tikzset{point style/.style={draw         = \tkz@pt@color,
                             inner sep    = 0pt,
                             shape        = \tkz@pt@shape,
                             minimum size = \tkz@pt@size*\pgflinewidth,
                             fill         = \tkz@pt@fill}}}%
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
%                       Draw Point   
%<--------------------------------------------------------------------------–> 
%<--------------------------------------------------------------------------–> 
%\tikzset{/drawpoint/size/.style={minimum size=#1*\pgflinewidth}}
\pgfkeys{/drawpoint/.cd, 
  size/.code    = {\tikzset{point style/.append style={%
                   minimum size = #1*\pgflinewidth}}},
  color/.code    = {\tikzset{point style/.append style={%
                   draw = #1}}}, 
  shape/.code    = {\tikzset{point style/.append style={%
                   shape=#1}}},
  fill/.code    = {\tikzset{point style/.append style={%
                   fill=#1}}}                                     }
    
\def\tkzDrawPoint{\pgfutil@ifnextchar[{\tkz@DrawPoint}{\tkz@DrawPoint[]}} 
\def\tkz@DrawPoint[#1](#2){%
\begingroup 
\pgfkeys{/drawpoint/.cd}
\pgfqkeys{/drawpoint}{#1}    
\node[point style] at (#2) {};
\endgroup
}

%<--------------------------------------------------------------------------–> 
\def\tkzDrawPoints{\pgfutil@ifnextchar[{\tkz@drawpts}{\tkz@drawpts[]}} 
%<--------------------------------------------------------------------------–> 
\def\tkz@drawpts[#1](#2){%
\begingroup
\pgfkeys{/drawpoint/.cd}
\pgfqkeys{/drawpoint}{#1}        
\foreach \point in {#2}{%
   \node[point style] at (\point) {};}
\endgroup 
}
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
% rename
%<--------------------------------------------------------------------------–>
% \def\tkzRenamePoint{\pgfutil@ifnextchar[{\tkzActivOff\tkz@RenamePoint}{%
%                                          \tkzActivOff\tkz@RenamePoint[]}}  
% \def\tkz@RenamePoint[#1](#2)#{%
% \coordinate (tkz@coord@temp) at (#2);%
% \pgfextractx{\pgf@x}{\pgfpointanchor{tkz@coord@temp}{center}}
% \pgfextracty{\pgf@y}{\pgfpointanchor{tkz@coord@temp}{center}}
% \tkz@ax\pgf@x %
% \tkz@ay\pgf@y %
% \tkz@RenamePointEnd[#1]}% 
%<--------------------------------------------------------------------------–>
\def\tkzRenamePoint(#1)#2{\coordinate (#2) at (#1);}
\def\tkz@RenamePointEnd[#1]#2{\coordinate[#1] (#2) at (\tkz@ax,\tkz@ay);}
\def\tkzGetPoint#1{\coordinate  (#1) at (tkzPointResult);} 
\def\tkzGetPoints#1#2{\coordinate  (#1) at (tkzFirstPointResult);%
                      \coordinate  (#2) at (tkzSecondPointResult);}
\def\tkzGetFirstPoint#1{\coordinate  (#1) at (tkzFirstPointResult);}
\def\tkzGetSecondPoint#1{\coordinate  (#1) at (tkzSecondPointResult);}
\def\tkzDefShiftPointCoord[#1](#2)#3{%
\begin{scope}[shift={(#1)}]
  \coordinate  (#3) at (#2);
\end{scope}
}%

\def\tkzDefShiftPoint[#1](#2)#3{%
 \tkz@@extractxy{#1}
 \tkz@ax\pgf@x %
 \tkz@ay\pgf@y %   
\begin{scope}[shift={(\tkz@ax,\tkz@ay)}]
   \coordinate  (#3) at (#2);
\end{scope}
}
%<-------------------------------------------------------------------------–>
%   tkzLabelPoint          Affichage des LABELS pour un point
%<-------------------------------------------------------------------------–> 
% \newif\iftkz@mode@show 
% \tikzoption{show}{\tikz@addmode{\tkz@mode@showfalse}}  
\tikzset{label style/.style={\tkz@euc@pointpos,\tkz@euc@labelcolor,font=\normalsize}}
\def\tkzLabelPoint{\pgfutil@ifnextchar[{\tkz@LabelPoint}{\tkz@LabelPoint[]}} 
\def\tkz@LabelPoint[#1](#2)#3{\node[label style,#1] at (#2) {#3};}%

\def\tkzLabelPoints{\pgfutil@ifnextchar[{\tkz@LabelPoints}{%
                                         \tkz@LabelPoints[]}}% 
\def\tkz@LabelPoints[#1](#2){%
 \foreach \point in {#2}{
 \node[label style,#1] at (\point) {$\point$};}
}%
%<--------------------------------------------------------------------------–>
%                                 Coord  
%<--------------------------------------------------------------------------–>
\newif\if@tkz@coord@noxdraw
\newif\if@tkz@coord@noydraw
\pgfkeys{
/tkzprcoord/.cd,
  xlabel/.code    = {\global\edef\tkz@xlabel{#1}},%
  ylabel/.code    = {\global\edef\tkz@ylabel{#1}}, 
  xstyle/.code    = {\tikzset{xcoord style/.append style={#1}}},
  ystyle/.code    = {\tikzset{ycoord style/.append style={#1}}},
  noxdraw/.is if    = @tkz@coord@noxdraw,
  noxdraw/.default  = true,
  noydraw/.is if    = @tkz@coord@noydraw,
  noydraw/.default  = true,    
 /tkzprcoord/.unknown/.code   = {\let\searchname=\pgfkeyscurrentname
                                 \pgfkeysalso{\searchname/.try=#1,
                                   /tikz/\searchname/.retry=#1}} 
}
                              \def\tkzPointShowCoord{\pgfutil@ifnextchar[{\tkz@PointShowCoord}{%
                                         \tkz@PointShowCoord[]}}     
\def\tkz@PointShowCoord[#1](#2){%
\begingroup 
\pgfkeys{%
tkzprcoord/.cd,
  xlabel  = {},
  ylabel  = {},
  xstyle  = {},
  ystyle  = {},
  noxdraw = false,
  noydraw   = false
  }
\pgfqkeys{/tkzprcoord}{#1} 
\if@tkz@coord@noxdraw\else\draw[arrow coord style] (#2)--(#2 |- tkz@xline); \fi 
\if@tkz@coord@noydraw\else \draw[arrow coord style] (#2)--(#2 -| tkz@yline);\fi   
\ifx\tkzutil@empty\tkz@xlabel
\else
  \protected@edef\tkz@temp{%  
  \noexpand\path (#2)--(#2 |- tkz@xline)
  \noexpand node[xcoord style]}\tkz@temp {\tkz@xlabel};
\fi
\ifx\tkzutil@empty\tkz@ylabel
\else
  \protected@edef\tkz@temp{%
  \noexpand\path (#2)--(#2 -| tkz@yline)
  \noexpand node[ycoord style]}\tkz@temp {\tkz@ylabel};
\fi    
\endgroup
}

%<-------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
%                                       tkzPoint
%<--------------------------------------------------------------------------–>
\pgfkeys{
  tkzpt/.cd,  
  pos/.code          = {\def\tkz@pt@pos{#1}},
  size/.code         = {\def\tkz@pt@size{#1}},
  name/.code         = {\def\tkz@pt@name{#1}},
  namecolor/.code    = {\def\tkz@pt@namecolor{#1}},
  time/.code         = {\def\tkz@pt@time{#1}},
  color/.code        = {\def\tkz@pt@color{#1}},
  shape/.code        = {\def\tkz@pt@shape{#1}},
  polar/.is if       = tkz@pt@polar,
  polar/.default     = true,  
  noname/.is if      = tkz@pt@noname,
  noname/.default    = true
}

\def\tkz@node#1{\path[coordinate](\ptxa,\ptya) coordinate(#1);}  
\def\tkz@drawnode#1{\path[coordinate](\ptxa,\ptya) coordinate(#1);
\tkz@DrawPt{#1}
}

\def\tkz@draw@point#1{%
  \node[ inner sep    = 0pt,
         shape        = \tkz@pt@shape,%
         draw         = \tkz@pt@color,%
         minimum size = \tkz@pt@size*\pgflinewidth,%
         fill         = \tkz@pt@color] at (#1) {};}
          
\def\tkzPoint{\@ifstar\tkzptStar\tkzptNoStar}
\def\tkzptNoStar{\pgfutil@ifnextchar[{\tkz@ptNoStar}{\tkz@ptNoStar[]}} 
\def\tkz@ptNoStar[#1](#2,#3)#{%  
\pgfkeys{/tkzpt/.cd,
 noname    = false,%  pas de nom
 name      = {},%     le nom est vide 
 polar     = false,%
 namecolor = \tkz@euc@labelcolor,%  couleur du nom
 pos       = \tkz@euc@pointpos,% name
 shape     = \tkz@euc@pointshape,%
 color     = \tkz@euc@pointcolor,% couleur du point
 size      = \tkz@euc@pointsize,%
 time      = 0.5
} 
\pgfqkeys{/tkzpt}{#1}  
   \iftkz@pt@polar%
     \FPeval\tkz@x{(#2*cos(#3*\FPpi/180))}
     \FPeval\tkz@y{(#2*sin(#3*\FPpi/180))}
   \else
     \FPeval\tkz@x{(#2)}
     \FPeval\tkz@y{(#3)}
   \fi

 \FPadd{\ptxa}{\tkz@x}{-\tkz@init@xorigine}
 \FPadd{\ptya}{\tkz@y}{-\tkz@init@yorigine}
 \FPdiv{\ptxa}{\ptxa}{\tkz@init@xstep}
 \FPdiv{\ptya}{\ptya}{\tkz@init@ystep}
  \tkz@drawnode
}
% dessin du point (par défaut c'est un node donc il ne peut pas être scalé)
\def\tkz@DrawPt#1{%
  \iftkz@pt@noname%  pas de nom rien
  \else% si name={} alors on prend le nom du node sinon name
       \ifx\tkzutil@empty\tkz@pt@name\def\tkz@pt@name{$#1$}%
       \fi
       \protected@edef\tkz@temp{%
          \noexpand \node[\tkz@pt@pos]}\tkz@temp at (#1)%
          {\textcolor{\tkz@pt@namecolor} {\tkz@pt@name}};%    
  \fi
% on retrace ???  ici ou après le fi
\tkz@draw@point{#1}
}

%<--------------------------------------------------------------------------–>
%                                  Star version tkzPoint*   
%<--------------------------------------------------------------------------–>
\def\tkzptStar{\pgfutil@ifnextchar[{\tkz@ptStar}{\tkz@ptStar[]}} 
\def\tkz@ptStar[#1](#2,#3)#{%
\pgfkeys{/tkzpt/.cd,
 polar     = false,%
} 
\pgfqkeys{/tkzpt}{#1}  
\iftkz@pt@polar%
  \FPeval\tkz@x{(#3*cos(#2*\FPpi/180))}
  \FPeval\tkz@y{(#3*sin(#2*\FPpi/180))}
\else
  \FPeval\tkz@x{(#2)}
  \FPeval\tkz@y{(#3)}
\fi
\FPadd{\ptxa}{\tkz@x}{-\tkz@init@xorigine}
\FPadd{\ptya}{\tkz@y}{-\tkz@init@yorigine}
\FPdiv{\ptxa}{\ptxa}{\tkz@init@xstep}
\FPdiv{\ptya}{\ptya}{\tkz@init@ystep}
\tkz@node
}

%<--------------------------------------------------------------------------–>
%                                  Points   
%<--------------------------------------------------------------------------–>
\def\tkzPoints{\pgfutil@ifnextchar[{\tkz@Points}{\tkz@Points[]}}  
\def\tkz@Points[#1](#2){%
\begingroup
   \foreach \ptx/\pty/\name in {#2}{%
             \tkzPoint[#1](\ptx,\pty){\name}%
   }
\endgroup
}

   %<--------------------------------------------------------------------------–>
% macro d'affichage  % 
%<--------------------------------------------------------------------------–>
\pgfqkeys{/pointwith}
{ orthogonal/.code            =\def\tkz@numv{0},
  orthogonal normed/.code     =\def\tkz@numv{1},
  linear/.code                =\def\tkz@numv{2},
  linear normed/.code         =\def\tkz@numv{3},
  colinear/.code         args ={at #1} {\global\def\tkz@numv{4}
                                        \global\def\tkz@frompoint{#1}},
  K/.code                     =\def\tkz@Koeff{#1}
  } 

\def\tkzDefPointWith{\pgfutil@ifnextchar[{\tkz@DefPointWith}{%
           \tkz@DefPointWith[]}}
\def\tkz@DefPointWith[#1](#2){%
\pgfqkeys{/pointwith}{linear,K=1}
\pgfqkeys{/pointwith}{#1}
\ifcase\tkz@numv%
 % first case 0
   \tkz@VecKOrth[\tkz@Koeff](#2){tkzPointResult}
  \or% 1
   \tkz@VecKOrthNorm[\tkz@Koeff](#2){tkzPointResult}
  \or% 2
   \tkz@VecK[\tkz@Koeff](#2){tkzPointResult} 
  \or% 3
   \tkz@VecKNorm[\tkz@Koeff](#2){tkzPointResult}
  \or% 4
   \tkz@VecKCoLinear[\tkz@Koeff](#2,\tkz@frompoint){tkzPointResult} 
   \fi    
}

%<-------------------------------------------------------------------------–>
% % % Points aléatoires sur un segment, une droite, une demi-droite un cercle 
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
%                          les points aléatoires
%<--------------------------------------------------------------------------–>
\def\tkz@numrp{0}
\pgfkeys{/tkzDefRandPoint/.cd,
rectangle/.code args={#1 and #2}{\global\def\tkz@numrp{0}%
                                 \global\def\tkz@infl{#1}%
                                 \global\def\tkz@supr{#2}},
segment/.code  args={#1--#2}{\global\def\tkz@numrp{1}%
                              \global\def\tkz@start{#1}%
                              \global\def\tkz@end{#2}}, 
line/.code args={#1--#2}{\global\def\tkz@numrp{2}%
                          \global\def\tkz@start{#1}%
                          \global\def\tkz@end{#2}},  
circle/.code args={center #1 radius #2}{\def\tkz@numrp{3}%
                                          \global\def\tkz@center{#1}
                                          \global\def\tkz@rad{#2}}
} 

\def\tkzGetRandPointOn{\pgfutil@ifnextchar[{\tkz@DefRandPointOn}{%
           \tkz@DefRandPointOn[]}}
\def\tkz@DefRandPointOn[#1]#2{% 
\begingroup
\pgfkeys{/tkzDefRandPoint/.cd}   
\pgfqkeys{/tkzDefRandPoint}{#1}  
\ifcase\tkz@numrp%
 % first case 0
 \tkzRandPointOnRect(\tkz@infl,\tkz@supr){#2}  
  \or% 1
 \tkzRandPointOnSegment(\tkz@start,\tkz@end){#2}  
  \or% 2
 \tkzRandPointOnLine(\tkz@start,\tkz@end){#2} 
  \or% 3
 \tkzRandPointOnCircle(\tkz@center,\tkz@rad){#2} 
\fi    
\endgroup
}

\def\tkzRandPointOnRect(#1,#2)#3{% 
\tkz@@extractxy{#1}
    \pgf@xa=\pgf@x\relax%
    \pgf@ya=\pgf@y\relax%   
\tkz@@extractxy{#2}
    \pgf@xb=\pgf@x\relax%
    \pgf@yb=\pgf@y\relax%     
\FPadd{\tkz@a}{\pgf@sys@tonumber{\pgf@xb}}{-\pgf@sys@tonumber{\pgf@xa}}
\FPadd{\tkz@b}{\pgf@sys@tonumber{\pgf@yb}}{-\pgf@sys@tonumber{\pgf@ya}}
  \pgfmathparse{rnd}\global\let\myrndone\pgfmathresult 
    \pgfmathparse{rnd}\global\let\myrndtwo\pgfmathresult  
\path[coordinate] ($(#1)+(\myrndone*\tkz@a pt,%
                          \myrndtwo*\tkz@b pt)$) coordinate (#3);
                          } 

\def\tkzRandPointOnSegment(#1,#2)#3{% 
  \pgfmathparse{rnd}\global\let\myrnd\pgfmathresult 
\path[coordinate]  ($ (#1)!\myrnd!(#2) $) coordinate (#3);} 

\def\tkzRandPointOnLine(#1,#2)#3{% 
  \pgfmathparse{rand}\global\let\myrnd\pgfmathresult 
\path[coordinate]  ($ (#1)!\myrnd!(#2) $) coordinate (#3);}

\def\tkzRandPointOnCircle(#1,#2)#3{% 
\pgfmathrandominteger{\myrnd}{0}{360}
\tkz@ax#2 %
\FPeval\tkz@xa{\pgf@sys@tonumber{\tkz@ax}*cos(\myrnd*\FPpi/180)} 
\FPeval\tkz@xb{\pgf@sys@tonumber{\tkz@ax}*sin(\myrnd*\FPpi/180)}  
\path[coordinate]($(#1) + (\tkz@xa pt,\tkz@xb pt) $) coordinate (#3);
}

%<--------------------------------------------------------------------------–>
%                    Coordonnées d'un point 
%    result in #2x et #2y    #1 est le point et on récupère ses coordonnées
% usage soit A un point \tkzGetPointCoord(A){V} alors \Vx = xA et \Vy = yA
% en cm 
% tkzGetPointCoord avec [#1] cm ou bien pt !!! %<--------------------------------------------------------------------------–>
\def\tkzGetPointCoord(#1)#2{%
\begingroup
\pgfextractx{\pgf@x}{\pgfpointanchor{#1}{center}}
\pgfmathparse{\pgf@sys@tonumber{\pgf@x}/28.45274}
\global\let\tkzresultx\pgfmathresult
\global\expandafter\edef\csname #2x\endcsname{\tkzresultx}% 
\pgfextracty{\pgf@y}{\pgfpointanchor{#1}{center}}
\pgfmathparse{\pgf@sys@tonumber{\pgf@y}/28.45274}
\global\let\tkzresulty\pgfmathresult
\global\expandafter\edef\csname #2y\endcsname{\tkzresulty}
\endgroup
}  

\def\tkz@@extractxy#1{%
\pgfextractx{\pgf@x}{\pgfpointanchor{#1}{center}}
\pgfextracty{\pgf@y}{\pgfpointanchor{#1}{center}} 
}
\let\tkzGetPointxy\tkzGetPointCoord
%<--------------------------------------------------------------------------–>
  
\endinput
