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