[Tex/LaTex] Custom arrow tip with `arrows.meta` TikZ library

tikz-arrowstikz-pgf

In the spirit of this question, how do I make a custom arrow tip using the new arrows.meta TikZ library? I would like to make a semicircular tip that accepts the open option, ideally, and perhaps other options like length (or radius or whatever the Circle arrow tip accepts).

Best Answer

The documentation for declaring new arrow tips is fairly comprehensive, but there appear to some errors in the examples. I'm not an expert on the arrows.meta stuff but the following appears to be the minimal requirements to get things started:

\documentclass[tikz,border=0.25cm]{standalone}
\usetikzlibrary{arrows.meta}
\makeatletter
\pgfdeclarearrow{
  name=semicircle,
  parameters={ 
    \the\pgfarrowlength,%
    \ifpgfarrowopen o\fi%  
  },
  setup code={
    % The line end value:
    \pgfarrowssettipend{0pt}
    \pgf@x=-.25\pgfarrowlength
    \advance\pgf@x by-.5\pgflinewidth
    % The hull point:
    \pgfutil@tempdima=0.25\pgfarrowlength
    \advance\pgfutil@tempdima by.5\pgflinewidth
    \pgfarrowssetlineend{\pgf@x}
    \pgfarrowssetvisualbackend{-.25\pgfarrowlength}
    \pgfarrowssetbackend{-.75\pgfarrowlength}
    \pgfarrowssavethe\pgfarrowlength
    \pgfarrowlinewidth=\pgflinewidth
    \pgfarrowssavethe\pgfarrowlinewidth
    \pgfarrowshullpoint{0pt}{0pt}
    \pgfarrowshullpoint{0pt}{-\pgfutil@tempdima}
    \pgfarrowshullpoint{0pt}{\pgfutil@tempdima}
  },
  drawing code={
    \pgfpathmoveto{\pgfpoint{-.25\pgfarrowlength-.5\pgflinewidth}{.25\pgfarrowlength}}
    \pgfpathlineto{\pgfpoint{-.25\pgfarrowlength-.5\pgflinewidth}{-.25\pgfarrowlength}}
    \pgfpatharc{-90}{90}{0.25\pgfarrowlength}
    \pgfpathclose
    \ifpgfarrowopen\pgfusepathqstroke\else\ifdim\pgfarrowlinewidth>0pt\pgfusepathqfillstroke\else\pgfusepathqfill\fi\fi
  },
  defaults={ length=10pt }
}

\begin{document}

\begin{tikzpicture}
\draw [help lines] grid (3,2);
\draw [semicircle-{semicircle[open]}] (0,0) -- (3,2);
\draw [very thick, {semicircle[length=40pt,open]}-{semicircle[length=20pt]}] 
  (0,2) -- (3,0);
\end{tikzpicture}

\end{document}

enter image description here