193 |
193 |
194 // An operator overload for calcVertex() |
194 // An operator overload for calcVertex() |
195 LDBoundingBox& operator<< (const Vertex& v); |
195 LDBoundingBox& operator<< (const Vertex& v); |
196 }; |
196 }; |
197 |
197 |
198 extern const Vertex g_origin; // Vertex at (0, 0, 0) |
198 extern const Vertex Origin; |
199 extern const Matrix g_identity; // Identity matrix |
199 extern const Matrix IdentityMatrix; |
200 |
200 |
201 static const double pi = 3.14159265358979323846; |
201 static const double Pi = 3.14159265358979323846; |
202 |
202 |
203 |
203 |
204 // ============================================================================= |
204 // ============================================================================= |
205 // Plural expression |
205 // Plural expression |
206 template<class T> static inline const char* plural (T n) |
206 template<typename T> |
|
207 static inline const char* Plural (T n) |
207 { |
208 { |
208 return (n != 1) ? "s" : ""; |
209 return (n != 1) ? "s" : ""; |
209 } |
210 } |
210 |
211 |
211 // ============================================================================= |
212 // ============================================================================= |
212 // Templated clamp |
213 // Templated clamp |
213 template<class T> static inline T clamp (T a, T min, T max) |
214 template<typename T> |
|
215 static inline T Clamp (T a, T min, T max) |
214 { |
216 { |
215 return (a > max) ? max : (a < min) ? min : a; |
217 return (a > max) ? max : (a < min) ? min : a; |
216 } |
218 } |
217 |
219 |
218 // Templated minimum |
220 // Templated minimum |
219 template<class T> static inline T min (T a, T b) |
221 template<typename T> |
|
222 static inline T Min (T a, T b) |
220 { |
223 { |
221 return (a < b) ? a : b; |
224 return (a < b) ? a : b; |
222 } |
225 } |
223 |
226 |
224 // Templated maximum |
227 // Templated maximum |
225 template<class T> static inline T max (T a, T b) |
228 template<typename T> |
|
229 static inline T Max (T a, T b) |
226 { |
230 { |
227 return (a > b) ? a : b; |
231 return (a > b) ? a : b; |
228 } |
232 } |
229 |
233 |
230 // Templated absolute value |
234 // Templated absolute value |
231 template<class T> static inline T abs (T a) |
235 template<typename T> |
|
236 static inline T Abs (T a) |
232 { |
237 { |
233 return (a >= 0) ? a : -a; |
238 return (a >= 0) ? a : -a; |
234 } |
239 } |
235 |
240 |
236 template<class T> inline bool isZero (T a) |
241 template<typename T> |
237 { |
242 inline bool IsZero (T a) |
238 return abs<T> (a) < 0.0001; |
243 { |
239 } |
244 return Abs<T> (a) < 0.0001; |
240 |
245 } |
241 template<class T> inline bool isInteger (T a) |
246 |
242 { |
247 template<typename T> |
243 return isZero (a - (int) a); |
248 inline bool IsIntegral (T a) |
244 } |
249 { |
245 |
250 return IsZero (a - int (a)); |
246 template<typename T> |
251 } |
247 inline bool within (T a, T b, T c) |
252 |
|
253 template<typename T> |
|
254 inline bool IsWithin (T a, T b, T c) |
248 { |
255 { |
249 return a >= b and a <= c; |
256 return a >= b and a <= c; |
250 } |
257 } |
251 |
258 |
252 template<typename T> |
259 template<typename T> |
253 void removeDuplicates (T& a) |
260 void RemoveDuplicates (T& a) |
254 { |
261 { |
255 std::sort (a.begin(), a.end()); |
262 std::sort (a.begin(), a.end()); |
256 a.erase (std::unique (a.begin(), a.end()), a.end()); |
263 a.erase (std::unique (a.begin(), a.end()), a.end()); |
257 } |
264 } |
258 |
265 |
259 inline QString utf16 (const char16_t* a) |
266 inline QString UTF16 (const char16_t* a) |
260 { |
267 { |
261 if (Q_LIKELY (sizeof(char16_t) == sizeof(unsigned short))) |
268 if (Q_LIKELY (sizeof(char16_t) == sizeof(unsigned short))) |
262 return QString::fromUtf16 (reinterpret_cast<const unsigned short*> (a)); |
269 return QString::fromUtf16 (reinterpret_cast<const unsigned short*> (a)); |
263 |
270 |
264 QVector<unsigned short> data; |
271 QVector<unsigned short> data; |