% tkz-obj-eu-polygons.tex
% Copyright 2023  Alain Matthes
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
% This work has the LPPL maintenance status “maintained”.
% The Current Maintainer of this work is Alain Matthes.

\def\fileversion{5.02c}
\def\filedate{2023/02/03} 
\typeout{2023/02/03 5.02c tkz-obj-eu-polygons.tex} 
% bug in regular polygon side 2020/03/09
\makeatletter  
%<--------------------------------------------------------------------------–>
%                                 Polygon 
%<--------------------------------------------------------------------------–>
%<---------------------------   square  ------------------------------------–>
%
%<--------------------------------------------------------------------------–>
\def\tkzDefSquare(#1,#2){
\begingroup
  \tkzURotateAngle(#2,-90)(#1)
  \pgfnodealias{tkzFirstPointResult}{tkzPointResult}
  \tkzURotateAngle(#1, 90)(#2)
  \pgfnodealias{tkzSecondPointResult}{tkzPointResult}
\endgroup
}
%<---------------------   parallélogramme  ---------------------------------–>
%
%<--------------------------------------------------------------------------–>
\def\tkzDefParallelogram(#1,#2,#3){
\begingroup
\tkzDefPointWith[colinear= at #3](#2,#1)
\endgroup
}
%<---------------------   rectangle        ---------------------------------–>
%
%<--------------------------------------------------------------------------–>
\def\tkzDefRectangle{\pgfutil@ifnextchar[{\tkz@DefRectangle}%
                      {\tkz@DefRectangle[]}} 
\def\tkz@DefRectangle[#1](#2,#3){%
\begingroup
   \path[#1](#2) -| coordinate (tkzFirstPointResult) (#3) -| coordinate (tkzSecondPointResult) (#2);
\endgroup
}
%<-------------------------- gold rectangle -------------------------------–>
%
%<--------------------------------------------------------------------------–>
\def\tkzDefGoldRectangle(#1,#2){
\begingroup
  \tkzDefPointWith[K=-\tkzInvPhi](#2,#1)
  \pgfnodealias{tkzFirstPointResult}{tkzPointResult}
  \tkzDefPointWith[K=\tkzInvPhi](#1,#2)
  \pgfnodealias{tkzSecondPointResult}{tkzPointResult}
\endgroup
}
\let\tkzDefGoldenRectangle\tkzDefGoldRectangle
%<----------------------------   Regular Polygon   -------------------------–>
\def\tkz@numregpol{0}
\pgfkeys{/defregpoly/.cd,
      name/.store in      =  \tkz@regpolname,
      sides/.store in     =  \tkz@regpolsides,
      center/.code        =  \def\tkz@numregpol{0},
      side/.code          =  \def\tkz@numregpol{1},
      name/.default       =  P,
      sides/.default      =  5,
      center
} 
\def\tkzDefRegPolygon{\pgfutil@ifnextchar[{\tkz@DefRegPolygon}{\tkz@DefRegPolygon[]}}
\def\tkz@DefRegPolygon[#1](#2,#3){% 
\begingroup 
\pgfqkeys{/defregpoly}{#1}  
\ifcase\tkz@numregpol%
  \tkzRegPolygonCenter(#2,#3)
  \or%  
  \tkzRegPolygonSide(#2,#3)  
 \fi    
\endgroup
} 
\def\tkzRegPolygonCenter(#1,#2){
\begingroup 
   \foreach \v in {1,2,...,\tkz@regpolsides}
   {%
   \pgfmathsetmacro{\tkz@regangle}{360/\tkz@regpolsides*(\v-1)}  
   \tkzDefPointBy[rotation= center #1 angle \tkz@regangle](#2)   
   \pgfnodealias{\tkz@regpolname\v}{tkzPointResult}
   } 
\endgroup
}     
\def\tkzRegPolygonSide(#1,#2){
\begingroup  
% get the center 
\pgfmathsetmacro{\tkz@regangle}{360/\tkz@regpolsides*(\tkz@regpolsides-1)}
\pgfmathsetmacro{\tkz@regangleside}{(180-\tkz@regangle)/2}
\tkzDefMidPoint(#1,#2)
\pgfnodealias{tkz@tempPt}{tkzPointResult}
\tkz@@CalcLengthcm(tkz@tempPt,#1){tkz@len}
\pgfmathsetmacro{\tkz@inscriberadius}{%
  \tkz@len*tan(90*(\tkz@regpolsides-2)/\tkz@regpolsides)}
\tkzDefPointWith[orthogonal normed,K=\tkz@inscriberadius](tkz@tempPt,#2)
\pgfnodealias{tkz@RegPolCenter}{tkzPointResult}
\tkzRegPolygonCenter(tkz@RegPolCenter,#1)
\pgfnodealias{tkzPointResult}{tkz@RegPolCenter}
\endgroup
}
    

\makeatother
\endinput