summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/wargame/source/hex/ridges.dtx
blob: 3914ff6ce550ae88c22854c993afd22ce02e5bc1 (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
% \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. 
% 
%    \begin{macrocode}
\tikzset{%
  hex/ridges/.style={
    line cap=round,
    draw=pgfstrokecolor,
    rounded corners=.25cm,
    scale line widths,
    decoration={
      path has corners=true,
      pre=waves,
      post=waves,
      pre length=-.1cm,
      post length=0cm,
      waves,
      radius=.2cm,
      segment length=.2cm},
    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,
  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,
}
%    \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}
\def\hex@do@ridges{%
  \edef\hex@r@tmp{[
    /hex/ridges/.cd,%
    radius=0.8,%
    /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
    }
    \def\hex@r@p{}
    % Hand written algorithm
    \ifhex@r@ne
      \def\hex@r@p{(0:\hex@r@r)--(60:\hex@r@r)}
    \fi
    \ifhex@r@n
      \hex@dbg{4}{Ridge along north edge: `\hex@r@p'}
      \ifhex@r@ne\else
        \xdef\hex@r@p{\hex@r@p ( 60:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(120:\hex@r@r)}
    \fi
    \ifhex@r@nw
      \ifhex@r@n\else
        \xdef\hex@r@p{\hex@r@p (120:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(180:\hex@r@r)}
    \fi
    \ifhex@r@sw
      \ifhex@r@nw\else
        \xdef\hex@r@p{\hex@r@p (180:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(240:\hex@r@r)}
    \fi
    \ifhex@r@s
      \ifhex@r@sw\else
        \xdef\hex@r@p{\hex@r@p (240:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(300:\hex@r@r)}
    \fi
    \ifhex@r@se
      \ifhex@r@s\else
        \xdef\hex@r@p{\hex@r@p (300:\hex@r@r)}
      \fi
      \xdef\hex@r@p{\hex@r@p --(360:\hex@r@r)}
    \fi
    \hex@dbg{3}{ Ridges path: \hex@r@p}
    \draw[hex/ridges] \hex@r@p;
  \endscope% End of ridges scope 
}
%    \end{macrocode}
% \end{Macro}
% 
% \iffalse
%</hex>
% --------------------------------------------------------------------
% \fi