|
1 /* $Id$ */ |
|
2 |
|
3 /** @file road_func.h Functions related to roads. */ |
|
4 |
|
5 #ifndef ROAD_FUNC_H |
|
6 #define ROAD_FUNC_H |
|
7 |
|
8 #include "core/bitmath_func.hpp" |
|
9 #include "road_type.h" |
|
10 #include "direction_func.h" |
|
11 |
|
12 /** |
|
13 * Whether the given roadtype is valid. |
|
14 * @param rt the roadtype to check for validness |
|
15 * @return true if and only if valid |
|
16 */ |
|
17 static inline bool IsValidRoadType(RoadType rt) |
|
18 { |
|
19 return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM; |
|
20 } |
|
21 |
|
22 /** |
|
23 * Are the given bits pointing to valid roadtypes? |
|
24 * @param rts the roadtypes to check for validness |
|
25 * @return true if and only if valid |
|
26 */ |
|
27 static inline bool AreValidRoadTypes(RoadTypes rts) |
|
28 { |
|
29 return HasBit(rts, ROADTYPE_ROAD) || HasBit(rts, ROADTYPE_TRAM); |
|
30 } |
|
31 |
|
32 /** |
|
33 * Maps a RoadType to the corresponding RoadTypes value |
|
34 * |
|
35 * @param rt the roadtype to get the roadtypes from |
|
36 * @return the roadtypes with the given roadtype |
|
37 */ |
|
38 static inline RoadTypes RoadTypeToRoadTypes(RoadType rt) |
|
39 { |
|
40 return (RoadTypes)(1 << rt); |
|
41 } |
|
42 |
|
43 /** |
|
44 * Returns the RoadTypes which are not present in the given RoadTypes |
|
45 * |
|
46 * This function returns the complement of a given RoadTypes. |
|
47 * |
|
48 * @param r The given RoadTypes |
|
49 * @return The complement of the given RoadTypes |
|
50 * @note The unused value ROADTYPES_HWAY will be used, too. |
|
51 */ |
|
52 static inline RoadTypes ComplementRoadTypes(RoadTypes r) |
|
53 { |
|
54 return (RoadTypes)(ROADTYPES_ALL ^ r); |
|
55 } |
|
56 |
|
57 |
|
58 /** |
|
59 * Calculate the complement of a RoadBits value |
|
60 * |
|
61 * Simply flips all bits in the RoadBits value to get the complement |
|
62 * of the RoadBits. |
|
63 * |
|
64 * @param r The given RoadBits value |
|
65 * @return the complement |
|
66 */ |
|
67 static inline RoadBits ComplementRoadBits(RoadBits r) |
|
68 { |
|
69 return (RoadBits)(ROAD_ALL ^ r); |
|
70 } |
|
71 |
|
72 /** |
|
73 * Calculate the mirrored RoadBits |
|
74 * |
|
75 * Simply move the bits to their new position. |
|
76 * |
|
77 * @param r The given RoadBits value |
|
78 * @return the mirrored |
|
79 */ |
|
80 static inline RoadBits MirrorRoadBits(RoadBits r) |
|
81 { |
|
82 return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2)); |
|
83 } |
|
84 |
|
85 /** |
|
86 * Calculate rotated RoadBits |
|
87 * |
|
88 * Move the Roadbits clockwise til they are in their final position. |
|
89 * |
|
90 * @param r The given RoadBits value |
|
91 * @param rot The given Rotation angle |
|
92 * @return the rotated |
|
93 */ |
|
94 static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot) |
|
95 { |
|
96 for (; rot > (DiagDirDiff)0; rot--){ |
|
97 r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3)); |
|
98 } |
|
99 return r; |
|
100 } |
|
101 |
|
102 /** |
|
103 * Create the road-part which belongs to the given DiagDirection |
|
104 * |
|
105 * This function returns a RoadBits value which belongs to |
|
106 * the given DiagDirection. |
|
107 * |
|
108 * @param d The DiagDirection |
|
109 * @return The result RoadBits which the selected road-part set |
|
110 */ |
|
111 static inline RoadBits DiagDirToRoadBits(DiagDirection d) |
|
112 { |
|
113 return (RoadBits)(ROAD_NW << (3 ^ d)); |
|
114 } |
|
115 |
|
116 #endif /* ROAD_FUNC_H */ |