% Copyright 2026 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
\usepgflibrary{shapes.multipart}
\unless\ifcsname pgfextset\endcsname
  \input tikzext-util.tex
\fi

\let\pgfnodeparttrbox\pgfnodeparttwobox
\let\pgfnodepartblbox\pgfnodepartthreebox
\let\pgfnodepartbrbox\pgfnodepartfourbox
\newif\ifpgfextcirclecrosssplitcustomfill
\pgfextset{
  circle cross split part fill/.code=%
    \def\pgf@lib@sh@ccs@list@fill{#1}%
    \pgfextcirclecrosssplitcustomfilltrue,%
  circle cross split uses custom fill/.is if=pgfextcirclecrosssplitcustomfill
}
\def\pgf@lib@sh@ccs@list@fill{none}%
\pgfdeclareshape{ext_circle cross split}{%
  \nodeparts{text,two,three,four}%
  \savedanchor\centerpoint{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}}%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/inner ysep}}%
    \pgf@x =\wd\pgfnodeparttextbox
    \pgf@yb=\dp\pgfnodeparttextbox
    \pgf@y=\dp\pgfnodeparttwobox
    \ifdim\pgf@yb>\pgf@y
      \pgf@y=\pgf@yb
    \fi
    \advance\pgf@x\pgf@xa
    \advance\pgf@y-\pgf@ya
    \advance\pgf@x.5\pgflinewidth
    \advance\pgf@y-.5\pgflinewidth
  }%
  \savedanchor\twoanchor{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}}%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/inner ysep}}%
    \advance\pgf@x.5\pgflinewidth
    \advance\pgf@x\pgf@xa
    \advance\pgf@y.5\pgflinewidth
    \advance\pgf@y\pgf@ya
    \pgf@yb\dp\pgfnodeparttextbox
    \pgf@yc\dp\pgfnodeparttwobox
    \ifdim\pgf@yb>\pgf@yc
      \pgf@yc\pgf@yb
    \fi
    \advance\pgf@y\pgf@yc
  }%
  \savedanchor\threeanchor{%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/inner ysep}}%
    \pgf@x\wd\pgfnodeparttextbox
    \pgf@yb\dp\pgfnodeparttextbox
    \pgf@yc\dp\pgfnodeparttwobox
    \ifdim\pgf@yb>\pgf@yc
      \pgf@yc\pgf@yb
    \fi
    \advance\pgf@y-\pgf@yc
    \advance\pgf@y-2\pgf@ya
    \advance\pgf@y-\pgflinewidth
    \pgf@yb\ht\pgfnodepartthreebox
    \pgf@yc\ht\pgfnodepartfourbox
    \ifdim\pgf@yb>\pgf@yc
      \pgf@yc\pgf@yb
    \fi
    \advance\pgf@y-\pgf@yc
    \advance\pgf@x-\wd\pgfnodepartthreebox
  }%
  \saveddimen\radius{%
    % height (upper):
    \pgf@y=\ht\pgfnodeparttextbox
    \ifdim\pgf@y<\ht\pgfnodeparttwobox
      \pgf@y=\ht\pgfnodeparttwobox
    \fi
    \ifdim\dp\pgfnodeparttextbox>\dp\pgfnodeparttwobox
      \advance\pgf@y by\dp\pgfnodeparttextbox
    \else
      \advance\pgf@y by\dp\pgfnodeparttwobox
    \fi
    % height (lower):
    \pgf@yb\ht\pgfnodepartthreebox
    \ifdim\pgf@yb<\ht\pgfnodepartfourbox
      \pgf@yb=\ht\pgfnodepartfourbox
    \fi
    \pgf@yc=\dp\pgfnodepartthreebox
    \ifdim\pgf@yc<\dp\pgfnodepartfourbox
      \advance\pgf@yb by\dp\pgfnodepartfourbox
    \else
      \advance\pgf@yb by\pgf@yc
    \fi
    \ifdim\pgf@yc>\pgf@y
      \pgf@y=\pgf@yc
    \fi
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/inner ysep}}%
    \advance\pgf@y2\pgf@ya
    %
    \pgf@x\wd\pgfnodeparttextbox
    \pgf@xa\wd\pgfnodepartthreebox
    \pgf@xb\wd\pgfnodeparttwobox
    \pgf@xc\wd\pgfnodepartfourbox
    \ifdim\pgf@xa>\pgf@x
      \pgf@x\pgf@xa
    \fi
    \ifdim\pgf@xb>\pgf@x
      \pgf@x\pgf@xb
    \fi
    \ifdim\pgf@xc>\pgf@x
      \pgf@x\pgf@xc
    \fi
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/inner xsep}}%
    \advance\pgf@x by 2\pgf@xa
    \ifdim\pgf@y>\pgf@x
      \pgf@x=\pgf@y
    \fi
    \advance\pgf@x by\pgflinewidth
    %
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    % from circle:
    \pgf@process{\pgfpointnormalised{}}%
    \ifdim\pgf@x>\pgf@y%
        \c@pgf@counta=\pgf@x%
        \ifnum\c@pgf@counta=0\relax%
        \else%
          \divide\c@pgf@counta by 255\relax%
          \pgf@xa=16\pgf@xa\relax%
          \divide\pgf@xa by\c@pgf@counta%
          \pgf@xa=16\pgf@xa\relax%
        \fi%
      \else%
        \c@pgf@counta=\pgf@y%
        \ifnum\c@pgf@counta=0\relax%
        \else%
          \divide\c@pgf@counta by 255\relax%
          \pgf@ya=16\pgf@ya\relax%
          \divide\pgf@ya by\c@pgf@counta%
          \pgf@xa=16\pgf@ya\relax%
        \fi%
    \fi%
    \pgf@x=\pgf@xa%
    %
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/minimum height}}%
    \ifdim\pgf@x<.5\pgf@xb
        \pgf@x=.5\pgf@xb
    \fi
    \ifdim\pgf@x<.5\pgf@yb
        \pgf@x=.5\pgf@yb
    \fi
    %
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \ifdim\pgf@xb<\pgf@yb
      \advance\pgf@x\pgf@yb
    \else
      \advance\pgf@x\pgf@xb
    \fi
  }%
  \inheritanchorborder[from=circle]%
  \inheritanchor[from=circle]{north}%
  \inheritanchor[from=circle]{north west}%
  \inheritanchor[from=circle]{north east}%
  \inheritanchor[from=circle]{center}%
  \inheritanchor[from=circle]{west}%
  \inheritanchor[from=circle]{east}%
  \inheritanchor[from=circle]{mid}%
  \inheritanchor[from=circle]{mid west}%
  \inheritanchor[from=circle]{mid east}%
  \inheritanchor[from=circle]{base}%
  \inheritanchor[from=circle]{base west}%
  \inheritanchor[from=circle]{base east}%
  \inheritanchor[from=circle]{south}%
  \inheritanchor[from=circle]{south west}%
  \inheritanchor[from=circle]{south east}%
  \anchor{two}{\twoanchor}%
  \anchor{three}{\threeanchor}%
  \anchor{four}{%
    \threeanchor
    \pgf@ya=\pgf@y
    \twoanchor
    \pgf@y=\pgf@ya
  }%
  \anchor{lower base}{%
    \threeanchor
    \pgf@ya=\pgf@y
    \centerpoint
    \pgf@y=\pgf@ya
  }
  \anchor{lower base west}{%
    \threeanchor
    \pgf@ya=\pgf@y
    \centerpoint
    \pgf@y=\pgf@ya
    \advance\pgf@x by-\radius
  }
  \anchor{lower base east}{%
    \threeanchor
    \pgf@ya=\pgf@y
    \centerpoint
    \pgf@y=\pgf@ya
    \advance\pgf@x by\radius
  }
  \anchor{lower mid}{%
    \threeanchor
    \pgf@ya=\pgf@y
    \centerpoint
    \pgf@y=\pgf@ya
    \pgfmathsetlength\pgf@ya{+.5ex}%
    \advance\pgf@y by\pgf@ya
  }
  \anchor{lower mid west}{%
    \threeanchor
    \pgf@ya=\pgf@y
    \centerpoint
    \pgf@y=\pgf@ya
    \advance\pgf@x by-\radius
    \pgfmathsetlength\pgf@ya{+.5ex}%
    \advance\pgf@y by\pgf@ya
  }
  \anchor{lower mid east}{%
    \threeanchor
    \pgf@ya=\pgf@y
    \centerpoint
    \pgf@y=\pgf@ya
    \advance\pgf@x by\radius
    \pgfmathsetlength\pgf@ya{+.5ex}%
    \advance\pgf@y by\pgf@ya
  }
  \inheritbackgroundpath[from=circle]
  \beforebackgroundpath{%
    \pgfutil@tempdima=\radius
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \ifdim\pgf@xb<\pgf@yb
      \advance\pgfutil@tempdima by-\pgf@yb
    \else
      \advance\pgfutil@tempdima by-\pgf@xb
    \fi
    \advance\pgfutil@tempdima by-.5\pgflinewidth%
    \pgfsetshortenstart{0pt}%
    \pgfsetshortenend{0pt}%
    \pgfsetarrows{-}%
    \pgfpathmoveto
      {\pgfpointadd{\centerpoint}{\pgfqpoint{-\pgfutil@tempdima}{0pt}}}%
    \pgfpathlineto
      {\pgfpointadd{\centerpoint}{\pgfqpoint{\pgfutil@tempdima}{0pt}}}%
    \pgfpathmoveto
      {\pgfpointadd{\centerpoint}{\pgfqpoint{0pt}{-\pgfutil@tempdima}}}%
    \pgfpathlineto
      {\pgfpointadd{\centerpoint}{\pgfqpoint{0pt}{\pgfutil@tempdima}}}%
    \pgfusepathqstroke
  }%
  \behindbackgroundpath{%
    \pgfutil@tempdima=\radius
    \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%  
    \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%  
    \ifdim\pgf@xb<\pgf@yb
      \advance\pgfutil@tempdima by-\pgf@yb
    \else
      \advance\pgfutil@tempdima by-\pgf@xb
    \fi
    \advance\pgfutil@tempdima by-.5\pgflinewidth%
    \ifpgfextcirclecrosssplitcustomfill%
      \pgf@lib@sh@rs@process@list{\pgf@lib@sh@ccs@list@fill}{4}%
      {%
        \pgfmathloop
           \ifnum\pgfmathcounter>4%
           \else%
             \pgf@lib@sh@getalpha\pgf@lib@sh@rs@number{\pgfmathcounter}%
              \edef\pgf@tempa
                {\csname pgf@lib@sh@rs@\pgf@lib@sh@rs@number @item\endcsname}%
              \ifx\pgf@tempa\pgf@lib@sh@rs@nonetext\else
                \pgfsetfillcolor{\pgf@tempa}%
                \ifcase\pgfmathcounter\or
                  \def\pgf@lib@sh@ccs@angle{90}\or
                  \def\pgf@lib@sh@ccs@angle{0}\or
                  \def\pgf@lib@sh@ccs@angle{180}\else
                  \def\pgf@lib@sh@ccs@angle{270}%
                \fi
                \pgfpathmoveto{\centerpoint}%
                \pgfpathlineto{\pgfpointadd{\centerpoint}
                  {\pgfqpointpolar{\pgf@lib@sh@ccs@angle}{\pgfutil@tempdima}}}%
                \pgfpatharc{+\pgf@lib@sh@ccs@angle}{\pgf@lib@sh@ccs@angle+90}
                  {+\pgfutil@tempdima}%
                \pgfpathclose
                \pgfusepathqfill
              \fi
        \repeatpgfmathloop
      }%
    \fi
  }%
}
%%% Compatibility
\tikzextset{
  /tikz-ext/compat/add library*={shapes.circlecrosssplit}{shapes}{pre 0.6},
  compat/shapes.circlecrosssplit/warn/.code={%
    \tikzextutil@compatwarning@key{shapes}{pre 0.6}{/pgf/circle cross split part fill}{/pgf/ext/circle cross split part fill}%
    \tikzextutil@compatwarning@key{shapes}{pre 0.6}{/pgf/circle cross split part custom fill}[true]{/pgf/ext/circle cross split part fill}%
    \tikzextutil@compat@cloneshape{circle cross split}{text,north,north west,north east,center,west,east,mid,mid west,mid east,base,base west,base east,south,south west,south east,center,two,three,four,lower mid,lower base,lower mid east,lower base east,lower mid west,lower base west}%
    \def\tikzext@temp{\tikzextutil@compatmaybewarning{shape 'circle cross split'}{'ext_circle cross split'}{shapes = pre 0.6}}%
    \expandafter\tikzextutil@prefix@macrotomacro\csname pgf@sh@s@circle cross split\endcsname\tikzext@temp
  },
  compat/shapes.circlecrosssplit/pre 0.6/.code={%
    \pgfkeysdef{/pgf/circle cross split part fill}{\pgfkeysvalueof{/pgf/ext/circle cross split part fill/.@cmd}##1\pgfeov}%
    \pgfkeysdef{/pgf/circle cross split part custom fill}{\pgfkeysvalueof{/pgf/circle cross split custom part fill/.@cmd}##1\pgfeov}%
    \pgfkeyssetvalue{/pgf/circle cross split part custom flll/.@def}{true}%
    \tikzextutil@compat@cloneshape{circle cross split}{text,north,north west,north east,center,west,east,mid,mid west,mid east,base,base west,base east,south,south west,south east,center,two,three,four,lower mid,lower base,lower mid east,lower base east,lower mid west,lower base west}%
  },
  compat/shapes.circlecrosssplit/\pgfkeysvalueof{/tikz/ext/compat/shapes}/.try
}