Skip to main content
+image
Source Link
cfr
  • 248.1k
  • 17
  • 313
  • 634

I wrote this while the OP was writing an answer. Since this solution is a bit simpler, it seems worth presenting as an alternative. However, I will delete this answer if the OP wishes.

One approach is just to save the 0.5 or 1.5 and then use that in the definition of the anchor. We can't save the dimension because we don't know \radius. We can't use the conditional directly in the definition of the anchor because the anchor isn't calculated until it is used, so the conditional may not have the same value when the anchor is actually accessed. It does, however, have the relevant value if we save the value to a macro. We can then use that macro to define the anchor.

\documentclass{article} % ateb: https://tex.stackexchange.com/a/733652/ % addaswyd o gwestiwn karlh: https://tex.stackexchange.com/q/733635/ \usepackage{tikz} \newif\ifmarkisinside \pgfkeys{% /pgf/port 1 inside/.is if=markisinside, /pgf/port 1 inside/.default=true, /pgf/port 1 inside=true, } \makeatletter \newdimen\tempdimen \pgfdeclareshape{mycircle}{% \nodeparts{text}% \inheritsavedanchors[from=circle] \inheritanchor[from=circle]{text}% \inheritanchor[from=circle]{center}% \inheritbackgroundpath[from=circle]% \savedmacro\portsep{% \ifmarkisinside \def\portsep{0.5}% \else \def\portsep{1.5}% \fi }% \anchor{port 1}{% \centerpoint \pgfmathsetlength\tempdimen{\portsep*\radius}% \advance \pgf@x by \tempdimen }% } \makeatother \begin{document} \begin{tikzpicture} \node [draw,mycircle,minimum size=2cm] (c1) at (0,0) {}; \fill (c1.port 1) circle(0.05); \node [draw,mycircle,minimum size=2cm,port 1 inside=false] (c2) at (4,0) {}; \fill (c2.port 1) circle(0.05); \end{tikzpicture} \end{document} 

offset anchor by one or half or three times radius

I wrote this while the OP was writing an answer. Since this solution is a bit simpler, it seems worth presenting as an alternative. However, I will delete this answer if the OP wishes.

One approach is just to save the 0.5 or 1.5 and then use that in the definition of the anchor. We can't save the dimension because we don't know \radius. We can't use the conditional directly in the definition of the anchor because the anchor isn't calculated until it is used, so the conditional may not have the same value when the anchor is actually accessed. It does, however, have the relevant value if we save the value to a macro. We can then use that macro to define the anchor.

\documentclass{article} \usepackage{tikz} \newif\ifmarkisinside \pgfkeys{% /pgf/port 1 inside/.is if=markisinside, /pgf/port 1 inside/.default=true, /pgf/port 1 inside=true, } \makeatletter \newdimen\tempdimen \pgfdeclareshape{mycircle}{% \nodeparts{text}% \inheritsavedanchors[from=circle] \inheritanchor[from=circle]{text}% \inheritanchor[from=circle]{center}% \inheritbackgroundpath[from=circle]% \savedmacro\portsep{% \ifmarkisinside \def\portsep{0.5}% \else \def\portsep{1.5}% \fi }% \anchor{port 1}{% \centerpoint \pgfmathsetlength\tempdimen{\portsep*\radius}% \advance \pgf@x by \tempdimen }% } \makeatother \begin{document} \begin{tikzpicture} \node [draw,mycircle,minimum size=2cm] (c1) at (0,0) {}; \fill (c1.port 1) circle(0.05); \node [draw,mycircle,minimum size=2cm,port 1 inside=false] (c2) at (4,0) {}; \fill (c2.port 1) circle(0.05); \end{tikzpicture} \end{document} 

I wrote this while the OP was writing an answer. Since this solution is a bit simpler, it seems worth presenting as an alternative. However, I will delete this answer if the OP wishes.

One approach is just to save the 0.5 or 1.5 and then use that in the definition of the anchor. We can't save the dimension because we don't know \radius. We can't use the conditional directly in the definition of the anchor because the anchor isn't calculated until it is used, so the conditional may not have the same value when the anchor is actually accessed. It does, however, have the relevant value if we save the value to a macro. We can then use that macro to define the anchor.

\documentclass{article} % ateb: https://tex.stackexchange.com/a/733652/ % addaswyd o gwestiwn karlh: https://tex.stackexchange.com/q/733635/ \usepackage{tikz} \newif\ifmarkisinside \pgfkeys{% /pgf/port 1 inside/.is if=markisinside, /pgf/port 1 inside/.default=true, /pgf/port 1 inside=true, } \makeatletter \newdimen\tempdimen \pgfdeclareshape{mycircle}{% \nodeparts{text}% \inheritsavedanchors[from=circle] \inheritanchor[from=circle]{text}% \inheritanchor[from=circle]{center}% \inheritbackgroundpath[from=circle]% \savedmacro\portsep{% \ifmarkisinside \def\portsep{0.5}% \else \def\portsep{1.5}% \fi }% \anchor{port 1}{% \centerpoint \pgfmathsetlength\tempdimen{\portsep*\radius}% \advance \pgf@x by \tempdimen }% } \makeatother \begin{document} \begin{tikzpicture} \node [draw,mycircle,minimum size=2cm] (c1) at (0,0) {}; \fill (c1.port 1) circle(0.05); \node [draw,mycircle,minimum size=2cm,port 1 inside=false] (c2) at (4,0) {}; \fill (c2.port 1) circle(0.05); \end{tikzpicture} \end{document} 

offset anchor by one or half or three times radius

Source Link
cfr
  • 248.1k
  • 17
  • 313
  • 634

I wrote this while the OP was writing an answer. Since this solution is a bit simpler, it seems worth presenting as an alternative. However, I will delete this answer if the OP wishes.

One approach is just to save the 0.5 or 1.5 and then use that in the definition of the anchor. We can't save the dimension because we don't know \radius. We can't use the conditional directly in the definition of the anchor because the anchor isn't calculated until it is used, so the conditional may not have the same value when the anchor is actually accessed. It does, however, have the relevant value if we save the value to a macro. We can then use that macro to define the anchor.

\documentclass{article} \usepackage{tikz} \newif\ifmarkisinside \pgfkeys{% /pgf/port 1 inside/.is if=markisinside, /pgf/port 1 inside/.default=true, /pgf/port 1 inside=true, } \makeatletter \newdimen\tempdimen \pgfdeclareshape{mycircle}{% \nodeparts{text}% \inheritsavedanchors[from=circle] \inheritanchor[from=circle]{text}% \inheritanchor[from=circle]{center}% \inheritbackgroundpath[from=circle]% \savedmacro\portsep{% \ifmarkisinside \def\portsep{0.5}% \else \def\portsep{1.5}% \fi }% \anchor{port 1}{% \centerpoint \pgfmathsetlength\tempdimen{\portsep*\radius}% \advance \pgf@x by \tempdimen }% } \makeatother \begin{document} \begin{tikzpicture} \node [draw,mycircle,minimum size=2cm] (c1) at (0,0) {}; \fill (c1.port 1) circle(0.05); \node [draw,mycircle,minimum size=2cm,port 1 inside=false] (c2) at (4,0) {}; \fill (c2.port 1) circle(0.05); \end{tikzpicture} \end{document}