| 74 void puts () const; |
74 void puts () const; |
| 75 str stringRep () const; |
75 str stringRep () const; |
| 76 void zero (); |
76 void zero (); |
| 77 matrix& operator= (matrix other); |
77 matrix& operator= (matrix other); |
| 78 |
78 |
| 79 inline double& val (const uint idx) |
79 inline double& val (int idx) |
| 80 { return m_vals[idx]; |
80 { return m_vals[idx]; |
| 81 } |
81 } |
| 82 |
82 |
| 83 inline const double val (const uint idx) const |
83 inline const double& val (int idx) const |
| 84 { return m_vals[idx]; |
84 { return m_vals[idx]; |
| 85 } |
85 } |
| 86 |
86 |
| 87 inline matrix operator* (matrix other) const |
87 inline matrix operator* (matrix other) const |
| 88 { return mult (other); |
88 { return mult (other); |
| 89 } |
89 } |
| 90 |
90 |
| 91 inline double& operator[] (const uint idx) |
91 inline double& operator[] (int idx) |
| 92 { return val (idx); |
92 { return val (idx); |
| 93 } |
93 } |
| 94 inline const double& operator[] (const uint idx) const |
94 inline const double& operator[] (int idx) const |
| 95 { return val (idx); |
95 { return val (idx); |
| 96 } |
96 } |
| 97 |
97 |
| 98 private: |
98 private: |
| 99 double m_vals[9]; |
99 double m_vals[9]; |
| 110 class vertex |
110 class vertex |
| 111 { public: |
111 { public: |
| 112 vertex() {} |
112 vertex() {} |
| 113 vertex (double x, double y, double z); |
113 vertex (double x, double y, double z); |
| 114 |
114 |
| 115 double& coord (const ushort n) |
115 vertex midpoint (const vertex& other); |
| |
116 void move (const vertex& other); |
| |
117 str stringRep (bool mangled) const; |
| |
118 void transform (matrix matr, vertex pos); |
| |
119 |
| |
120 inline double& coord (int n) |
| 116 { return m_coords[n]; |
121 { return m_coords[n]; |
| 117 } |
122 } |
| 118 const double& coord (const ushort n) const |
123 |
| |
124 inline const double& coord (int n) const |
| 119 { return m_coords[n]; |
125 { return m_coords[n]; |
| 120 } |
126 } |
| 121 vertex midpoint (const vertex& other); |
|
| 122 void move (const vertex& other); |
|
| 123 str stringRep (bool mangled) const; |
|
| 124 void transform (matrix matr, vertex pos); |
|
| 125 |
127 |
| 126 inline double& x () |
128 inline double& x () |
| 127 { return m_coords[X]; |
129 { return m_coords[X]; |
| 128 } |
130 } |
| 129 |
131 |
| 171 // |
173 // |
| 172 // Array class that wraps around std::deque |
174 // Array class that wraps around std::deque |
| 173 // ============================================================================= |
175 // ============================================================================= |
| 174 template<class T> class List |
176 template<class T> class List |
| 175 { public: |
177 { public: |
| 176 typedef typename std::deque<T>::iterator it; |
178 typedef typename std::deque<T>::iterator Iterator; |
| 177 typedef typename std::deque<T>::const_iterator c_it; |
179 typedef typename std::deque<T>::const_iterator ConstIterator; |
| 178 typedef typename std::deque<T>::reverse_iterator r_it; |
180 typedef typename std::deque<T>::reverse_iterator ReverseIterator; |
| 179 typedef typename std::deque<T>::const_reverse_iterator cr_it; |
181 typedef typename std::deque<T>::const_reverse_iterator ConstReverseIterator; |
| 180 |
182 |
| 181 List() {} |
183 List() {} |
| 182 List (initlist<T> vals) |
184 List (initlist<T> vals) |
| 183 { m_vect = vals; |
185 { m_vect = vals; |
| 184 } |
186 } |
| 185 |
187 |
| 186 inline it begin() |
188 inline Iterator begin() |
| 187 { return m_vect.begin(); |
189 { return m_vect.begin(); |
| 188 } |
190 } |
| 189 |
191 |
| 190 inline c_it begin() const |
192 inline ConstIterator begin() const |
| 191 { return m_vect.cbegin(); |
193 { return m_vect.cbegin(); |
| 192 } |
194 } |
| 193 |
195 |
| 194 inline it end() |
196 inline Iterator end() |
| 195 { return m_vect.end(); |
197 { return m_vect.end(); |
| 196 } |
198 } |
| 197 |
199 |
| 198 inline c_it end() const |
200 inline ConstIterator end() const |
| 199 { return m_vect.cend(); |
201 { return m_vect.cend(); |
| 200 } |
202 } |
| 201 |
203 |
| 202 inline r_it rbegin() |
204 inline ReverseIterator rbegin() |
| 203 { return m_vect.rbegin(); |
205 { return m_vect.rbegin(); |
| 204 } |
206 } |
| 205 |
207 |
| 206 inline cr_it crbegin() const |
208 inline ConstReverseIterator crbegin() const |
| 207 { return m_vect.crbegin(); |
209 { return m_vect.crbegin(); |
| 208 } |
210 } |
| 209 |
211 |
| 210 inline r_it rend() |
212 inline ReverseIterator rend() |
| 211 { return m_vect.rend(); |
213 { return m_vect.rend(); |
| 212 } |
214 } |
| 213 |
215 |
| 214 inline cr_it crend() const |
216 inline ConstReverseIterator crend() const |
| 215 { return m_vect.crend(); |
217 { return m_vect.crend(); |
| 216 } |
218 } |
| 217 |
219 |
| 218 void erase (ulong pos) |
220 void erase (ulong pos) |
| 219 { assert (pos < size()); |
221 { assert (pos < size()); |
| 270 |
272 |
| 271 void makeUnique() |
273 void makeUnique() |
| 272 { // Remove duplicate entries. For this to be effective, the List must be |
274 { // Remove duplicate entries. For this to be effective, the List must be |
| 273 // sorted first. |
275 // sorted first. |
| 274 sort(); |
276 sort(); |
| 275 it pos = std::unique (begin(), end()); |
277 Iterator pos = std::unique (begin(), end()); |
| 276 resize (std::distance (begin(), pos)); |
278 resize (std::distance (begin(), pos)); |
| 277 } |
279 } |
| 278 |
280 |
| 279 ulong size() const |
281 ulong size() const |
| 280 { return m_vect.size(); |
282 { return m_vect.size(); |
| 322 // |
324 // |
| 323 // Helper class used to reverse-iterate Lists in range-for-loops. |
325 // Helper class used to reverse-iterate Lists in range-for-loops. |
| 324 // ============================================================================= |
326 // ============================================================================= |
| 325 template<class T> class ListReverser |
327 template<class T> class ListReverser |
| 326 { public: |
328 { public: |
| 327 typedef typename List<T>::r_it it; |
329 typedef typename List<T>::ReverseIterator Iterator; |
| 328 |
330 |
| 329 ListReverser (List<T>& vect) |
331 ListReverser (List<T>& vect) |
| 330 { m_vect = &vect; |
332 { m_vect = &vect; |
| 331 } |
333 } |
| 332 |
334 |
| 333 it begin() |
335 Iterator begin() |
| 334 { return m_vect->rbegin(); |
336 { return m_vect->rbegin(); |
| 335 } |
337 } |
| 336 |
338 |
| 337 it end() |
339 Iterator end() |
| 338 { return m_vect->rend(); |
340 { return m_vect->rend(); |
| 339 } |
341 } |
| 340 |
342 |
| 341 private: |
343 private: |
| 342 List<T>* m_vect; |
344 List<T>* m_vect; |
| 349 // |
351 // |
| 350 // Like ListReverser, except works on const Lists. |
352 // Like ListReverser, except works on const Lists. |
| 351 // ============================================================================= |
353 // ============================================================================= |
| 352 template<class T> class ConstListReverser |
354 template<class T> class ConstListReverser |
| 353 { public: |
355 { public: |
| 354 typedef typename List<T>::cr_it it; |
356 typedef typename List<T>::ConstReverseIterator Iterator; |
| 355 |
357 |
| 356 ConstListReverser (const List<T>& vect) |
358 ConstListReverser (const List<T>& vect) |
| 357 { m_vect = &vect; |
359 { m_vect = &vect; |
| 358 } |
360 } |
| 359 |
361 |
| 360 it begin() const |
362 Iterator begin() const |
| 361 { return m_vect->crbegin(); |
363 { return m_vect->crbegin(); |
| 362 } |
364 } |
| 363 |
365 |
| 364 it end() const |
366 Iterator end() const |
| 365 { return m_vect->crend(); |
367 { return m_vect->crend(); |
| 366 } |
368 } |
| 367 |
369 |
| 368 private: |
370 private: |
| 369 const List<T>* m_vect; |
371 const List<T>* m_vect; |