%% tikzlibrarytikzphysics.core.code.tex %% ----------------------------------------------------------- %% Core helpers shared by all tikzphysics modules. %% %% Provides: %% * \tikzphysics@length@keyhandler --- unit-aware length key router %% * physics debug/.cd family --- anchor and key overlays %% * \tikzphysics@registeranchors / \tikzphysics@registerkeys --- registries %% used by each shape so debug mode knows what to display %% * \geometryvalue --- per-node resolved geometry values %% %% Every shape module should \usetikzlibrary{tikzphysics.core} %% before declaring its shapes. %% %% Author : Vaibhav Blayer %% Version : v1.8.0 (2026-10-11) %% License : LPPL 1.3c %% ----------------------------------------------------------- \makeatletter %% Public hooks run after a style's built-in defaults. The short names are %% intentional: users can write every block/.style without a key directory. \tikzset{ every physics object/.style={}, every physics connection/.style={}, } \newcommand{\tikzphysics@declarehook}[1]{% \tikzset{every physics #1/.style={}, every #1/.style={/tikz/every physics #1}}% } %% ============================================================ %% UNIT-AWARE LENGTH KEY HANDLER %% %% Usage inside a key's .code handler: %% some key/.code = {\tikzphysics@length@keyhandler{/pgf/minimum width}{#1}} %% %% Semantics: %% - If the user value carries a unit (4cm, 30mm, 2ex, 1.5in), %% that unit is respected. %% - If the user value is a bare number or a unit-free math %% expression (4, 2*sqrt(2), 3+1), the result is interpreted %% as centimetres. This matches TikZ's typical "coordinate" %% convention and keeps JEE-physics dimensions readable. %% %% IMPORTANT IMPLEMENTATION NOTE: %% Do NOT use \pgfkeysalso{#1=\pgfmathresult pt} directly. %% pgfkeys stores the RHS as unexpanded token sequence, so the %% shared \pgfmathresult macro gets overwritten by the next %% call — causing cross-contamination between keys %% (e.g. setting minimum width then minimum height would make %% both end up with the second value). Instead, resolve to a %% fixed-point literal via \pgfmathsetlength + \the, then build %% the \pgfkeysalso call with \edef+\noexpand so the stored %% value is a constant string like "85.35826pt". %% ============================================================ \newdimen\tikzphysics@length@tmpdim %% Resolve a tikzphysics length into a concrete dimension. Bare values %% are centimetres; explicit TeX units are preserved. All public size %% keys are required to be strictly positive so invalid geometry fails %% at the option that introduced it rather than much later in PGF math. \newcommand{\tikzphysics@resolve@length}[2]{% \tikzphysics@resolve@nonnegative{#1}{#2}% \ifdim#1=0pt\relax \PackageError{tikzphysics}% {Length `#2' must be greater than zero}% {Use a positive bare value (interpreted as cm) or a positive TeX dimension.}% \fi } %% Spring leads and other optional distances may be zero. \newcommand{\tikzphysics@resolve@nonnegative}[2]{% \pgfmathparse{#2}% \ifpgfmathunitsdeclared \pgfmathsetlength{#1}{\pgfmathresult pt}% \else \pgfmathsetlength{#1}{\pgfmathresult cm}% \fi \ifdim#1<0pt\relax \PackageError{tikzphysics}% {Length `#2' must not be negative}% {Use zero, a positive bare value (cm), or a positive TeX dimension.}% \fi } \newcommand{\tikzphysics@length@keyhandler}[2]{% \tikzphysics@resolve@length{\tikzphysics@length@tmpdim}{#2}% \edef\tikzphysics@length@call{% \noexpand\pgfkeysalso{#1=\the\tikzphysics@length@tmpdim}% }% \tikzphysics@length@call } %% ============================================================ %% ANCHOR AND KEY REGISTRIES %% %% Each shape module registers the anchors it exposes and the %% keys it accepts. Debug mode reads these registries to know %% what to overlay. %% ============================================================ \newcommand{\tikzphysics@registeranchors}[2]{% \expandafter\gdef\csname tikzphysics@anchors@#1\endcsname{#2}% } \newcommand{\tikzphysics@registerkeys}[2]{% \expandafter\gdef\csname tikzphysics@keys@#1\endcsname{#2}% } %% User-facing name shown at the top of debug key panels. Internal PGF shape %% names stay namespaced even when the public TikZ style is deliberately short. \newcommand{\tikzphysics@registerdisplayname}[2]{% \expandafter\gdef\csname tikzphysics@displayname@#1\endcsname{#2}% } %% Key-defaults registry: stores {key/default, key/default, ...} %% for the debug overlay to display. \newcommand{\tikzphysics@registerkeydefaults}[2]{% \expandafter\gdef\csname tikzphysics@keydefaults@#1\endcsname{#2}% } %% ============================================================ %% NAMED-NODE GEOMETRY VALUES %% %% Shapes may register a recorder that snapshots useful scalar metadata %% after a named node has been built. Values are stored per node and are %% therefore safe when several differently configured shapes coexist. %% %% Public access: %% \geometryvalue{W}{left angle} %% \tikzphysicsgeometryvalue{W}{left angle} % collision-safe spelling %% %% A stored value is a fixed literal, so it can be used directly in a TikZ %% option such as rotate=\geometryvalue{W}{slope angle}. %% ============================================================ \newcommand{\tikzphysics@registergeometryrecorder}[2]{% \expandafter\gdef\csname tikzphysics@geometry@recorder@#1\endcsname{#2}% } \newcommand{\tikzphysics@storegeometryvalue}[3]{% \expandafter\xdef\csname tikzphysics@geometry@value@#1@#2\endcsname{#3}% } \newcommand{\tikzphysicsgeometryvalue}[2]{% \ifcsname tikzphysics@geometry@value@#1@#2\endcsname \csname tikzphysics@geometry@value@#1@#2\endcsname \else \PackageError{tikzphysics}% {Geometry value `#2' is unavailable for node `#1'}% {Check that the node is named, uses a supported tikzphysics shape, and that the property name is documented.}% 0% \fi } \newcommand{\geometryvalue}[2]{\tikzphysicsgeometryvalue{#1}{#2}} %% Queue a registered recorder for the node being constructed. The hook runs %% after the node exists, while \tikzlastnode still identifies it. \tikzset{ physics geometry shape/.code = {% \pgfkeysalso{% prefix after command = {% \pgfextra{% \edef\tikzphysics@geometry@tmpnode{\tikzlastnode}% \ifx\tikzphysics@geometry@tmpnode\@empty\else \ifcsname tikzphysics@geometry@recorder@#1\endcsname \csname tikzphysics@geometry@recorder@#1\endcsname {\tikzphysics@geometry@tmpnode}% \fi \fi }% }% }% }, } %% ============================================================ %% NUMERIC (EDGE-PARAMETRIC) ANCHORS %% %% Declares a family of anchors -0, -1, ..., -100 %% linearly interpolating from (sx,sy) to (ex,ey). Each anchor %% corresponds to "t%" of the way along the edge, measured from %% the start point. Call from inside \pgfdeclareshape, once per %% edge. Coordinate arguments may reference saved macros (or %% literal dimens) -- they are left unexpanded so they resolve at %% anchor-access time, while the integer t is baked into the %% generated csname and the computation. %% %% CCW convention across tikzphysics is to start each edge at its %% CCW-trajectory starting point, e.g.: %% bottom : bl -> br (left to right) %% right : br -> tr (bottom to top) %% top : tr -> tl (right to left) %% left : tl -> bl (top to bottom) %% slope : apex -> foot (strict CCW on a wedge with br apex) %% %% Usage: %% \tikzphysics@declareedgeanchors{bottom}{-\myhx}{-\myhy}{\myhx}{-\myhy} %% %% Cost: 101 short anchor calls and one shared calculation per family. %% ============================================================ %% Store a family's calculation once per shape. Each integer anchor is a %% short call to that calculation, with its own literal percentage. Geometry %% expressions and saved-state macros remain unexpanded until anchor access. %% This avoids 101 copies of potentially long formulas in TeX's main memory. \def\tikzphysics@declareanchorfamily@one#1#2#3{% \anchor{#1}{#2{#3}}% } \def\tikzphysics@declareanchorfamily#1#2#3{% \expandafter\gdef\csname tikzphysics@anchorfamily@\pgf@sm@shape@name @#1\endcsname##1{% \def\tikzphysics@percent{((##1)/100)}% #3% }% \foreach \tikzphysics@@t in {0,1,...,100}{% \edef\tikzphysics@@partial{% \noexpand\tikzphysics@declareanchorfamily@one{#2\tikzphysics@@t}% \expandafter\noexpand\csname tikzphysics@anchorfamily@\pgf@sm@shape@name @#1\endcsname {\tikzphysics@@t}}% \tikzphysics@@partial }% } %% Linear edges keep their saved dimensional expressions and directions. \def\tikzphysics@declareedgeanchors#1#2#3#4#5{% \tikzphysics@declareanchorfamily{#1}{#1-}{% \pgfmathsetlength{\pgf@x}{(#2)+\tikzphysics@percent*((#4)-(#2))}% \pgfmathsetlength{\pgf@y}{(#3)+\tikzphysics@percent*((#5)-(#3))}% }% } %% General percentage families restore the instance's saved geometry before %% either coordinate is evaluated, including compound PV/Carnot formulas. \def\tikzphysics@declarepercentanchors#1#2#3#4{% \tikzphysics@declareanchorfamily{#1}{#1-}{% #2% \pgfmathsetlength{\pgf@x}{#3}% \pgfmathsetlength{\pgf@y}{#4}% }% } \newcommand{\tikzphysics@registerfamilies}[2]{% \expandafter\gdef\csname tikzphysics@families@#1\endcsname{#2}% } %% ============================================================ %% LOGICAL SHAPE OVERRIDE %% %% Some physics* names are styles that reuse a base PGF shape %% (e.g. physicsblock is shape=rectangle, physicspulley is shape=circle). %% For debug lookup we want the *logical* name so the right %% anchor/key list is shown. %% %% Usage inside a style: %% my shape/.style = { %% shape = rectangle, %% physics logical shape = my shape, %% ... %% } %% %% The drawer checks \tikzphysics@logical@shape@ before %% falling back to \pgf@sh@ns@. %% ============================================================ \tikzset{ %% We use `prefix after command' rather than `append after %% command' so the logical-shape recorder runs BEFORE any %% debug emitter that was queued via `every node/.append %% style' at a wider scope. Without that ordering, the %% emitter would look up the shape while the override is %% still undefined and fall through to PGF's base shape. physics logical shape/.code = {% \pgfkeysalso{% prefix after command = {% \pgfextra{% \edef\tikzphysics@logical@tmpnode{\tikzlastnode}% \expandafter\xdef \csname tikzphysics@logical@shape@\tikzphysics@logical@tmpnode\endcsname{#1}% }% }% }% }, } %% ============================================================ %% DEBUG OVERLAY %% %% Keys (all under the `physics debug/' path, cascadable from %% tikzpicture -> scope -> node): %% physics debug/anchors = true | false %% physics debug/keys = true | false %% physics debug/all = true | false (shorthand for both) %% %% Debug output is allowed to bleed outside the node's bounding %% box; this is intentional, because the feature is a coding aid %% and users will always disable it before final typesetting. %% %% Visual style is tunable via the following keys: %% physics debug/anchor dot color %% physics debug/anchor dot radius %% physics debug/anchor label color %% physics debug/anchor label font %% physics debug/key label color %% physics debug/key label font %% ============================================================ %% Snapshot options while the node is still being constructed, then restore %% them in its after-command hook. This makes local false overrides, local %% colours and multiple differently configured nodes reliable. \newif\iftikzphysics@debug@anchors \newif\iftikzphysics@debug@keys \def\tikzphysics@debug@properties{anchors,keys,anchor list,anchor families,anchor samples,anchor dot color,anchor dot radius,anchor label color,anchor label font,key label color,key label font,anchor legend xshift,anchor legend yshift,key panel xshift,key panel yshift} \tikzset{ physics debug/.cd, anchors/.is choice, anchors/true/.code={\pgfkeyssetvalue{/tikz/physics debug/anchors}{true}}, anchors/false/.code={\pgfkeyssetvalue{/tikz/physics debug/anchors}{false}}, anchors/.initial=false, anchors/.default=true, keys/.is choice, keys/true/.code={\pgfkeyssetvalue{/tikz/physics debug/keys}{true}}, keys/false/.code={\pgfkeyssetvalue{/tikz/physics debug/keys}{false}}, keys/.initial=false, keys/.default=true, all/.style={/tikz/physics debug/anchors=#1,/tikz/physics debug/keys=#1}, all/.default=true, anchor legend xshift/.initial=0pt, anchor legend yshift/.initial=-4mm, key panel xshift/.initial=0pt, key panel yshift/.initial=4mm, anchor list/.initial=auto, anchor families/.initial={}, anchor samples/.initial={0,25,50,75,100}, anchor dot color/.initial=red, anchor dot radius/.initial=1.2pt, anchor label color/.initial=red!80!black, anchor label font/.initial=\scriptsize\ttfamily, key label color/.initial=gray, key label font/.initial=\tiny\ttfamily, /tikz/show anchors/.style={physics debug/anchors=#1}, /tikz/show anchors/.default=true, /tikz/show keys/.style={physics debug/keys=#1}, /tikz/show keys/.default=true, %% TikZ normally gives an unnamed node its internal name after node text %% has been processed. The debug snapshot runs during that text phase, so %% assign the same internal name early enough for both hooks to use it. /tikz/physics debug ensure name/.code={\tikz@fig@mustbenamed}, /tikz/physics debug setup/.style={ /tikz/physics debug ensure name, execute at begin node=\tikzphysics@debug@snapshot, append after command={\pgfextra{ \edef\tikzphysics@debug@do{\noexpand\tikzphysics@debug@emit{\tikzlastnode}}% \tikzphysics@debug@do }} }, } %% Draw debugging above filled nodes, while retaining the document's layers. \pgfdeclarelayer{tikzphysicsdebug} \tikzset{every picture/.append style={execute at begin picture={% \edef\tikzphysics@debug@layers{\pgf@layerlist}% \def\tikzphysics@debug@found{0}% \@for\tikzphysics@debug@layer:=\tikzphysics@debug@layers\do{% \def\tikzphysics@debug@wanted{tikzphysicsdebug}% \ifx\tikzphysics@debug@layer\tikzphysics@debug@wanted \def\tikzphysics@debug@found{1}% \fi}% \ifnum\tikzphysics@debug@found=0 \expandafter\pgfsetlayers\expandafter{\tikzphysics@debug@layers,tikzphysicsdebug}% \fi}}} \def\tikzphysics@debug@snapshot{% \ifx\tikz@fig@name\@empty\else \@for\tikzphysics@debug@prop:=\tikzphysics@debug@properties\do{% \pgfkeysgetvalue{/tikz/physics debug/\tikzphysics@debug@prop}{\tikzphysics@debug@value}% \expandafter\global\expandafter\let \csname tikzphysics@debug@saved@\tikz@fig@name @\tikzphysics@debug@prop\endcsname \tikzphysics@debug@value }% \fi } \def\tikzphysics@debug@emit#1{% \begingroup \global\expandafter\let\csname tikzphysics@debug@labeltop@#1\endcsname\@undefined \ifcsname tikzphysics@debug@saved@#1@anchors\endcsname \@for\tikzphysics@debug@prop:=\tikzphysics@debug@properties\do{% \expandafter\let\expandafter\tikzphysics@debug@value \csname tikzphysics@debug@saved@#1@\tikzphysics@debug@prop\endcsname \pgfkeyslet{/tikz/physics debug/\tikzphysics@debug@prop}{\tikzphysics@debug@value}% }% \csname tikzphysics@debug@anchors\pgfkeysvalueof{/tikz/physics debug/anchors}\endcsname \csname tikzphysics@debug@keys\pgfkeysvalueof{/tikz/physics debug/keys}\endcsname \tikzset{physics debug/all=false}% \def\tikzphysics@debug@visible{0}% \iftikzphysics@debug@anchors\def\tikzphysics@debug@visible{1}\fi \iftikzphysics@debug@keys\def\tikzphysics@debug@visible{1}\fi \ifnum\tikzphysics@debug@visible=1 \begin{pgfonlayer}{tikzphysicsdebug}% \iftikzphysics@debug@anchors\tikzphysics@debug@drawanchors{#1}\fi \iftikzphysics@debug@keys\tikzphysics@debug@drawkeys{#1}\fi \end{pgfonlayer}% \fi \fi \endgroup } %% ---- shape resolver ---- %% Return the shape name to use for debug lookup. Prefers %% physics logical shape (set by physics* styles on composite shapes) %% over pgf's raw shape name. Result goes to \tikzphysics@debug@shape. \newcommand{\tikzphysics@debug@resolveshape}[1]{% \expandafter\ifcsname tikzphysics@logical@shape@#1\endcsname \edef\tikzphysics@debug@shape{\csname tikzphysics@logical@shape@#1\endcsname}% \else \expandafter\ifcsname pgf@sh@ns@#1\endcsname \edef\tikzphysics@debug@shape{\csname pgf@sh@ns@#1\endcsname}% \else \let\tikzphysics@debug@shape\@empty \fi \fi } %% ---- drawer: anchors ---- %% For node #1, resolve its shape, then mark each distinct anchor position %% once and list every anchor in a two-pair table. Coincident anchors share %% a marker number in the table instead of piling number strings on the node. \newcounter{tikzphysics@debug@anchorcount} \newcounter{tikzphysics@debug@markercount} \newdimen\tikzphysics@debug@centerx \newdimen\tikzphysics@debug@centery \newdimen\tikzphysics@debug@miny \newdimen\tikzphysics@debug@tableoffset \newdimen\tikzphysics@debug@dx \newdimen\tikzphysics@debug@dy \newdimen\tikzphysics@debug@labelx \newdimen\tikzphysics@debug@labely \newdimen\tikzphysics@debug@labeltop \newcount\tikzphysics@debug@labeltries \newcommand{\tikzphysics@debug@drawanchors}[1]{% \begingroup \tikzphysics@debug@resolveshape{#1}% \ifx\tikzphysics@debug@shape\@empty\else \expandafter\ifcsname tikzphysics@anchors@\tikzphysics@debug@shape\endcsname \edef\tikzphysics@debug@list{\csname tikzphysics@anchors@\tikzphysics@debug@shape\endcsname}% \def\tikzphysics@debug@auto{auto}% \edef\tikzphysics@debug@selection{\pgfkeysvalueof{/tikz/physics debug/anchor list}}% \ifx\tikzphysics@debug@selection\tikzphysics@debug@auto \ifcsname tikzphysics@reference@anchors@\tikzphysics@debug@shape\endcsname \edef\tikzphysics@debug@list{\csname tikzphysics@reference@anchors@\tikzphysics@debug@shape\endcsname}% \fi \else \let\tikzphysics@debug@list\tikzphysics@debug@selection \fi \edef\tikzphysics@debug@families{\pgfkeysvalueof{/tikz/physics debug/anchor families}}% \edef\tikzphysics@debug@samples{\pgfkeysvalueof{/tikz/physics debug/anchor samples}}% \def\tikzphysics@debug@all{all}% \ifx\tikzphysics@debug@families\tikzphysics@debug@all \ifcsname tikzphysics@reference@families@\tikzphysics@debug@shape\endcsname \edef\tikzphysics@debug@families{\csname tikzphysics@reference@families@\tikzphysics@debug@shape\endcsname}% \else\let\tikzphysics@debug@families\@empty\fi \fi %% Expand native foreach ranges such as 0,1,...,100 before combining %% them with family names. The resulting list is local to this drawer. \gdef\tikzphysics@debug@expanded{}% \foreach \tikzphysics@debug@sample in \tikzphysics@debug@samples{% \ifx\tikzphysics@debug@expanded\@empty \xdef\tikzphysics@debug@expanded{\tikzphysics@debug@sample}% \else \xdef\tikzphysics@debug@expanded{\tikzphysics@debug@expanded,\tikzphysics@debug@sample}% \fi }% \let\tikzphysics@debug@samples\tikzphysics@debug@expanded \@for\tikzphysics@debug@family:=\tikzphysics@debug@families\do{% \@for\tikzphysics@debug@sample:=\tikzphysics@debug@samples\do{% \ifx\tikzphysics@debug@list\@empty \edef\tikzphysics@debug@list{\tikzphysics@debug@family-\tikzphysics@debug@sample}% \else \edef\tikzphysics@debug@list{\tikzphysics@debug@list,\tikzphysics@debug@family-\tikzphysics@debug@sample}% \fi }% }% \edef\tikzphysics@debug@dotcolor{\pgfkeysvalueof{/tikz/physics debug/anchor dot color}}% \edef\tikzphysics@debug@dotradius{\pgfkeysvalueof{/tikz/physics debug/anchor dot radius}}% \edef\tikzphysics@debug@labelcolor{\pgfkeysvalueof{/tikz/physics debug/anchor label color}}% \pgf@process{\pgfpointanchor{#1}{center}}% \tikzphysics@debug@centerx=\pgf@x \tikzphysics@debug@centery=\pgf@y \tikzphysics@debug@miny=\pgf@y %% One marker per position; coincident anchors share its table number. \setcounter{tikzphysics@debug@anchorcount}{0}% \setcounter{tikzphysics@debug@markercount}{0}% \def\tikzphysics@debug@clusters{}% \@for\tikzphysics@debug@a:=\tikzphysics@debug@list\do{% \stepcounter{tikzphysics@debug@anchorcount}% \pgf@process{\pgfpointanchor{#1}{\tikzphysics@debug@a}}% \ifdim\pgf@y<\tikzphysics@debug@miny \tikzphysics@debug@miny=\pgf@y \fi \edef\tikzphysics@debug@px{\the\pgf@x}% \edef\tikzphysics@debug@py{\the\pgf@y}% %% Compare distances instead of rounded grid cells: equivalent %% formulae may land on opposite sides of a rounding boundary. \def\tikzphysics@debug@cluster{}% \@for\tikzphysics@debug@previous:=\tikzphysics@debug@clusters\do{% \tikzphysics@debug@dx=\tikzphysics@debug@px\relax \advance\tikzphysics@debug@dx by-\csname tikzphysics@debug@px@\tikzphysics@debug@previous\endcsname\relax \tikzphysics@debug@dy=\tikzphysics@debug@py\relax \advance\tikzphysics@debug@dy by-\csname tikzphysics@debug@py@\tikzphysics@debug@previous\endcsname\relax \ifdim\tikzphysics@debug@dx<0pt\tikzphysics@debug@dx=-\tikzphysics@debug@dx\fi \ifdim\tikzphysics@debug@dy<0pt\tikzphysics@debug@dy=-\tikzphysics@debug@dy\fi \ifdim\tikzphysics@debug@dx<.1pt\ifdim\tikzphysics@debug@dy<.1pt \let\tikzphysics@debug@cluster\tikzphysics@debug@previous \fi\fi}% \ifx\tikzphysics@debug@cluster\@empty \edef\tikzphysics@debug@cluster{\arabic{tikzphysics@debug@anchorcount}}% \expandafter\edef\csname tikzphysics@debug@px@\tikzphysics@debug@cluster\endcsname{\tikzphysics@debug@px}% \expandafter\edef\csname tikzphysics@debug@py@\tikzphysics@debug@cluster\endcsname{\tikzphysics@debug@py}% \fi \ifcsname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname \edef\tikzphysics@debug@marker{\csname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname}% \else \stepcounter{tikzphysics@debug@markercount}% \edef\tikzphysics@debug@marker{\arabic{tikzphysics@debug@markercount}}% \expandafter\edef\csname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname{\tikzphysics@debug@marker}% \expandafter\edef\csname tikzphysics@debug@location@\tikzphysics@debug@cluster\endcsname{\tikzphysics@debug@a}% \ifx\tikzphysics@debug@clusters\@empty \let\tikzphysics@debug@clusters\tikzphysics@debug@cluster \else \edef\tikzphysics@debug@clusters{\tikzphysics@debug@clusters,\tikzphysics@debug@cluster}% \fi \fi \expandafter\edef\csname tikzphysics@debug@markerfor@\arabic{tikzphysics@debug@anchorcount}\endcsname{\tikzphysics@debug@marker}% }% \tikzphysics@debug@tableoffset=\tikzphysics@debug@miny \advance\tikzphysics@debug@tableoffset by -\tikzphysics@debug@centery \def\tikzphysics@debug@placedlabels{}% \tikzphysics@debug@labeltop=\tikzphysics@debug@centery \@for\tikzphysics@debug@cluster:=\tikzphysics@debug@clusters\do{% \edef\tikzphysics@debug@a{\csname tikzphysics@debug@location@\tikzphysics@debug@cluster\endcsname}% \edef\tikzphysics@debug@marker{\csname tikzphysics@debug@cluster@\tikzphysics@debug@cluster\endcsname}% \pgf@process{\pgfpointanchor{#1}{\tikzphysics@debug@a}}% \ifdim\pgf@x<\tikzphysics@debug@centerx \def\tikzphysics@debug@labelanchor{east}% \def\tikzphysics@debug@labelshift{-2pt}% \else \def\tikzphysics@debug@labelanchor{west}% \def\tikzphysics@debug@labelshift{2pt}% \fi \pgf@process{\pgfpointanchor{#1}{\tikzphysics@debug@a}}% \edef\tikzphysics@debug@markery{\the\pgf@y}% \tikzphysics@debug@labelx=\pgf@x \advance\tikzphysics@debug@labelx by\tikzphysics@debug@labelshift \tikzphysics@debug@labely=\pgf@y \tikzphysics@debug@labeltries=0 \def\tikzphysics@debug@retry{1}% \loop \def\tikzphysics@debug@retry{0}% \@for\tikzphysics@debug@previous:=\tikzphysics@debug@placedlabels\do{% \tikzphysics@debug@dx=\tikzphysics@debug@labelx \advance\tikzphysics@debug@dx by-\csname tikzphysics@debug@lx@\tikzphysics@debug@previous\endcsname\relax \tikzphysics@debug@dy=\tikzphysics@debug@labely \advance\tikzphysics@debug@dy by-\csname tikzphysics@debug@ly@\tikzphysics@debug@previous\endcsname\relax \ifdim\tikzphysics@debug@dx<0pt\tikzphysics@debug@dx=-\tikzphysics@debug@dx\fi \ifdim\tikzphysics@debug@dy<0pt\tikzphysics@debug@dy=-\tikzphysics@debug@dy\fi \ifdim\tikzphysics@debug@dx<12pt\ifdim\tikzphysics@debug@dy<7pt \def\tikzphysics@debug@retry{1}% \fi\fi}% \ifnum\tikzphysics@debug@retry=1 \advance\tikzphysics@debug@labely by7pt \fi \advance\tikzphysics@debug@labeltries by1 \ifnum\tikzphysics@debug@labeltries>\value{tikzphysics@debug@markercount} \def\tikzphysics@debug@retry{0}% \fi \ifnum\tikzphysics@debug@retry=1\repeat \expandafter\edef\csname tikzphysics@debug@lx@\tikzphysics@debug@cluster\endcsname{\the\tikzphysics@debug@labelx}% \expandafter\edef\csname tikzphysics@debug@ly@\tikzphysics@debug@cluster\endcsname{\the\tikzphysics@debug@labely}% \ifx\tikzphysics@debug@placedlabels\@empty \let\tikzphysics@debug@placedlabels\tikzphysics@debug@cluster \else \edef\tikzphysics@debug@placedlabels{\tikzphysics@debug@placedlabels,\tikzphysics@debug@cluster}% \fi \tikzphysics@debug@dy=\tikzphysics@debug@labely \advance\tikzphysics@debug@dy by-\tikzphysics@debug@markery \edef\tikzphysics@debug@labelyshift{\the\tikzphysics@debug@dy}% \ifdim\tikzphysics@debug@labely>\tikzphysics@debug@labeltop \tikzphysics@debug@labeltop=\tikzphysics@debug@labely \fi \ifdim\tikzphysics@debug@dy>0pt \draw[\tikzphysics@debug@dotcolor,line width=.2pt] (#1.\tikzphysics@debug@a)--++(0,\tikzphysics@debug@labelyshift);% \fi \fill[\tikzphysics@debug@dotcolor] (#1.\tikzphysics@debug@a) circle (\tikzphysics@debug@dotradius);% \node[\tikzphysics@debug@dotcolor,font=\tiny\bfseries, inner sep=.4pt,fill=white,fill opacity=.9,text opacity=1, anchor=\tikzphysics@debug@labelanchor, xshift=\tikzphysics@debug@labelshift, yshift=\tikzphysics@debug@labelyshift] at (#1.\tikzphysics@debug@a) {\tikzphysics@debug@marker};% }% \expandafter\xdef\csname tikzphysics@debug@labeltop@#1\endcsname{\the\tikzphysics@debug@labeltop}% %% Pass 2: put every anchor in a numbered, two-pair table. \setcounter{tikzphysics@debug@anchorcount}{0}% \gdef\tikzphysics@debug@legendrows{}% \foreach \tikzphysics@debug@a in \tikzphysics@debug@list {% \stepcounter{tikzphysics@debug@anchorcount}% \edef\tikzphysics@debug@marker{\csname tikzphysics@debug@markerfor@\arabic{tikzphysics@debug@anchorcount}\endcsname}% %% Odd entries start a new row; even entries end it. \ifodd\value{tikzphysics@debug@anchorcount}% %% Add row separator before odd entries (except the first) \ifnum\value{tikzphysics@debug@anchorcount}>1 \expandafter\xdef\expandafter\tikzphysics@debug@legendrows\expandafter{% \tikzphysics@debug@legendrows \noexpand\\ \tikzphysics@debug@marker \noexpand& \tikzphysics@debug@a}% \else \expandafter\xdef\expandafter\tikzphysics@debug@legendrows\expandafter{% \tikzphysics@debug@legendrows \tikzphysics@debug@marker \noexpand& \tikzphysics@debug@a}% \fi \else \expandafter\xdef\expandafter\tikzphysics@debug@legendrows\expandafter{% \tikzphysics@debug@legendrows \noexpand& \tikzphysics@debug@marker \noexpand& \tikzphysics@debug@a}% \fi }% %% Keep the marker/anchor pairs together in a readable reference card. \node[\tikzphysics@debug@labelcolor, font=\pgfkeysvalueof{/tikz/physics debug/anchor label font}, anchor=north west, inner sep=2pt, fill=white, fill opacity=0.9, text opacity=1, draw=\tikzphysics@debug@dotcolor, draw opacity=0.3, line width=0.2pt, rounded corners=1pt, xshift=\pgfkeysvalueof{/tikz/physics debug/anchor legend xshift}, yshift=\the\tikzphysics@debug@tableoffset, yshift=\pgfkeysvalueof{/tikz/physics debug/anchor legend yshift}] at (#1.center) {\begin{tabular}{@{}r@{\enspace}l@{\qquad}r@{\enspace}l@{}} \multicolumn{4}{@{}l}{\bfseries Anchors}\tabularnewline[2pt] \# & Name & \# & Name\tabularnewline\hline \tikzphysics@debug@legendrows \end{tabular}};% \fi \fi \endgroup } %% Reference content is generated from module declarations. This is an API %% reference, explicitly labelled as defaults rather than live node values. \newcommand{\tikzphysics@debug@drawkeys}[1]{% \begingroup \tikzphysics@debug@resolveshape{#1}% \ifcsname tikzphysics@reference@body@\tikzphysics@debug@shape\endcsname \pgf@process{\pgfpointanchor{#1}{center}}% \edef\tikzphysics@debug@panelx{\the\pgf@x}% \tikzphysics@debug@miny=\pgf@y \edef\tikzphysics@debug@list{\csname tikzphysics@reference@anchors@\tikzphysics@debug@shape\endcsname}% \@for\tikzphysics@debug@a:=\tikzphysics@debug@list\do{% \pgf@process{\pgfpointanchor{#1}{\tikzphysics@debug@a}}% \ifdim\pgf@y>\tikzphysics@debug@miny \tikzphysics@debug@miny=\pgf@y \fi}% \ifcsname tikzphysics@debug@labeltop@#1\endcsname \tikzphysics@debug@dy=\csname tikzphysics@debug@labeltop@#1\endcsname\relax \ifdim\tikzphysics@debug@dy>\tikzphysics@debug@miny \tikzphysics@debug@miny=\tikzphysics@debug@dy \fi \fi \edef\tikzphysics@debug@panely{\the\tikzphysics@debug@miny}% \node[physics debug/all=false,anchor=south west,fill=white, draw=gray!50,inner sep=4pt,align=left,text width=8cm, font=\pgfkeysvalueof{/tikz/physics debug/key label font}, text=\pgfkeysvalueof{/tikz/physics debug/key label color}, xshift=\pgfkeysvalueof{/tikz/physics debug/key panel xshift}, yshift=\pgfkeysvalueof{/tikz/physics debug/key panel yshift}] at (\tikzphysics@debug@panelx,\tikzphysics@debug@panely) {\csname tikzphysics@reference@body@\tikzphysics@debug@shape\endcsname}; \fi \endgroup } %% Standalone reference card, usable inside a tikzpicture for nodes, paths, %% and pics alike. Ordinary node options position/style the card. \newcommand{\physicshelp}[2][]{% \begingroup \ifcsname tikzphysics@reference@lookup@#2\endcsname \edef\tikzphysics@debug@shape{\csname tikzphysics@reference@lookup@#2\endcsname}% \node[physics debug/all=false,draw=gray!50,fill=white, rounded corners=2pt,inner sep=6pt,align=left,text width=9cm, font=\scriptsize\ttfamily,#1] {\csname tikzphysics@reference@body@\tikzphysics@debug@shape\endcsname}; \else \PackageError{tikzphysics}{Unknown reference topic `#2'}% {Use a public style name such as wedge, spring, pulley, or pendulum.}% \fi \endgroup } \let\tikzphysicshelp\physicshelp %% BEGIN NATIVE COMPONENT EXTENSIONS %% Common component helpers. Length scalars are centimetres; the node state %% stores resolved values, so later keys cannot alter an earlier instance. \def\tikzphysics@component@length#1#2{% \pgfmathparse{\pgfkeysvalueof{/tikz/#2}}% \ifpgfmathunitsdeclared \pgfmathsetlength\pgf@x{\pgfmathresult pt}% \else\pgfmathsetlength\pgf@x{\pgfmathresult cm}\fi% \pgfmathsetmacro#1{\pgf@x/1cm}% } \def\tikzphysics@component@check#1#2{% \pgfmathtruncatemacro\tikzphysics@component@valid{#1}% \ifnum\tikzphysics@component@valid=1\else \PackageError{tikzphysics}{#2}{See the native components guide for valid dimensions.}% \fi } \def\tikzphysics@component@point#1#2{\pgfpoint{(#1)*1cm}{(#2)*1cm}} \def\tikzphysics@component@move#1#2{\pgfpathmoveto{\tikzphysics@component@point{#1}{#2}}} \def\tikzphysics@component@line#1#2{\pgfpathlineto{\tikzphysics@component@point{#1}{#2}}} \def\tikzphysics@component@ellipse#1#2#3#4{% \pgfpathellipse{\tikzphysics@component@point{#1}{#2}}% {\tikzphysics@component@point{#3}{0}}{\tikzphysics@component@point{0}{#4}}} %% END NATIVE COMPONENT EXTENSIONS \makeatother \usetikzlibrary{tikzphysics.catalog} \endinput .