回路シンボル図形の背景パスで \pgfpointanchor を使用する

回路シンボル図形の背景パスで \pgfpointanchor を使用する

高校の物理の教科書で使用されている一般的な電源の回路記号を作成してみました。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC,shapes.gates.ee}
\makeatletter
\pgfdeclareshape{mybox}{%
  \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]
  \inheritbackgroundpath[from=rectangle ee]
\anchor{west circ center}{
\pgfpointlineattime{0.5}{\southwest}{\northeast}
\advance\pgf@x by-0.5\tikzcircuitssizeunit%
}
\anchor{east circ center}{
\pgfpointlineattime{0.5}{\southwest}{\northeast}
\advance\pgf@x by0.5\tikzcircuitssizeunit%
}
\backgroundpath{%
\pgfpathmoveto{\pgfpointanchor{\tikz@fig@name}{west}}
\pgfpathlineto{\pgfpointanchor{\tikz@fig@name}{west circ center}}
\pgfpathmoveto{\pgfpointanchor{\tikz@fig@name}{east}}
\pgfpathlineto{\pgfpointanchor{\tikz@fig@name}{east circ center}}
\pgfusepath{stroke}
\pgfpathcircle{\pgfpointanchor{\tikz@fig@name}{east circ center}}{0.25\tikzcircuitssizeunit}
\pgfpathcircle{\pgfpointanchor{\tikz@fig@name}{west circ center}}{0.25\tikzcircuitssizeunit}
\pgfusepath{stroke,fill}
}
}
\makeatother
\tikzset{
  circuit declare symbol=general source,
  set general source graphic={
     draw,fill=white,shape=mybox, circuit symbol size=width 3 height 1,
    transform shape,
    }
}
\begin{document}
\begin{tikzpicture}[circuit ee IEC]
\draw(0,0)to[general source={info={foo}}](2,0)to[resistor={info=bar}](4,0);
\draw(0,0)to[resistor](0,-3)to[make contact](4,-3)to[bulb](4,0);
\end{tikzpicture}

\end{document}

は、私のマシンでは機能する や などのコマンドを使用して描画されます。自体\backgroundpathは、と のみに基づいたハード計算によるバックグラウンド パスを使用して独自の派生シェイプを定義しますが、他のアンカーが確立されると、面倒に見えます。\pgfpathlineto\pgfpointanchortikz\southwest\northeas

私のやり方には何か害やリスクがありますか?tikzのやり方に切り替えるべきでしょうか、それともこのままでいいのでしょうか?

答え1

つまり、あなたは間違っていません。それが価値があるかどうかはあなた次第です。


PGFマニュアルでは\anchor、 とは対照的に\savedanchor、 はオンデマンド作成つまり、アンカーの座標は、ユーザーが明示的に を記述した場合にのみ計算されます(A.east)

アンカーの 90% はまったく使用されておらず、計算に時間を無駄にする必要がないため、これにより多くの時間が節約されます。


TiがZは背景パスを描画しているため、これら\anchorの座標はまだ計算されていません。Tiの場合Z は描画のためだけにこれらの座標を計算するので、\anchorそもそも使用しても意味がありません... すべてを単純に作成します\savedanchor

つまり、TeXとの互換性の問題ではないのです。Zは純粋なTeXコードを好みます。なぜなら、その方が速いからです。著者は、何百万人もの人々の2秒を節約するために、さらに2時間を費やすことを決意しました。私の意見では、TiはZ は TeX 用に設計されており、LaTeX と互換性があります。


あなたの場合、それはすべてあなた次第です。簡単なコードを書いて、さらに数ミリ秒待ちたいですか? それとも、 で遊んでみたいですか\pgf@x? 私は個人的に前者を好みます。

関連情報