\input regression-test.tex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzphysics}

\newdimen\tikzphysicstestx
\newdimen\tikzphysicstesty
\newdimen\tikzphysicstestxx
\newdimen\tikzphysicstestyy
\newdimen\tikzphysicstestdiff

\newcommand{\tikzphysicsgetpoint}[2]{%
  \pgfextractx{\tikzphysicstestx}{\pgfpointanchor{#1}{#2}}%
  \pgfextracty{\tikzphysicstesty}{\pgfpointanchor{#1}{#2}}%
}

\newcommand{\tikzphysicsassertdim}[3]{%
  \tikzphysicstestdiff=#1\relax
  \advance\tikzphysicstestdiff by -#2\relax
  \ifdim\tikzphysicstestdiff<0pt \tikzphysicstestdiff=-\tikzphysicstestdiff\fi
  \ifdim\tikzphysicstestdiff<0.02pt
    \TYPE{PASS: #3}%
  \else
    \TYPE{FAIL: #3 (got \the#1, expected \the#2)}%
  \fi
}

\newcommand{\tikzphysicsassertpoint}[5]{%
  \tikzphysicsgetpoint{#1}{#2}%
  \tikzphysicstestxx=\tikzphysicstestx
  \tikzphysicstestyy=\tikzphysicstesty
  \tikzphysicsgetpoint{#3}{#4}%
  \tikzphysicsassertdim{\tikzphysicstestxx}{\tikzphysicstestx}{#5 x}%
  \tikzphysicsassertdim{\tikzphysicstestyy}{\tikzphysicstesty}{#5 y}%
}

\begin{document}
\START

\begin{tikzpicture}
  \node[physicsplatform-left, physics platform width=5, physics platform depth=2,
        physics wall angle=-90, anchor=floor-tl] (Ldown) at (0,0) {};
  \node[physicsplatform-left, physics platform width=5, physics platform depth=2,
        physics wall angle=45, anchor=floor-tl] (Lup) at (0,0) {};
  \node[physicsplatform-right, physics platform width=5, physics platform depth=2,
        physics wall angle=-90, anchor=floor-tr] (Rdown) at (0,0) {};
  \node[physicsplatform-left, physics platform width=5, physics platform depth=2,
        physics strip width=0.3, physics wall angle=135, anchor=floor-tl]
        (Lmiter) at (0,0) {};
  \node[physicsplatform-right, physics platform width=5, physics platform depth=2,
        physics strip width=0.3, physics wall angle=45, anchor=floor-tr]
        (Rmiter) at (0,0) {};

  \tikzphysicsassertpoint{Ldown}{corner}{Ldown}{floor-tl}{left corner at -90 degrees}
  \tikzphysicsassertpoint{Lup}{corner}{Lup}{floor-tl}{left corner at 45 degrees}
  \tikzphysicsassertpoint{Rdown}{corner}{Rdown}{floor-tr}{right corner at -90 degrees}

  \tikzphysicsassertpoint{Ldown}{wall-A}{Ldown}{floor-tl}{default left wall A equals floor top-left}
  \tikzphysicsassertpoint{Lup}{wall-A}{Lup}{floor-tl}{bent left wall stays continuous at corner}
  \tikzphysicsgetpoint{Ldown}{wall-D}
  \tikzphysicsassertdim{\tikzphysicstestx}{0pt}{default left wall D x}
  \tikzphysicsassertdim{\tikzphysicstesty}{-2cm}{default left wall spans platform depth}

  \tikzphysicsgetpoint{Lmiter}{wall-B}
  \tikzphysicsassertdim{\tikzphysicstestx}{-0.124264cm}{left wall B is exact 135-degree miter}
  \tikzphysicsassertdim{\tikzphysicstesty}{-0.3cm}{left miter meets floor inner edge}
  \tikzphysicsgetpoint{Rmiter}{wall-B}
  \tikzphysicsassertdim{\tikzphysicstestx}{0.124264cm}{right wall B is exact 45-degree miter}
  \tikzphysicsassertdim{\tikzphysicstesty}{-0.3cm}{right miter meets floor inner edge}

  \tikzphysicsassertpoint{Ldown}{floor-top-0}{Ldown}{floor-tr}{floor-top-0 endpoint}
  \tikzphysicsassertpoint{Ldown}{floor-top-100}{Ldown}{floor-tl}{floor-top-100 endpoint}
  \tikzphysicsassertpoint{Lup}{wall-outer-0}{Lup}{wall-A}{wall-outer-0 endpoint}
  \tikzphysicsassertpoint{Lup}{wall-outer-100}{Lup}{wall-D}{wall-outer-100 endpoint}
\end{tikzpicture}

\begin{tikzpicture}
  \node[physicswedge, physics wedge width=4, physics wedge angle=30, anchor=bl] (W) at (0,0) {};
  \tikzphysicsassertpoint{W}{base-0}{W}{bl}{wedge base-0 endpoint}
  \tikzphysicsassertpoint{W}{base-100}{W}{br}{wedge base-100 endpoint}
  \tikzphysicsassertpoint{W}{slope-0}{W}{top}{wedge slope-0 endpoint}
  \tikzphysicsassertpoint{W}{slope-100}{W}{bl}{wedge slope-100 endpoint}
\end{tikzpicture}

\begin{tikzpicture}
  \node[physicslens, physics lens radius=5, physics lens thickness=0.25,
        physics lens aperture angle=30] (Lens) at (0,0) {};
  \tikzphysicsassertpoint{Lens}{front-0}{Lens}{front-bottom}{lens front-0 endpoint}
  \tikzphysicsassertpoint{Lens}{front-100}{Lens}{front-top}{lens front-100 endpoint}
  \tikzphysicsassertpoint{Lens}{back-0}{Lens}{back-bottom}{lens back-0 endpoint}
  \tikzphysicsassertpoint{Lens}{back-100}{Lens}{back-top}{lens back-100 endpoint}
\end{tikzpicture}

\begin{tikzpicture}
  \node[physicsblock, physics block width=1, physics block height=10mm] (Block) at (0,0) {};
  \tikzphysicsgetpoint{Block}{east}
  \tikzphysicsassertdim{\tikzphysicstestx}{0.5cm}{bare block width is centimetres}
  \tikzphysicsgetpoint{Block}{north}
  \tikzphysicsassertdim{\tikzphysicstesty}{5mm}{explicit block height unit is preserved}
\end{tikzpicture}

\begin{tikzpicture}
  \coordinate (StringA) at (-3,-1);
  \coordinate (StringB) at (3,-1);
  \node[physicspulley, physics pulley diameter=1] (StringPulley) at (0,0) {};
  \physicsstringoverpulley{StringA}{StringPulley}{StringB}
  \physicsstringoverpulley[
    physics string start solution=1,
    physics string end solution=2,
    physics string wrap=shortest,
    dashed]
    {StringA}{StringPulley}{StringB}
  \physicsstringoverpulley[physics string route=over]{StringA}{StringPulley}{StringB}
  \physicsstringoverpulley[physics string route=under]{StringA}{StringPulley}{StringB}
  \physicsstringoverpulley[physics string route=shortest]{StringA}{StringPulley}{StringB}
  \TYPE{PASS: tangent pulley string default, explicit, and named routes compile}
\end{tikzpicture}

\END
\end{document}
