Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diamond shape: keep aspect when checking against minimum ht/wd #1042

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions doc/generic/pgf/text-en/pgfmanual-en-tikz-shapes.tex
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,13 @@ \subsubsection{Common Options: Separations, Margins, Padding and
%
\end{key}

\begin{key}{/pgf/shape aspect=\meta{aspect ratio}}
\begin{key}{/pgf/shape aspect=\meta{aspect ratio} (initially none)}
\keyalias{tikz}
Sets a desired aspect ratio for the shape. For the |diamond| shape, this
option sets the ratio between width and height of the shape.
option sets the ratio between width and height of the shape. Unlike
|/pgf/aspect| which only recommends the ratio, this key ensures it.

If the special value |none| is given, the ratio assurance is canceled.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the special none value? I would have just left it empty.

%
\begin{codeexample}[preamble={\usetikzlibrary{shapes.geometric}}]
\begin{tikzpicture}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,15 @@
%
\pgfkeys{/pgf/.cd,
aspect/.code={\pgfsetshapeaspect{#1}},% this for tikz...
shape aspect/.initial=1,% but this is consistent with other pgfset stuff.
shape aspect/.initial=none,% but this is consistent with other pgfset stuff.
shape aspect/.code={%
\pgfkeys{/pgf/aspect=#1}%
\pgfkeyssetvalue{/pgf/shape aspect}{#1}
\edef\pgf@lib@temp{#1}%
\ifx\pgf@lib@temp\pgf@nonetext
\pgfkeys{/pgf/aspect=1}%
\else
\pgfkeys{/pgf/aspect=#1}%
\fi
\pgfkeyssetvalue{/pgf/shape aspect}{#1}%
Comment on lines +216 to +221
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default was empty the code could be simplified (untested).

Suggested change
\ifx\pgf@lib@temp\pgf@nonetext
\pgfkeys{/pgf/aspect=1}%
\else
\pgfkeys{/pgf/aspect=#1}%
\fi
\pgfkeyssetvalue{/pgf/shape aspect}{#1}%
\pgfqkeys{/pgf}{aspect/.expanded=\pgfutil@ifxempty\pgf@lib@temp{1}{#1}}%
\pgfkeyssetvalue{/pgf/shape aspect}{#1}%

Same for the other conditionals.

}%
}%

Expand Down Expand Up @@ -252,18 +257,29 @@
\pgf@y=\pgfshapeaspectinverse\pgf@xa%
\advance\pgf@y by\pgf@ya%
%
% Check against minimum height/width
% Check against minimum height/width while keeping the shape aspect
% if `/pgf/shape aspect` is set
%
\pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
\pgf@xb=.5\pgf@xb%
\pgfkeysgetvalue{/pgf/shape aspect}\pgf@lib@temp
\PackageWarning{pgf}{\meaning\pgf@lib@temp}%
\ifdim\pgf@x<\pgf@xb%
% yes, too small. Enlarge...
\ifx\pgf@lib@temp\pgf@nonetext
\else
\advance\pgf@y by\pgfshapeaspectinverse\dimexpr\pgf@xb-\pgf@x\relax
\fi
\pgf@x=\pgf@xb%
\fi%
\pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
\pgf@yb=.5\pgf@yb%
\ifdim\pgf@y<\pgf@yb%
% yes, too small. Enlarge...
\ifx\pgf@lib@temp\pgf@nonetext
\else
\advance\pgf@x by\pgfshapeaspect\dimexpr\pgf@yb-\pgf@y\relax
\fi
\pgf@y=\pgf@yb%
\fi%
%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,14 @@
%
\pgfkeys{/pgf/.cd,
aspect/.code={\pgfsetshapeaspect{#1}},% this for tikz...
shape aspect/.initial=1,% but this is consistent with other pgfset stuff.
shape aspect/.initial=none,% but this is consistent with other pgfset stuff.
shape aspect/.code={%
\pgfkeys{/pgf/aspect=#1}%
\edef\pgf@lib@temp{#1}%
\ifx\pgf@lib@temp\pgf@nonetext
\pgfkeys{/pgf/aspect=1}%
\else
\pgfkeys{/pgf/aspect=#1}%
\fi
\pgfkeyssetvalue{/pgf/shape aspect}{#1}
}%
}%
Expand Down