%% The LaTeX package tcolorbox - version 4.12 (2018/01/12)
%% tcbskinsjigsaw.code.tex: Code for colorboxes with different skins
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2018 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% 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 `author-maintained'.
%%
%% This work consists of all files listed in README
%%
\tcb@set@library@version{4.12}

\tcbuselibrary{skins}

\def\tcb@drawframe@pathjigsaw{%
  \tcb@pathboundary{tcb fill frame}{\tcb@boundaryframe@standardjigsaw}%
}

\def\tcb@boundary@pathfirstjigsaw@A{%
  \tcbdimto\tcb@xa{\tcb@width-\kvtcb@right@rule}%
  \tcbdimto\tcb@ya{\tcb@height-\kvtcb@top@rule}%
  \pgfpathmoveto{\pgfpointorigin}%
  \tcb@arc@out@NW\pgfpathlineto{\pgfqpoint{0pt}{\tcb@height}}%
  \tcb@arc@out@NE\pgfpathlineto{\pgfqpoint{\tcb@width}{\tcb@height}}%
  \tcb@arc@zpt\pgfpathlineto{\pgfqpoint{\tcb@width}{0pt}}%
  \pgfpathlineto{\pgfqpoint{\tcb@xa}{0pt}}%
  \tcb@arc@ins@NE\pgfpathlineto{\pgfqpoint{\tcb@xa}{\tcb@ya}}%
  \tcb@arc@ins@NW\pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{\tcb@ya}}%
  \tcb@arc@zpt\pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{0pt}}%
  \pgfpathclose%
}

\def\tcb@boundary@pathfirstjigsaw@B{%
  \tcbdimto\tcb@xa{\tcb@width-\kvtcb@right@rule}%
  \tcbdimto\tcb@ya{\kvtcb@bottom@rule+\tcb@innerheight}%
  \pgfpathmoveto{\pgfpointorigin}%
  \tcb@arc@out@NW\pgfpathlineto{\pgfqpoint{0pt}{\tcb@height}}%
  \tcb@arc@out@NE\pgfpathlineto{\pgfqpoint{\tcb@width}{\tcb@height}}%
  \tcb@arc@zpt\pgfpathlineto{\pgfqpoint{\tcb@width}{0pt}}%
  \pgfpathlineto{\pgfqpoint{\tcb@xa}{0pt}}%
  \pgfpathlineto{\pgfqpoint{\tcb@xa}{\tcb@ya}}%
  \pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{\tcb@ya}}%
  \pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{0pt}}%
  \pgfpathclose%
}

\def\tcb@drawframe@pathfirstjigsaw{%
  \tcb@pathboundary{tcb fill frame}{%
    \pgfseteorule%
    \iftcb@hasTitle%
      \iftcb@titlefilled%
        \ifdim\dimexpr\kvtcb@title@rule>0pt\relax%
          \tcb@boundary@pathfirstjigsaw@B%
          \tcb@boundarytitle@standard%
        \else%
          \tcb@boundary@pathfirstjigsaw@A%
        \fi%
      \else%
        \tcb@boundary@pathfirstjigsaw@B%
      \fi%
    \else%
      \tcb@boundary@pathfirstjigsaw@A%
    \fi%
  }%
}

\def\tcb@boundary@pathmiddlejigsaw@A{%
  \tcbdimto\tcb@xa{\tcb@width-\kvtcb@right@rule}%
  \pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{\kvtcb@left@rule}{\tcb@height}}%
  \pgfpathrectangle{\pgfqpoint{\tcb@xa}{0pt}}{\pgfqpoint{\kvtcb@right@rule}{\tcb@height}}%
}

\def\tcb@boundary@pathmiddlejigsaw@B{%
  \tcbdimto\tcb@xa{\tcb@width-\kvtcb@right@rule}%
  \tcbdimto\tcb@ya{\tcb@height-\kvtcb@top@rule}%
  \pgfpathmoveto{\pgfpointorigin}%
  \tcb@arc@zpt\pgfpathlineto{\pgfqpoint{0pt}{\tcb@height}}%
  \pgfpathlineto{\pgfqpoint{\tcb@width}{\tcb@height}}%
  \pgfpathlineto{\pgfqpoint{\tcb@width}{0pt}}%
  \pgfpathlineto{\pgfqpoint{\tcb@xa}{0pt}}%
  \pgfpathlineto{\pgfqpoint{\tcb@xa}{\tcb@ya}}%
  \pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{\tcb@ya}}%
  \pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{0pt}}%
  \pgfpathclose%
}

\def\tcb@boundary@pathmiddlejigsaw@C{%
  \tcbdimto\tcb@xa{\tcb@width-\kvtcb@right@rule}%
  \tcbdimto\tcb@ya{\kvtcb@bottom@rule+\tcb@innerheight}%
  \pgfpathmoveto{\pgfpointorigin}%
  \tcb@arc@zpt\pgfpathlineto{\pgfqpoint{0pt}{\tcb@height}}%
  \pgfpathlineto{\pgfqpoint{\tcb@width}{\tcb@height}}%
  \pgfpathlineto{\pgfqpoint{\tcb@width}{0pt}}%
  \pgfpathlineto{\pgfqpoint{\tcb@xa}{0pt}}%
  \pgfpathlineto{\pgfqpoint{\tcb@xa}{\tcb@ya}}%
  \pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{\tcb@ya}}%
  \pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{0pt}}%
  \pgfpathclose%
}

\def\tcb@drawframe@pathmiddlejigsaw{%
  \tcb@pathboundary{tcb fill frame}{%
    \pgfseteorule%
    \iftcb@hasTitle%
      \iftcb@titlefilled%
        \ifdim\dimexpr\kvtcb@title@rule>0pt\relax%
          \tcb@boundary@pathmiddlejigsaw@C%
          \tcb@arc@zpt%
          \tcbdimto\tcb@ya{\kvtcb@bottom@rule+\tcb@innerheight+\kvtcb@title@rule}%
          \tcbdimto\tcb@xb{\tcb@width-\kvtcb@right@rule}%
          \tcbdimto\tcb@yb{\tcb@height-\kvtcb@top@rule}%
          \pgfpathrectanglecorners{\pgfqpoint{\kvtcb@left@rule}{\tcb@ya}}{\pgfqpoint{\tcb@xb}{\tcb@yb}}%
        \else%
          \tcb@boundary@pathmiddlejigsaw@B%
        \fi%
      \else%
        \tcb@boundary@pathmiddlejigsaw@C%
      \fi%
    \else%
      \tcb@boundary@pathmiddlejigsaw@A%
    \fi%
  }%
}

\def\tcb@drawframe@pathlastjigsaw{%
  \tcb@pathboundary{tcb fill frame}{%
    \pgfseteorule%
    \iftcb@hasTitle%
      \iftcb@titlefilled%
        \ifdim\dimexpr\kvtcb@title@rule>0pt\relax%
          \tcb@boundaryframe@pathlast%
          \tcb@arc@zpt%
          \tcbdimto\tcb@ya{\kvtcb@bottom@rule+\tcb@innerheight+\kvtcb@title@rule}%
          \tcbdimto\tcb@xb{\tcb@width-\kvtcb@right@rule}%
          \tcbdimto\tcb@yb{\tcb@height-\kvtcb@top@rule}%
          \pgfpathrectanglecorners{\pgfqpoint{\kvtcb@left@rule}{\tcb@ya}}{\pgfqpoint{\tcb@xb}{\tcb@yb}}%
          \tcb@boundaryinterior@title@standard%
        \else%
          \tcb@boundaryframe@pathlast%
          \tcb@boundary@base{\kvtcb@left@rule}{\kvtcb@bottom@rule}%
            {\tcb@width-\kvtcb@right@rule}{\tcb@height-\kvtcb@top@rule}%
            {\tcb@arc@ins@SW}{\tcb@arc@zpt}{\tcb@arc@zpt}{\tcb@arc@ins@SE}%
        \fi%
      \else%
        \tcb@boundaryframe@pathlast%
      \fi%
    \else%
      \tcbdimto\tcb@xa{\tcb@width-\kvtcb@right@rule}%
      \pgfpathmoveto{\pgfpointorigin}%
      \tcb@arc@zpt\pgfpathlineto{\pgfqpoint{0pt}{\tcb@height}}%
      \pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{\tcb@height}}%
      \tcb@arc@ins@SW\pgfpathlineto{\pgfqpoint{\kvtcb@left@rule}{\kvtcb@bottom@rule}}%
      \tcb@arc@ins@SE\pgfpathlineto{\pgfqpoint{\tcb@xa}{\kvtcb@bottom@rule}}%
      \tcb@arc@zpt\pgfpathlineto{\pgfqpoint{\tcb@xa}{\tcb@height}}%
      \pgfpathlineto{\pgfqpoint{\tcb@width}{\tcb@height}}%
      \tcb@arc@out@SE\pgfpathlineto{\pgfqpoint{\tcb@width}{0pt}}%
      \tcb@arc@out@SW\pgfpathclose%
    \fi%
  }%
}


\def\tcb@draw@shadowjigsaw@unbroken{%
  \let\tcb@shadow=\tcb@shadow@unbroken%
  \begin{tcbinvclipframe}%
  \kvtcb@shadow%
  \end{tcbinvclipframe}%
}

\def\tcb@draw@shadowjigsaw@first{%
  \let\tcb@shadow=\tcb@shadow@first%
  \begin{tcbinvclipframe}%
  \kvtcb@shadow%
  \end{tcbinvclipframe}%
}

\def\tcb@draw@shadowjigsaw@middle{%
  \let\tcb@shadow=\tcb@shadow@middle%
  \begin{tcbinvclipframe}%
  \kvtcb@shadow%
  \end{tcbinvclipframe}%
}

\def\tcb@draw@shadowjigsaw@last{%
  \let\tcb@shadow=\tcb@shadow@last%
  \begin{tcbinvclipframe}%
  \kvtcb@shadow%
  \end{tcbinvclipframe}%
}

\tcb@new@skin{enhanced jigsaw}{base@unbroken,%
  frame engine=pathjigsaw,interior titled engine=path,interior engine=path,segmentation engine=path,title engine=path,%
  set@extensions@preframe={\tcb@draw@shadowjigsaw@unbroken},%
  skin first=enhancedfirst jigsaw,skin middle=enhancedmiddle jigsaw,skin last=enhancedlast jigsaw}

\tcb@new@skin{enhancedfirst jigsaw}{base@first,%
  frame engine=pathfirstjigsaw,interior titled engine=pathfirst,interior engine=pathfirst,segmentation engine=path,title engine=pathfirst,%
  set@extensions@preframe={\tcb@draw@shadowjigsaw@first},%
  skin first=enhancedfirst jigsaw,skin middle=enhancedmiddle jigsaw,skin last=enhancedmiddle jigsaw}

\tcb@new@skin{enhancedmiddle jigsaw}{base@middle,%
  frame engine=pathmiddlejigsaw,interior titled engine=pathmiddle,interior engine=pathmiddle,segmentation engine=path,title engine=pathmiddle,%
  set@extensions@preframe={\tcb@draw@shadowjigsaw@middle},%
  skin first=enhancedmiddle jigsaw,skin middle=enhancedmiddle jigsaw,skin last=enhancedmiddle jigsaw}

\tcb@new@skin{enhancedlast jigsaw}{base@last,%
  frame engine=pathlastjigsaw,interior titled engine=pathlast,interior engine=pathlast,segmentation engine=path,title engine=pathlast,%
  set@extensions@preframe={\tcb@draw@shadowjigsaw@last},%
  skin first=enhancedmiddle jigsaw,skin middle=enhancedmiddle jigsaw,skin last=enhancedlast jigsaw}

\tcbset{%
  enhanced jigsaw/.style={skin=enhanced jigsaw},%
  enhanced standard jigsaw/.style={skin=enhanced jigsaw,
    skin first=enhanced jigsaw,skin middle=enhanced jigsaw,skin last=enhanced jigsaw},%
  frame engine/pathjigsaw/.style={frame code=\tcb@drawframe@pathjigsaw},
  frame engine/pathfirstjigsaw/.style={frame code=\tcb@drawframe@pathfirstjigsaw},
  frame engine/pathmiddlejigsaw/.style={frame code=\tcb@drawframe@pathmiddlejigsaw},
  frame engine/pathlastjigsaw/.style={frame code=\tcb@drawframe@pathlastjigsaw},
}

