Trying to implement a handy way to check if a TikZ point is right or left of another one, I came up with the following MWE.
\documentclass[border=1mm, tikz]{standalone}
\makeatletter
% prints 1 if #1.center is right than #2.center, 0 otherwise
\newcommand{\isRight}[2]{
%\pgfpointdiff{a}{b} gives b-a
\pgfpointdiff{\pgfpointanchor{#2}{center}}{\pgfpointanchor{#1}{center}}
\pgfmathparse{greater(\pgf@x,0)}\pgfmathresult
}
% 1 if #1.center is left than #2.center, 0 otherwise -> result in \pgfmathresult
\newcommand{\checkIfLeft}[2]{
%\pgfpointdiff{a}{b} gives b-a
\pgfpointdiff{\pgfpointanchor{#2}{center}}{\pgfpointanchor{#1}{center}}%
\pgfmathparse{less(\pgf@x,0)}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\node[draw] (A) at (0,0) {A};
\node[draw] (B) at (1,0) {B};
\checkIfLeft{A}{B}
\ifnum\pgfmathresult=1
\node at (0.5,1){A is left of B};
\fi
%\ifnum\isRight{B}{A}=1
% \node at (0.5,-1){B is right of A};
%\fi
\end{tikzpicture}
\end{document}
but I am quite unsatisfied with it. What I would like to have is something that may be used in a \ifnum ... \fi construct, as in the commented code (and I would like not to use packages beyond what pgf loads).
Here my questions:
- In the commented code, what is exactly happening in the
\ifnumexpansion, which makes the compilation fail? - How can I fix the
\isRightcommand in order to be able to use it together with\ifnum? - If question 2 is tricky, how can I affect the
\ifnumexpansion to achieve what I wish? - Is there in
pgfa smarter/more straightforward way to check if aTikZpoint is left/right of another point? My final goal would be to draw something only if a point is right/left of another.
Bonus question:
- How (and where) is
\pdfstrcmp{}{}implemented, since it is harmless to use it in a\ifnum ... \ficonstruct?



\pdfstrcmpis a primitive. – Ulrike Fischer Apr 02 '19 at 12:46\pdfstrcmpis a primitive clarifies why I was not finding its implementation... I should have had a look to thepdftexmanual before. – Axel Krypton Apr 02 '19 at 13:14