43 { |
43 { |
44 return (s & SLOPE_HALFTILE) != 0; |
44 return (s & SLOPE_HALFTILE) != 0; |
45 } |
45 } |
46 |
46 |
47 /** |
47 /** |
|
48 * Removes a halftile slope from a slope |
|
49 * |
|
50 * Non-halftile slopes remain unmodified. |
|
51 * |
|
52 * @param s A #Slope. |
|
53 * @return The slope s without it's halftile slope. |
|
54 */ |
|
55 static inline Slope RemoveHalftileSlope(Slope s) |
|
56 { |
|
57 return (Slope)(s & ~SLOPE_HALFTILE_MASK); |
|
58 } |
|
59 |
|
60 /** |
48 * Return the complement of a slope. |
61 * Return the complement of a slope. |
49 * |
62 * |
50 * This method returns the complement of a slope. The complement of a |
63 * This method returns the complement of a slope. The complement of a |
51 * slope is a slope with raised corner which aren't raised in the given |
64 * slope is a slope with raised corner which aren't raised in the given |
52 * slope. |
65 * slope. |
60 assert(!IsSteepSlope(s) && !IsHalftileSlope(s)); |
73 assert(!IsSteepSlope(s) && !IsHalftileSlope(s)); |
61 return (Slope)(0xF ^ s); |
74 return (Slope)(0xF ^ s); |
62 } |
75 } |
63 |
76 |
64 /** |
77 /** |
|
78 * Tests if a specific slope has exactly one corner raised. |
|
79 * |
|
80 * @param s The #Slope |
|
81 * @return true iff exactly one corner is raised |
|
82 */ |
|
83 static inline bool IsSlopeWithOneCornerRaised(Slope s) |
|
84 { |
|
85 return (s == SLOPE_W) || (s == SLOPE_S) || (s == SLOPE_E) || (s == SLOPE_N); |
|
86 } |
|
87 |
|
88 /** |
|
89 * Returns the slope with a specific corner raised. |
|
90 * |
|
91 * @param corner The #Corner. |
|
92 * @return The #Slope with corner "corner" raised. |
|
93 */ |
|
94 static inline Slope SlopeWithOneCornerRaised(Corner corner) |
|
95 { |
|
96 assert(IsValidCorner(corner)); |
|
97 return (Slope)(1 << corner); |
|
98 } |
|
99 |
|
100 /** |
65 * Tests if a slope has a highest corner (i.e. one corner raised or a steep slope). |
101 * Tests if a slope has a highest corner (i.e. one corner raised or a steep slope). |
66 * |
102 * |
67 * Note: A halftile slope is ignored. |
103 * Note: A halftile slope is ignored. |
68 * |
104 * |
69 * @param s The #Slope. |
105 * @param s The #Slope. |
70 * @return true iff the slope has a highest corner. |
106 * @return true iff the slope has a highest corner. |
71 */ |
107 */ |
72 static inline bool HasSlopeHighestCorner(Slope s) |
108 static inline bool HasSlopeHighestCorner(Slope s) |
73 { |
109 { |
74 s = (Slope)(s & ~SLOPE_HALFTILE_MASK); |
110 s = RemoveHalftileSlope(s); |
75 return IsSteepSlope(s) || (s == SLOPE_W) || (s == SLOPE_S) || (s == SLOPE_E) || (s == SLOPE_N); |
111 return IsSteepSlope(s) || IsSlopeWithOneCornerRaised(s); |
76 } |
112 } |
77 |
113 |
78 /** |
114 /** |
79 * Returns the highest corner of a slope (one corner raised or a steep slope). |
115 * Returns the highest corner of a slope (one corner raised or a steep slope). |
80 * |
116 * |
82 * @param s The #Slope. |
118 * @param s The #Slope. |
83 * @return Highest corner. |
119 * @return Highest corner. |
84 */ |
120 */ |
85 static inline Corner GetHighestSlopeCorner(Slope s) |
121 static inline Corner GetHighestSlopeCorner(Slope s) |
86 { |
122 { |
87 switch (s & ~SLOPE_HALFTILE_MASK) { |
123 switch (RemoveHalftileSlope(s)) { |
88 case SLOPE_W: |
124 case SLOPE_W: |
89 case SLOPE_STEEP_W: return CORNER_W; |
125 case SLOPE_STEEP_W: return CORNER_W; |
90 case SLOPE_S: |
126 case SLOPE_S: |
91 case SLOPE_STEEP_S: return CORNER_S; |
127 case SLOPE_STEEP_S: return CORNER_S; |
92 case SLOPE_E: |
128 case SLOPE_E: |
133 { |
169 { |
134 return (Corner)(corner ^ 2); |
170 return (Corner)(corner ^ 2); |
135 } |
171 } |
136 |
172 |
137 /** |
173 /** |
138 * Returns the slope with a specific corner raised. |
174 * Tests if a specific slope has exactly three corners raised. |
139 * |
175 * |
140 * @param corner The #Corner. |
176 * @param s The #Slope |
141 * @return The #Slope with corner "corner" raised. |
177 * @return true iff exactly three corners are raised |
142 */ |
178 */ |
143 static inline Slope SlopeWithOneCornerRaised(Corner corner) |
179 static inline bool IsSlopeWithThreeCornersRaised(Slope s) |
144 { |
180 { |
145 assert(IsValidCorner(corner)); |
181 return !IsHalftileSlope(s) && !IsSteepSlope(s) && IsSlopeWithOneCornerRaised(ComplementSlope(s)); |
146 return (Slope)(1 << corner); |
|
147 } |
182 } |
148 |
183 |
149 /** |
184 /** |
150 * Returns the slope with all except one corner raised. |
185 * Returns the slope with all except one corner raised. |
151 * |
186 * |
153 * @return The #Slope with all corners but "corner" raised. |
188 * @return The #Slope with all corners but "corner" raised. |
154 */ |
189 */ |
155 static inline Slope SlopeWithThreeCornersRaised(Corner corner) |
190 static inline Slope SlopeWithThreeCornersRaised(Corner corner) |
156 { |
191 { |
157 return ComplementSlope(SlopeWithOneCornerRaised(corner)); |
192 return ComplementSlope(SlopeWithOneCornerRaised(corner)); |
|
193 } |
|
194 |
|
195 /** |
|
196 * Returns a specific steep slope |
|
197 * |
|
198 * @param corner A #Corner. |
|
199 * @return The steep #Slope with "corner" as highest corner. |
|
200 */ |
|
201 static inline Slope SteepSlope(Corner corner) |
|
202 { |
|
203 return (Slope)(SLOPE_STEEP | SlopeWithThreeCornersRaised(OppositeCorner(corner))); |
|
204 } |
|
205 |
|
206 /** |
|
207 * Tests if a specific slope is an inclined slope. |
|
208 * |
|
209 * @param s The #Slope |
|
210 * @return true iff the slope is inclined. |
|
211 */ |
|
212 static inline bool IsInclinedSlope(Slope s) |
|
213 { |
|
214 return (s == SLOPE_NW) || (s == SLOPE_SW) || (s == SLOPE_SE) || (s == SLOPE_NE); |
|
215 } |
|
216 |
|
217 /** |
|
218 * Returns the direction of an inclined slope. |
|
219 * |
|
220 * @param s A #Slope |
|
221 * @return The direction the slope goes up in. Or INVALID_DIAGDIR if the slope is not an inclined slope. |
|
222 */ |
|
223 static inline DiagDirection GetInclinedSlopeDirection(Slope s) |
|
224 { |
|
225 switch (s) { |
|
226 case SLOPE_NE: return DIAGDIR_NE; |
|
227 case SLOPE_SE: return DIAGDIR_SE; |
|
228 case SLOPE_SW: return DIAGDIR_SW; |
|
229 case SLOPE_NW: return DIAGDIR_NW; |
|
230 default: return INVALID_DIAGDIR; |
|
231 } |
|
232 } |
|
233 |
|
234 /** |
|
235 * Returns the slope, that is inclined in a specific direction. |
|
236 * |
|
237 * @param dir A #DiagDirection |
|
238 * @return The #Slope that goes up in direction dir. |
|
239 */ |
|
240 static inline Slope InclinedSlope(DiagDirection dir) |
|
241 { |
|
242 switch (dir) { |
|
243 case DIAGDIR_NE: return SLOPE_NE; |
|
244 case DIAGDIR_SE: return SLOPE_SE; |
|
245 case DIAGDIR_SW: return SLOPE_SW; |
|
246 case DIAGDIR_NW: return SLOPE_NW; |
|
247 default: NOT_REACHED(); |
|
248 } |
158 } |
249 } |
159 |
250 |
160 /** |
251 /** |
161 * Adds a halftile slope to a slope. |
252 * Adds a halftile slope to a slope. |
162 * |
253 * |