ionUtils.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include "ionTypes.h"
12 
13 
17 #define ION_ARRAYSIZE(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
18 
19 
20 namespace ion
21 {
22 
25  void WaitForUser();
26 
29  int DigitCount(int n);
30 
32  int MakeEven(int const i);
33 
35  bool ToggleBool(bool & Condition);
36 
38  float Saturate(float const v);
39 
41  double Saturate(double const v);
42 
44  template <typename T>
45  T Clamp(T const v, T const min, T const max)
46  {
47  return ((v > max) ? max : ((v < min) ? min : v));
48  }
49 
51  template <typename T>
52  T Sq(T const a)
53  {
54  return a * a;
55  }
56 
58  template <typename T>
59  T Average(T const a, T const b)
60  {
61  return (a + b) / 2;
62  }
63 
65  template <typename T>
66  T Average(T const a, T const b, T const c)
67  {
68  return (a + b + c) / 3;
69  }
70 
72  template <typename T>
73  T Average(T const a, T const b, T const c, T const d)
74  {
75  return (a + b + c + d) / 4;
76  }
77 
79  template <typename T>
80  T Sign(T const val)
81  {
82  return (T) ((0 < val) - (val < 0));
83  }
84 
85 }
T Average(T const a, T const b)
Definition: ionUtils.h:59
bool ToggleBool(bool &Condition)
Definition: ionUtils.cpp:40
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
int MakeEven(int const i)
Definition: ionUtils.cpp:35
void WaitForUser()
Portable version of system("PAUSE")
Definition: ionUtils.cpp:10
Defines typedefs for integer and floating point types.
T Sign(T const val)
Definition: ionUtils.h:80
T Sq(T const a)
Definition: ionUtils.h:52
T Saturate(T const value)
Clamps a value between 0 and 1.
Definition: ionMathFunctions.h:110
T Clamp(T const v, T const min, T const max)
Definition: ionUtils.h:45
int DigitCount(int n)
Count the number of digits (including a - for negative numbers) in a decimal integer.
Definition: ionUtils.cpp:16