% lua-tikz3dtools-latex2e-command-definitions.tex
\ProvidesFile{lua-tikz3dtools-latex2e-command-definitions}
\newcommand{\drawpoint}[2][]{
    \begingroup 
        \coordinate (@) at (#2);
        \node at (@) [
            circle
            ,minimum size = 2*\tikz@td@gm@pointradius cm
            ,inner sep = 0pt
            ,outer sep = 0pt
            ,fill
            ,/lua-tikz3dtools/geometric-vector/.search also = {/tikz}
            ,/lua-tikz3dtools/geometric-vector/.cd
            ,#1
        ] {};
    \endgroup
}
\newcommand{\drawmark}[1][]{
    \begingroup
        \pgfmathsetmacro{\tikz@td@gm@halfmarklength}{\tikz@td@gm@marklength/2}
        \draw[
            /lua-tikz3dtools/geometric-vector/.search also = {/tikz}
            ,/lua-tikz3dtools/geometric-vector/.cd
            ,#1
        ] (0,-\tikz@td@gm@halfmarklength pt) -- (0,\tikz@td@gm@halfmarklength pt);
    \endgroup
}
\newcommand{\drawvector}[3][]{
    \begingroup
        \tikzset{
            /lua-tikz3dtools/geometric-vector/.search also = {/tikz},
            /lua-tikz3dtools/geometric-vector/.cd,
            #1
        }
        \coordinate (@start) at (#2);
        \ifnum\tikz@td@gm@points=1
            \drawpoint[#1]{@start}
            \draw
                [
                    very thick
                    ,{-Stealth[round]}
                    ,shorten < = \tikz@td@gm@pointradius cm
                    ,/lua-tikz3dtools/geometric-vector/.search also = {/tikz}
                    ,/lua-tikz3dtools/geometric-vector/.cd
                    ,#1
                ] (@start) -- ++(#3);
        \fi
        \ifnum\tikz@td@gm@points=2
            \drawpoint[#1]{@start}
            \draw
                [
                    very thick
                    ,{-Stealth[round]}
                    ,shorten < = \tikz@td@gm@pointradius cm
                    ,shorten > = \tikz@td@gm@pointradius cm
                    ,/lua-tikz3dtools/geometric-vector/.search also = {/tikz}
                    ,/lua-tikz3dtools/geometric-vector/.cd
                    ,#1
                ] (@start) -- ++(#3) coordinate (@end);
            \drawpoint[#1]{@end}
        \fi
        \ifnum\tikz@td@gm@points=0
            \draw
                [
                    very thick
                    ,{-Stealth[round]}
                    ,/lua-tikz3dtools/geometric-vector/.search also = {/tikz}
                    ,/lua-tikz3dtools/geometric-vector/.cd
                    ,#1
                ] (@start) -- ++(#3);
        \fi
        \ifnum\tikz@td@gm@points=3
            \draw
                [
                    very thick
                    ,{-Stealth[round]}
                    ,/lua-tikz3dtools/geometric-vector/.search also = {/tikz}
                    ,/lua-tikz3dtools/geometric-vector/.cd
                    ,#1
                ] (@start) -- ++(#3) coordinate (@end);
            \drawpoint[#1]{@end}
        \fi
        \ifnum\tikz@td@gm@mark=1
            \path
                [
                    decoration = {
                        markings
                        ,mark =
                            between positions \tikz@td@gm@markstart
                            and \tikz@td@gm@markstop
                            step \tikz@td@gm@markstep
                            with {\drawmark}
                    }
                    ,decorate
                ] (#2) -- ++(#3);
        \fi
    \endgroup
}

% Labels a path:
% #2 - Start Coordinate,
% #3 - End Coordinate,
% #4 - Vector (direction),
% #5 - Relative Position along path,
% #6 - Offset coordinate,
% #7 - The label text.
\newcommand{\drawlabel}[7][]{
    \begingroup
    \path
        [
            decoration = {
                markings
                ,mark =
                    at position #4
                    with 
                        {
                            \node
                                [
                                    #1
                                ]
                                at (#5,#6) {#7};
                        }
            }
            ,decorate
        ] (#2) -- ++(#3);
    \endgroup
}


\newcommand{\appendprism}[1][]{
    \begingroup
    \tikzset{
        /lua-tikz3dtools/clipped-subspace/plane/.search also = {/lua-tikz3dtools/clipped-subspace},
        /lua-tikz3dtools/clipped-subspace/plane/.cd,
        #1
    }
    % For brevity, assign keys to macros
    \def\xmin{\tikz@td@cs@xmin}
    \def\xmax{\tikz@td@cs@xmax}
    \def\ymin{\tikz@td@cs@ymin}
    \def\ymax{\tikz@td@cs@ymax}
    \def\zmin{\tikz@td@cs@zmin}
    \def\zmax{\tikz@td@cs@zmax}

    % Bottom square edges
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = (1-u)*\xmin + u*\xmax,
        y = \ymin,
        z = \zmin,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = \xmax,
        y = (1-u)*\ymin + u*\ymax,
        z = \zmin,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = (1-u)*\xmax + u*\xmin,
        y = \ymax,
        z = \zmin,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = \xmin,
        y = (1-u)*\ymax + u*\ymin,
        z = \zmin,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]

    % Top square edges
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = (1-u)*\xmin + u*\xmax,
        y = \ymin,
        z = \zmax,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = \xmax,
        y = (1-u)*\ymin + u*\ymax,
        z = \zmax,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = (1-u)*\xmax + u*\xmin,
        y = \ymax,
        z = \zmax,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = \xmin,
        y = (1-u)*\ymax + u*\ymin,
        z = \zmax,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]

    % Vertical edges (pillars)
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = \xmin,
        y = \ymin,
        z = (1-u)*\zmin + u*\zmax,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = \xmax,
        y = \ymin,
        z = (1-u)*\zmin + u*\zmax,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = \xmax,
        y = \ymax,
        z = (1-u)*\zmin + u*\zmax,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \appendcurve[
        u min=0, u max=1, u samples=20,
        x = \xmin,
        y = \ymax,
        z = (1-u)*\zmin + u*\zmax,
        draw options = {draw},
        transformation = \tikz@td@cs@transformation
    ]
    \endgroup
}
