| 1 |
% \iffalse |
| 2 |
% -------------------------------------------------------------------- |
| 3 |
%<*hex> |
| 4 |
% \fi |
| 5 |
% |
| 6 |
% \subsubsection{Ridges} |
| 7 |
% \label{sec:impl:hex:ridges} |
| 8 |
% |
| 9 |
% A hex can be decorated with up to 6 ridges --- one for each edge of |
| 10 |
% the hexagon. The first thing is to set up the graphics style to use |
| 11 |
% for the ridges. We use the \spec{wave} decoration. |
| 12 |
% |
| 13 |
% If rounded corners are set for ridges, (e.g., via \spec{every hex |
| 14 |
% ridges}), then it should be \spec{0pt} or \spec{4pt} (roughly 2mm) |
| 15 |
% or larger. Otherwise, one will get a ``dimension too large'' |
| 16 |
% error. |
| 17 |
% |
| 18 |
% \begin{macrocode} |
| 19 |
\tikzset{% |
| 20 |
hex/ridges pre/.style={ |
| 21 |
line cap=round, |
| 22 |
draw=pgfstrokecolor, |
| 23 |
solid, |
| 24 |
/hex/ridges/.cd,% |
| 25 |
radius=0.85,% |
| 26 |
n=4, |
| 27 |
R=.25, |
| 28 |
}, |
| 29 |
hex/ridges/.style={ |
| 30 |
get scale, |
| 31 |
decoration={ |
| 32 |
path has corners=true, |
| 33 |
waves, |
| 34 |
radius=\wg@scale\hex@r@R, |
| 35 |
segment length=\wg@scale\hex@r@s, |
| 36 |
}, |
| 37 |
decorate}} |
| 38 |
% \end{macrocode} |
| 39 |
% |
| 40 |
% To properly set up the ridges, we need to concatenate ridge paths in |
| 41 |
% order. To facilitate that, we define 6 \cs{if}s --- one for each |
| 42 |
% edge. |
| 43 |
% |
| 44 |
% \begin{macrocode} |
| 45 |
\newif\ifhex@r@ne |
| 46 |
\newif\ifhex@r@n |
| 47 |
\newif\ifhex@r@nw |
| 48 |
\newif\ifhex@r@sw |
| 49 |
\newif\ifhex@r@s |
| 50 |
\newif\ifhex@r@se |
| 51 |
% \end{macrocode} |
| 52 |
% |
| 53 |
% Next is the keys for each edge. These will set the above \cs{if}s |
| 54 |
% to \spec{true}. We put these into the family \spec{/hex/r} so that |
| 55 |
% we can parse them separately. |
| 56 |
% |
| 57 |
% \begin{macrocode} |
| 58 |
\tikzset{% |
| 59 |
/hex/ridges/.search also={/tikz}, |
| 60 |
/hex/ridges/.cd, |
| 61 |
north east/.is if=hex@r@ne, |
| 62 |
north/.is if=hex@r@n, |
| 63 |
north west/.is if=hex@r@nw, |
| 64 |
south west/.is if=hex@r@sw, |
| 65 |
south/.is if=hex@r@s, |
| 66 |
south east/.is if=hex@r@se, |
| 67 |
radius/.store in=\hex@r@r, |
| 68 |
curve radius/.store in=\hex@r@w, |
| 69 |
NE/.is if=hex@r@ne, |
| 70 |
N/.is if=hex@r@n, |
| 71 |
NW/.is if=hex@r@nw, |
| 72 |
SW/.is if=hex@r@sw, |
| 73 |
S/.is if=hex@r@s, |
| 74 |
SE/.is if=hex@r@se, |
| 75 |
r/.store in=\hex@r@r, |
| 76 |
n/.store in=\hex@r@n, |
| 77 |
R/.store in=\hex@r@w, |
| 78 |
} |
| 79 |
% \end{macrocode} |
| 80 |
% |
| 81 |
% \begin{Macro}{\hex@do@ridges} |
| 82 |
% |
| 83 |
% This is the macro that actually generates the ridge. We use the |
| 84 |
% same \textsc{pgf} filtered key parsing trick as above. Note that |
| 85 |
% the routine below is handcrafted since it is relatively simple. |
| 86 |
% |
| 87 |
% \begin{macrocode} |
| 88 |
\newdimen\hex@r@s |
| 89 |
\newdimen\hex@r@R |
| 90 |
\def\hex@do@ridges{% |
| 91 |
\edef\hex@r@tmp{[ |
| 92 |
hex/ridges pre, |
| 93 |
/tikz/every hex ridges/.try, |
| 94 |
\hex@ridges]} |
| 95 |
\expandafter\scope\hex@r@tmp% |
| 96 |
\hex@dbg{3}{Ridges: `\meaning\hex@ridges', `\meaning\hex@r@tmp' |
| 97 |
^^Jnorth east=\ifhex@r@ne yes\else no\fi |
| 98 |
^^Jnorth =\ifhex@r@n yes\else no\fi |
| 99 |
^^Jnorth west=\ifhex@r@nw yes\else no\fi |
| 100 |
^^Jsouth west=\ifhex@r@sw yes\else no\fi |
| 101 |
^^Jsouth =\ifhex@r@s yes\else no\fi |
| 102 |
^^Jsouth east=\ifhex@r@se yes\else no\fi |
| 103 |
^^Jradius =\hex@r@r |
| 104 |
^^Jn =\hex@r@n |
| 105 |
} |
| 106 |
\pgfmathparse{\hex@r@r/\hex@r@n}\xdef\hex@r@t{\pgfmathresult} |
| 107 |
\hex@r@s=\hex@r@t cm |
| 108 |
\hex@r@R=\hex@r@w cm |
| 109 |
\def\hex@r@p{} |
| 110 |
% Hand written algorithm |
| 111 |
\ifhex@r@ne |
| 112 |
\ifhex@r@se |
| 113 |
\xdef\hex@r@p{(0:\hex@r@r)--(60:\hex@r@r)} |
| 114 |
\else |
| 115 |
\xdef\hex@r@p{($(0:\hex@r@r)+(-60:\hex@r@t/2)$)--(60:\hex@r@r)} |
| 116 |
\fi |
| 117 |
\hex@dbg{4}{Ridge along north east edge: `\hex@r@p'} |
| 118 |
\fi |
| 119 |
\ifhex@r@n |
| 120 |
\ifhex@r@ne\else |
| 121 |
\xdef\hex@r@p{\hex@r@p ($( 60:\hex@r@r)+(0:\hex@r@t/2)$)} |
| 122 |
\fi |
| 123 |
\xdef\hex@r@p{\hex@r@p --(120:\hex@r@r)} |
| 124 |
\hex@dbg{4}{Ridge along north edge: `\hex@r@p'} |
| 125 |
\fi |
| 126 |
\ifhex@r@nw |
| 127 |
\ifhex@r@n\else |
| 128 |
\xdef\hex@r@p{\hex@r@p ($(120:\hex@r@r)+(60:\hex@r@t/2)$)} |
| 129 |
\fi |
| 130 |
\xdef\hex@r@p{\hex@r@p --(180:\hex@r@r)} |
| 131 |
\hex@dbg{4}{Ridge along north west: `\hex@r@p'} |
| 132 |
\fi |
| 133 |
\ifhex@r@sw |
| 134 |
\ifhex@r@nw\else |
| 135 |
\xdef\hex@r@p{\hex@r@p ($(180:\hex@r@r)+(120:\hex@r@t/2)$)} |
| 136 |
\fi |
| 137 |
\ifhex@r@s |
| 138 |
\xdef\hex@r@p{\hex@r@p --(240:\hex@r@r)} |
| 139 |
\else |
| 140 |
\xdef\hex@r@p{\hex@r@p --(240:\hex@r@r)} |
| 141 |
\fi |
| 142 |
\hex@dbg{4}{Ridge along south west: `\hex@r@p'} |
| 143 |
\fi |
| 144 |
\ifhex@r@s |
| 145 |
\ifhex@r@sw\else |
| 146 |
\xdef\hex@r@p{\hex@r@p ($(240:\hex@r@r)+(-\hex@r@t/2,0)$)} |
| 147 |
\fi |
| 148 |
\ifhex@r@se |
| 149 |
\xdef\hex@r@p{\hex@r@p --(300:\hex@r@r)} |
| 150 |
\else |
| 151 |
\xdef\hex@r@p{\hex@r@p --(300.5:\hex@r@r)} |
| 152 |
\fi |
| 153 |
\hex@dbg{4}{Ridge along south: `\hex@r@p'} |
| 154 |
\fi |
| 155 |
\ifhex@r@se |
| 156 |
\ifhex@r@s\else |
| 157 |
\xdef\hex@r@p{\hex@r@p ($(300:\hex@r@r)+(-120:\hex@r@t/2)$)} |
| 158 |
\fi |
| 159 |
\ifhex@r@ne |
| 160 |
%\xdef\hex@r@p{\hex@r@p --cycle} |
| 161 |
\xdef\hex@r@p{\hex@r@p -- (0:\hex@r@r)} |
| 162 |
\else |
| 163 |
\xdef\hex@r@p{\hex@r@p --(.5:\hex@r@r)} |
| 164 |
\fi |
| 165 |
\hex@dbg{4}{Ridge along south east: `\hex@r@p'} |
| 166 |
\fi |
| 167 |
\hex@dbg{3}{ Ridges path: \hex@r@p} |
| 168 |
% \draw[red] \hex@r@p; |
| 169 |
\draw[hex/ridges] \hex@r@p; |
| 170 |
\endscope% End of ridges scope |
| 171 |
} |
| 172 |
% \end{macrocode} |
| 173 |
% \end{Macro} |
| 174 |
% |
| 175 |
% \iffalse |
| 176 |
%</hex> |
| 177 |
% -------------------------------------------------------------------- |
| 178 |
% \fi |