% --------------------------------------------------------------------------
%
% the CHEMMACROS package -- module: `tikz'
%
% --------------------------------------------------------------------------
% Clemens Niederberger
% --------------------------------------------------------------------------
% https://github.org/cgnieder/chemmacros/
% contact@mychemistry.eu
% --------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% --------------------------------------------------------------------------
% Copyright 2011--2020 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% 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 2008/05/04 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% --------------------------------------------------------------------------
\ChemModule*{tikz}{2015/10/26 upright greek symbols}

\RequirePackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing}

\ExplSyntaxOn

\tl_const:Nx \c_chemmacros_other_colon_tl { \token_to_str:N : }

% --------------------------------------------------------------------------
% TikZ drawings - helper macros
\cs_new_protected:Npn \chemmacros_tikz_picture:nn #1#2
  { \tikzpicture[{#1}] #2 \endtikzpicture }
\cs_new_protected:Npn \chemmacros_tikz:nn #1#2           { \tikz[{#1}] {#2} }
\cs_new_protected:Npn \chemmacros_tikz_draw:n #1         { \draw[{#1}] }
\cs_new_protected:Npn \chemmacros_tikz_node:n #1         { \node[{#1}] }
\cs_new_protected:Npn \chemmacros_tikz_shade:n #1        { \shade[{#1}] }
\cs_new_protected:Npn \chemmacros_tikz_shadedraw:n #1    { \shadedraw[{#1}] }
\cs_new_protected:Npn \chemmacros_tikz_node_in_draw:n #1 { node[{#1}] }

\cs_generate_variant:Nn \chemmacros_tikz_picture:nn     { xn }
\cs_generate_variant:Nn \chemmacros_tikz_draw:n         { x }
\cs_generate_variant:Nn \chemmacros_tikz_node:n         { x }
\cs_generate_variant:Nn \chemmacros_tikz_shade:n        { x }
\cs_generate_variant:Nn \chemmacros_tikz_shadedraw:n    { x }
\cs_generate_variant:Nn \chemmacros_tikz_node_in_draw:n { x }

% --------------------------------------------------------------------------
% arrow tips for electron movement
\dim_new:N \l__chemmacros_el_length_dim

% full tip for pairs
\pgfarrowsdeclare { el } { el }
  {
    \dim_set:Nn \l__chemmacros_el_length_dim
      { 2.5pt + 2.5\pgflinewidth }
    \pgfarrowsleftextend { -\l__chemmacros_el_length_dim }
    \pgfarrowsrightextend { .5\pgflinewidth }
  }
  {
    \dim_set:Nn \l__chemmacros_el_length_dim
      { 2.5pt + 2.5\pgflinewidth }
    \pgfsetdash {} { 0pt }
    \pgfsetroundjoin
    \pgfsetroundcap
    \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
    \pgfpathlineto
      {
        \pgfpoint
          { -\l__chemmacros_el_length_dim }
          { .3\l__chemmacros_el_length_dim }
      }
    \pgfpathlineto
      { \pgfpoint { -.5\l__chemmacros_el_length_dim } { 0pt } }
    \pgfpathlineto
      {
        \pgfpoint
          { -\l__chemmacros_el_length_dim }
          { -.3\l__chemmacros_el_length_dim }
      }
    \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
    \pgfusepathqfillstroke
  }

% half tip on the left
\pgfarrowsdeclare { left~el } { left~el }
  {
    \dim_set:Nn \l__chemmacros_el_length_dim
      { 2.5pt + 2.5\pgflinewidth }
    \pgfarrowsleftextend { -\l__chemmacros_el_length_dim }
    \pgfarrowsrightextend { .5\pgflinewidth }
  }
  {
    \dim_set:Nn \l__chemmacros_el_length_dim
      { 2.5pt + 2.5\pgflinewidth }
    \pgfsetdash {} { 0pt }
    \pgfsetroundjoin
    \pgfsetroundcap
    \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
    \pgfpathlineto
      {
        \pgfpoint
          { -\l__chemmacros_el_length_dim }
          { .3\l__chemmacros_el_length_dim }
      }
    \pgfpathlineto { \pgfpoint { -.5\l__chemmacros_el_length_dim } { 0pt } }
    \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
    \pgfusepathqfillstroke
  }

% half tip in the right
\pgfarrowsdeclare { right~el } { right~el }
  {
    \dim_set:Nn \l__chemmacros_el_length_dim
      { 2.5pt + 2.5\pgflinewidth }
    \pgfarrowsleftextend { -\l__chemmacros_el_length_dim }
    \pgfarrowsrightextend { .5\pgflinewidth }
  }
  {
    \dim_set:Nn \l__chemmacros_el_length_dim
      { 2.5pt + 2.5\pgflinewidth }
    \pgfsetdash {} { 0pt }
    \pgfsetroundjoin
    \pgfsetroundcap
    \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
    \pgfpathlineto
      {
        \pgfpoint
          { -\l__chemmacros_el_length_dim }
          { -.3\l__chemmacros_el_length_dim }
      }
    \pgfpathlineto { \pgfpoint { -.5\l__chemmacros_el_length_dim } { 0pt } }
    \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
    \pgfusepathqfillstroke
  }
% --------------------------------------------------------------------------
% http://tex.stackexchange.com/a/25689/
\ChemCompatibilityFrom{5.3}
\pgfdeclaredecoration{wave}{initial}{
  \state{initial}[
    width = +0pt ,
    next~ state = sine,
    persistent~ precomputation = {
      \pgfmathsetmacro\matchinglength{
        \pgfdecoratedinputsegmentlength /
        int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)
      }
      \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
    }
  ]{}
  \state{sine}[width=\pgfdecorationsegmentlength]{
    \pgfpathsine{
      \pgfpoint
        {0.25\pgfdecorationsegmentlength}
        {0.5\pgfdecorationsegmentamplitude}
      }
    \pgfpathcosine{
      \pgfpoint
        {0.25\pgfdecorationsegmentlength}
        {-0.5\pgfdecorationsegmentamplitude}
      }
    \pgfpathsine{
      \pgfpoint
        {0.25\pgfdecorationsegmentlength}
        {-0.5\pgfdecorationsegmentamplitude}
      }
    \pgfpathcosine{
      \pgfpoint
        {0.25\pgfdecorationsegmentlength}
        {0.5\pgfdecorationsegmentamplitude}
      }
  }
  \state{final}{}
}
\EndChemCompatibility

% --------------------------------------------------------------------------
\file_input_stop:

2015/10/26 - add decoration `wave' (complete sines)
