회로 기호 모양의 배경 경로에 \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? 나는 개인적으로 전자를 선호합니다.

관련 정보