%% Shared native piston-cylinder apparatus for fluids and thermodynamics.
%% Existing geometry and anchors retain their public contracts.
\usetikzlibrary{tikzphysics.core}
\makeatletter
%% piston cylinder
\tikzset{
 piston cylinder width/.initial=1.8cm,
 physics piston cylinder width/.style={piston cylinder width={#1}},
 piston cylinder height/.initial=3cm,
 physics piston cylinder height/.style={piston cylinder height={#1}},
 piston position/.initial=.65,
 physics piston position/.style={piston position={#1}},
}
\pgfdeclareshape{physicspistoncylindernode}{
 \savedmacro\tikzphysics@component@physicspistoncylindernodestate{%
  \tikzphysics@component@length\cw{piston cylinder width}
  \tikzphysics@component@length\ch{piston cylinder height}
  \pgfmathparse{\pgfkeysvalueof{/tikz/piston position}}
  \ifpgfmathunitsdeclared
   \PackageError{tikzphysics}{Piston position must be unitless}{Use a fraction strictly between .1 and .9.}%
  \fi
  \edef\cp{\pgfmathresult}
\tikzphysics@component@check{\cw>0 && \ch>0 && \cp>.1 && \cp<.9}{Cylinder dimensions must be positive and piston position between .1 and .9}
  \addtosavedmacro\cw
  \addtosavedmacro\ch
  \addtosavedmacro\cp
 }
 \anchor{center}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{0}}
 \anchor{north}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{\ch/2}}
 \anchor{south}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{-(\ch/2)}}
 \anchor{east}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{\cw/2}{0}}
 \anchor{west}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{-(\cw/2)}{0}}
 \anchor{north east}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{\cw/2}{\ch/2}}
 \anchor{north west}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{-(\cw/2)}{\ch/2}}
 \anchor{south east}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{\cw/2}{-(\ch/2)}}
 \anchor{south west}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{-(\cw/2)}{-(\ch/2)}}
 \anchor{piston}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{(-.5+\cp)*\ch}}
 \anchor{rod-end}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{.5*\ch}}
 \anchor{gas-center}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{(-.5+\cp/2)*\ch}}
 \anchor{heat-left}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{-\cw/2}{(-.5+\cp/2)*\ch}}
 \anchor{heat-right}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{\cw/2}{(-.5+\cp/2)*\ch}}
 \anchor{heat-bottom}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{-\ch/2}}
 \anchor{piston-top}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{(-.46+\cp)*\ch}}
 \anchor{rod-start}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{(-.46+\cp)*\ch}}
 \anchor{work}{\tikzphysics@component@physicspistoncylindernodestate\tikzphysics@component@point{0}{.5*\ch}}
 \anchor{text}{\pgf@x=-.5\wd\pgfnodeparttextbox\pgf@y=-.5\ht\pgfnodeparttextbox\advance\pgf@y by.5\dp\pgfnodeparttextbox}
 \tikzphysics@declarepercentanchors{bottom}{\tikzphysics@component@physicspistoncylindernodestate}{(-\cw/2+\tikzphysics@percent*\cw)*1cm}{(-\ch/2)*1cm}
 \tikzphysics@declarepercentanchors{right}{\tikzphysics@component@physicspistoncylindernodestate}{(\cw/2)*1cm}{(-\ch/2+\tikzphysics@percent*\ch)*1cm}
 \tikzphysics@declarepercentanchors{top}{\tikzphysics@component@physicspistoncylindernodestate}{(\cw/2-\tikzphysics@percent*\cw)*1cm}{(\ch/2)*1cm}
 \tikzphysics@declarepercentanchors{left}{\tikzphysics@component@physicspistoncylindernodestate}{(-\cw/2)*1cm}{(\ch/2-\tikzphysics@percent*\ch)*1cm}
 \tikzphysics@declarepercentanchors{piston}{\tikzphysics@component@physicspistoncylindernodestate}{((-.5+\tikzphysics@percent)*\cw)*1cm}{((-.5+\cp)*\ch)*1cm}
 \tikzphysics@declarepercentanchors{axis}{\tikzphysics@component@physicspistoncylindernodestate}{(0)*1cm}{((-.5+\tikzphysics@percent)*\ch)*1cm}
 \tikzphysics@declarepercentanchors{wall-left}{\tikzphysics@component@physicspistoncylindernodestate}{(-\cw/2)*1cm}{((-.5+\tikzphysics@percent)*\ch)*1cm}
 \tikzphysics@declarepercentanchors{wall-right}{\tikzphysics@component@physicspistoncylindernodestate}{(\cw/2)*1cm}{((-.5+\tikzphysics@percent)*\ch)*1cm}
 \tikzphysics@declarepercentanchors{gas-axis}{\tikzphysics@component@physicspistoncylindernodestate}{(0)*1cm}{((-.5+\tikzphysics@percent*\cp)*\ch)*1cm}
 \tikzphysics@declarepercentanchors{gas-left}{\tikzphysics@component@physicspistoncylindernodestate}{(-\cw/2)*1cm}{((-.5+\tikzphysics@percent*\cp)*\ch)*1cm}
 \tikzphysics@declarepercentanchors{gas-right}{\tikzphysics@component@physicspistoncylindernodestate}{(\cw/2)*1cm}{((-.5+\tikzphysics@percent*\cp)*\ch)*1cm}
 \tikzphysics@declarepercentanchors{piston-top}{\tikzphysics@component@physicspistoncylindernodestate}{((-.5+\tikzphysics@percent)*\cw)*1cm}{((-.46+\cp)*\ch)*1cm}
 \tikzphysics@declarepercentanchors{rod}{\tikzphysics@component@physicspistoncylindernodestate}{(0)*1cm}{((-.46+\cp+\tikzphysics@percent*(.96-\cp))*\ch)*1cm}
 \anchorborder{\edef\cpx{\the\pgf@x}\edef\cpy{\the\pgf@y}\tikzphysics@component@physicspistoncylindernodestate\pgfpointborderrectangle{\pgfpoint{\cpx}{\cpy}}{\tikzphysics@component@point{\cw/2}{\ch/2}}}
 \backgroundpath{\tikzphysics@component@physicspistoncylindernodestate
\tikzphysics@component@move{-\cw/2}{\ch/2}
\tikzphysics@component@line{-\cw/2}{-\ch/2}
\tikzphysics@component@line{\cw/2}{-\ch/2}
\tikzphysics@component@line{\cw/2}{\ch/2}
\tikzphysics@component@move{-\cw/2}{(-.5+\cp)*\ch}
\tikzphysics@component@line{\cw/2}{(-.5+\cp)*\ch}
\tikzphysics@component@line{\cw/2}{(-.46+\cp)*\ch}
\tikzphysics@component@line{-\cw/2}{(-.46+\cp)*\ch}
\pgfpathclose
\tikzphysics@component@move{0}{(-.46+\cp)*\ch}
\tikzphysics@component@line{0}{.5*\ch}
 }
}
\tikzphysics@declarehook{piston cylinder}
\tikzphysics@registerdisplayname{physicspistoncylindernode}{piston cylinder}
\tikzphysics@registeranchors{physicspistoncylindernode}{center,north,south,east,west,piston,rod-end,gas-center,heat-left,heat-right,heat-bottom,piston-top,rod-start,work}
\tikzphysics@registerfamilies{physicspistoncylindernode}{bottom,right,top,left,piston,axis,wall-left,wall-right,gas-axis,gas-left,gas-right,piston-top,rod}
\tikzphysics@registerkeys{physicspistoncylindernode}{piston cylinder width,piston cylinder height,piston position}
\tikzphysics@registerkeydefaults{physicspistoncylindernode}{piston cylinder width/1.8cm,piston cylinder height/3cm,piston position/.65}
\tikzset{physicspistoncylindernode/.style={shape=physicspistoncylindernode,physics logical shape=physicspistoncylindernode,anchor=center,draw=black,fill=none,inner sep=0pt,outer sep=0pt,physics debug setup,every physics object,every piston cylinder},piston cylinder/.style={physicspistoncylindernode}}

\makeatother
\endinput
