% 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.13 c}
\def\filedate{2011/01/19}   

 
%<--------------------------------------------------------------------------–>
   
%<--------------------------------------------------------------------------–>
%                          les lignes
%<--------------------------------------------------------------------------–>
\def\tkz@numl{0}
\pgfkeys{/tkzDefLine/.cd,
  mediator/.code         ={\global\def\tkz@numl{0}},
  perpendicular/.code args={through #1} {\global\def\tkz@numl{1}%
                                         \global\def\tkz@through{#1}},
  orthogonal/.code args={through #1} {\global\def\tkz@numl{1}%
                                         \global\def\tkz@through{#1}}, 
  parallel/.code args={through #1}{\global\def\tkz@numl{2}%
                                   \global\def\tkz@through{#1}},   
  bisector/.code         ={\global\def\tkz@numl{3}},
  bisector out/.code     ={\global\def\tkz@numl{4}},
  K/.code                =\def\tkz@koeff{#1} 
} 

\def\tkzDefLine{\pgfutil@ifnextchar[{\tkz@DefLine}{%
           \tkz@DefLine[]}}
\def\tkz@DefLine[#1](#2){% 
\begingroup
\pgfkeys{/tkzDefLine/.cd,K=1}  
\pgfqkeys{/tkzDefLine}{#1}  
\ifcase\tkz@numl%
 % first case 0
 \tkzDefMediatorLine(#2)  
  \or% 1
  \tkzDefOrthLine[\tkz@koeff](#2)  
  \or% 2
   \tkzDefLineLL(#2)
  \or% 3
  \tkzDefBisectorLine(#2)
  \or% 4
  \tkzDefBisectorOutLine(#2)
  \fi    
\endgroup
}
%<--------------------------------------------------------------------------–>
%                            tkzLineLL    revoir out !!
%<--------------------------------------------------------------------------–>
\def\tkzDefLineLL(#1,#2){% 
\begingroup% recherche d'un vecteur tq #2#3=#4tkz@point
   \pgfpointdiff{\pgfpointanchor{#1}{center}}%
                {\pgfpointanchor{#2}{center}}%
   \pgf@xa=\pgf@x%
   \pgf@ya=\pgf@y%
   \path[coordinate](\tkz@through)--+(\pgf@xa,\pgf@ya)%
         coordinate (tkzPointResult);
\endgroup}% 
%<--------------------------------------------------------------------------–>
%                        tkzOrthLine 
%<--------------------------------------------------------------------------–>
\def\tkzDefOrthLine{\pgfutil@ifnextchar[{\tkz@DefOrthLine}{%
                                         \tkz@DefOrthLine[1]}} 
 \def\tkz@DefOrthLine[#1](#2,#3){% 
\begingroup
   \tkzVecKOrth(#2,#3){tkz@OLtmp}
   \tkz@VecKCoLinear[#1](#2,tkz@OLtmp,\tkz@through){tkzPointResult} 
\endgroup
} 
%<--------------------------------------------------------------------------–>
%                            tkzMediatorLine
%<--------------------------------------------------------------------------–>
\def\tkzDefMediatorLine(#1,#2){% 
\begingroup
  \path (#1) -- (#2) coordinate[pos=.5](tkzPointResult); 
  \tkzURotateAngle(#1,60)(#2) \tkzGetPoint{tkzFirstPointResult}
  \tkzURotateAngle(#2,60)(#1) \tkzGetPoint{tkzSecondPointResult}
\endgroup
}
%<--------------------------------------------------------------------------–>
%              BisectorLine   % pb avec un angle plat
%<--------------------------------------------------------------------------–>
\def\tkzDefBisectorLine(#1,#2,#3){% 
\begingroup
    \tkzDuplicateLen(#2,#1)(#2,#3) \tkzGetPoint{tkz@tmp}
    \tkzURotateAngle(tkz@tmp,60)(#1) \tkzGetPoint{tkzPointResult}
    % \tkzVecKNorm[5](#2,#1){tkz@pt1}
    % \tkzVecKNorm[5](#2,#3){tkz@pt2}
    % \tkzDefEquilateral(tkz@pt2,tkz@pt1)
    % \tkzVecKNorm(#2,tkzPointResult){tkzPointResult}
\endgroup
}
%<--------------------------------------------------------------------------–>
%              Out BisectorLine
%<--------------------------------------------------------------------------–>
\def\tkzDefBisectorOutLine(#1,#2,#3){% 
\begingroup
    \tkzVecKNorm(#2,#1){tkz@pt1} 
    \tkzVecKNorm[-1](#2,#3){tkz@pt2}
    \tkzDefEquilateral(tkz@pt2,tkz@pt1)\tkzGetPoint{tkz@pt3}
    \tkzVecKNorm(#2,tkz@pt3){tkzPointResult}
\endgroup
} 
%<-------------------------------------------------------------------------–> 
\def\tkzLabelLine{\pgfutil@ifnextchar[{\tkz@AddLabelLine}{%
                                          \tkz@AddLabelLine[]}} 
\def\tkz@AddLabelLine[#1](#2,#3)#4{
     \path  (#2) to node[#1]{#4}(#3);
} 
%<--------------------------------------------------------------------------–>
%                                Setup   Line
%<--------------------------------------------------------------------------–>

\tikzset{line style/.style={%
           line width = \tkz@euc@linewidth,
           color      = \tkz@euc@linecolor,
           style      = \tkz@euc@linestyle,
           add        = {\tkz@euc@lineleft} and {\tkz@euc@lineright}}}   
\pgfkeys{%
setupline/.cd,
line width/.code   =     {\global\edef\tkz@line@lw{#1}},
color/.code        =     {\global\edef\tkz@line@color{#1}},
style/.code        =     {\global\edef\tkz@line@style{#1}},
add/.code args     =     {#1 and #2} {\global\edef\tkz@line@left{#1}%
                                      \global\edef\tkz@line@right{#2} }
} 
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
\def\tkzSetUpLine{\pgfutil@ifnextchar[{\tkzActivOff\tkz@SetUpLine}{%
                                         \tkzActivOff\tkz@SetUpLine[]}}
%<--------------------------------------------------------------------------–>
\def\tkz@SetUpLine[#1]{%
\tkzActivOff
\pgfkeys{%
setupline/.cd,
line width   = \tkz@euc@linewidth,
color        = \tkz@euc@linecolor,
style        = \tkz@euc@linestyle,
add          = {\tkz@euc@lineleft} and {\tkz@euc@lineright}}  
\pgfqkeys{/setupline}{#1}
\tikzset{line style/.style={%
                   color       = \tkz@line@color,
                   line width  = \tkz@line@lw,
                   style       = \tkz@line@style,
                   add         = {\tkz@line@left} and {\tkz@line@right}
                   }}
}%   
%<--------------------------------------------------------------------------–>
%<--------------------------------------------------------------------------–>
%                              Draw line
%<--------------------------------------------------------------------------–>
\pgfkeys{%
tkzdrawline/.cd,
start/.code =  {\def\tkz@line@start{#1}},%
end/.code =    {\def\tkz@line@end{#1}},
start style/.code ={\tikzset{tkzstartstyle/.style={#1}}},
end style/.code ={\tikzset{tkzendstyle/.style={#1}}},  
 /tkzdrawline/.unknown/.code   = {\let\searchname=\pgfkeyscurrentname
                              \pgfkeysalso{\searchname/.try=#1,
                                   /tikz/\searchname/.retry=#1}} 
                                   }       

\def\tkzDrawLine{\pgfutil@ifnextchar[{\tkz@DrawLine}{%
                                      \tkz@DrawLine[]}} 
\def\tkz@DrawLine[#1](#2,#3){%
\begingroup
\pgfkeys{%
tkzdrawline/.cd,
start = {} , 
end   = {} , 
start style={},
end style={},}
\pgfqkeys{/tkzdrawline}{#1}
\draw[ line style,/tkzdrawline/.cd,#1] (#2) to%
       node [at start,left,/tkzdrawline/.cd,tkzstartstyle] {\tkz@line@start}%
       node [at end,right,/tkzdrawline/.cd,tkzendstyle] {\tkz@line@end} (#3);
\endgroup
}% 
%<--------------------------------------------------------------------------–>
\def\tkz@multiLines#1 #2\@nil{% 
 \protected@edef\tkz@temp{
   \noexpand \tkzDrawLine[\tkz@optline](#1)}\tkz@temp% 
   \def\tkz@nextArg{#2}%
   \ifx\tkzutil@empty\tkz@nextArg
     \let\next\@gobble
   \fi
   \next#2\@nil
}
%<--------------------------------------------------------------------------–>
\def\tkzDrawLines{\pgfutil@ifnextchar[{\tkz@DrawLines}{%
           \tkz@DrawLines[]}}  
\def\tkz@DrawLines[#1](#2){%
\global\edef\tkz@optline{#1} 
\begingroup
   \let\next\tkz@multiLines
   \next#2 \@nil %    
\endgroup     
}%    

 %<--------------------------------------------------------------------------–>
%<---------------------------    The SHOW   --------------------------------–>
%<--------------------------------------------------------------------------–>
\global\def\tkz@numsh{0}
\pgfkeys{/show/.cd,
  mediator/.code       =\global\def\tkz@numsh{0},
  perpendicular/.code args={through #1} {\global\def\tkz@numsh{1}%
                                         \global\def\tkz@through{#1}}, 
  orthogonal/.code args={through #1} {\global\def\tkz@numsh{1}%
                                         \global\def\tkz@through{#1}},
  parallel/.code args={through #1}{\global\def\tkz@numsh{2}%
                                   \global\def\tkz@through{#1}},   
  bisector/.code         = \global\def\tkz@numsh{3},
  K/.code                = \def\tkz@koeff{#1}, 
  length/.code           = \def\tkz@show@length{#1},
  ratio/.code            = \def\tkz@show@ratio{#1},
  gap/.code              = \def\tkz@show@gap{#1},
  size/.code             = \def\tkz@show@size{#1},
  /show/.unknown/.code   = {\let\searchname=\pgfkeyscurrentname
                              \pgfkeysalso{\searchname/.try=#1,
                                   /compass/\searchname/.retry=#1,
                                   /tikz/\searchname/.retry=#1}}
                                   } 

\def\tkzShowLine{\pgfutil@ifnextchar[{\tkz@ShowLine}{%
           \tkz@ShowLine[]}}
\def\tkz@ShowLine[#1](#2){% 
\begingroup
\pgfqkeys{/show}{K=1,gap=2,ratio=.5,length=1,size=1}  
\pgfqkeys{/show}{#1}  
\ifcase\tkz@numsh%
 % first case 0
 \tkzShowMediatorLine[#1](#2)  
  \or% 1
  \tkzShowOrthLine[#1](#2)(\tkz@through)  
  \or% 2
   \tkzShowLLLine[#1](#2)(\tkz@through)
  \or% 3
  \tkzShowBisectorLine[#1](#2)
\fi
\endgroup
}

\def\tkzShowMediatorLine{\pgfutil@ifnextchar[{\tkz@ShowMediatorLine}{%
                                          \tkz@ShowMediatorLine[]}}  
\def\tkz@ShowMediatorLine[#1](#2,#3){%
\begingroup
\pgfkeys{%
show/.cd,
gap    = 2,
ratio  = .5,
length = 1
}
\pgfkeys{show/.cd,#1}  
 \path (#2) -- (#3) coordinate[pos=.5](tkzmidpoint);
 \tkzURotateAngle(#2,60)(#3)\tkzGetPoint{tkzFirstPointResult}
 \tkzURotateAngle(#3,60)(#2)\tkzGetPoint{tkzSecondPointResult} 
 \tkz@VecKOrthNorm[1](tkzmidpoint,#2){MED@tmp1}
 \tkz@VecKOrthNorm[1](tkzmidpoint,#3){MED@tmp2}
 \tkz@VecKNorm[\tkz@show@gap](tkzmidpoint,MED@tmp1){MED@1}
 \tkz@VecKNorm[\tkz@show@gap](tkzmidpoint,MED@tmp2){MED@2} 
 \tkzCompass[#1,length=\tkz@show@ratio*\tkz@show@length](#2,MED@1)
 \tkzCompass[#1](#3,MED@1)
 \tkzCompass[#1,length=\tkz@show@ratio*\tkz@show@length](#2,MED@2)
 \tkzCompass[#1](#3,MED@2)
\endgroup
}
\def\tkzShowLLLine{\pgfutil@ifnextchar[{\tkz@ShowLLLine}{%
                                        \tkz@ShowLLLine[]}}  
\def\tkz@ShowLLLine[#1](#2,#3)(#4){%
\begingroup
\pgfkeys{show/.cd,gap=2,ratio=.75,length=1}
\pgfkeys{show/.cd,#1}   
   \tkz@VecKCoLinear[1](#2,#3,#4){tkz@lltmp}
   \tkzCompass[#1](#4,tkz@lltmp)
   \tkzCompass[#1,length=\tkz@show@ratio*\tkz@show@length](#3,tkz@lltmp)
\endgroup
} 

%<--------------------------------------------------------------------------–>
%                        tkzLineOrth 
%<--------------------------------------------------------------------------–>
% pas de projection ortho car le point peut être sur la droite.
% manque les tests . Il faudrait voir si on peut projeter et choisir
\def\tkzShowOrthLine{\pgfutil@ifnextchar[{\tkz@ShowOrthLine}{%
                                          \tkz@ShowOrthLine[]}} 
\def\tkz@ShowOrthLine[#1](#2,#3)(#4){% 
 \begingroup
\pgfkeys{show/.cd,ratio=.75,length=1,gap=-1} % ????
\pgfkeys{show/.cd,#1}  %????
  \tkzVecKOrth(#2,#3){tkz@OLtmp}
  \tkz@VecKCoLinear[1](#2,tkz@OLtmp,#4){tkzPointCo}
  \tkzInterLL(#2,#3)(#4,tkzPointCo)\tkzGetPoint{tkzPOpoint}
  \tkzCalcLength(#4,tkzPOpoint)\tkzGetLength{tkz@mathLen}
  \tkz@VecKNorm[1](#2,#3){PO@tmp}
  \tkz@VecKCoLinear[1](#2,PO@tmp,tkzPOpoint){PO@tmp2}
  \tkz@VecKCoLinear[-1](#2,PO@tmp,tkzPOpoint){PO@tmp1} 
  \tkz@VecKCoLinear[2](tkzPOpoint,PO@tmp1,tkzPOpoint){PO@1}
  \tkz@VecKCoLinear[2](tkzPOpoint,PO@tmp2,tkzPOpoint){PO@2}
  \ifdim\tkz@mathLen pt>10 pt\relax
      \tkz@VecKNorm[1](#4,tkzPOpoint){PO@tmp1}
    \else
      \tkz@VecKOrthNorm[1](tkzPOpoint,PO@2){PO@tmp1}
   \fi
  \tkz@VecKCoLinear[-\tkz@show@gap](PO@tmp1,tkzPOpoint,tkzPOpoint){PO@3}
  \tkzCompass[#1,length=\tkz@show@ratio *\tkz@show@length](#4,PO@1)
  \tkzCompass[#1,length=\tkz@show@ratio *\tkz@show@length](#4,PO@2)
  \tkzCompass[#1,length=\tkz@show@ratio *\tkz@show@length](PO@1,PO@3)
  \tkzCompass[#1,length=\tkz@show@length](PO@2,PO@3) 
  \endgroup
 }    
%<-------------------------------------------------------------------------–> 
%    bisector Line
%<-------------------------------------------------------------------------–> 
\def\tkzShowBisectorLine{\pgfutil@ifnextchar[{\tkz@ShowBisectorLine}{%
                                          \tkz@ShowBisectorLine[]}}   
\def\tkz@ShowBisectorLine[#1](#2,#3,#4){% 
\begingroup
\pgfkeys{show/.cd,gap=2,ratio=.5,length=1,size=1}
\pgfkeys{show/.cd,#1}    
    \tkzVecKNorm(#3,#2){tkz@pt1} 
    \tkzVecKNorm(#3,#4){tkz@pt2}
    \tkzDefEquilateral(tkz@pt2,tkz@pt1)\tkzGetPoint{tkz@pt3}
    \tkzVecKNorm(#3,tkz@pt3){tkzBisPoint}
    \tkzVecKNorm[\tkz@show@size](#3,#2){BI@1}
    \tkzVecKNorm[\tkz@show@size](#3,#4){BI@2}  
    \tkzVecK[\tkz@show@gap](#3,tkzBisPoint){tkzBisPoint}
    \tkzCompass[#1,length=\tkz@show@ratio *\tkz@show@length](#3,BI@1)                  
    \tkzCompass[#1,length=\tkz@show@ratio *\tkz@show@length](#3,BI@2)                                            
    \tkzCompass[#1,length=\tkz@show@length](BI@1,tkzBisPoint)
    \tkzCompass[#1,length=\tkz@show@ratio *\tkz@show@length](BI@2,tkzBisPoint)  
  \endgroup    
}

%<-------------------------------------------------------------------------–> 
%<-------------------------------------------------------------------------–> 

\endinput
