Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geom_utils

Functions

template<class T >
const T & csMax (const T &a, const T &b)
 
template<class T >
const T & csMin (const T &a, const T &b)
 
template<class T >
void csSort (T &a, T &b)
 
template<class T , class U >
void csSort (T &a, T &b, U &x, U &y)
 
template<class T >
csClamp (const T &a, T max, T min)
 
template<class T >
csSmoothStep (const T &a, T max, T min)
 
template<class T , class Tfactor >
csLerp (const T &a, const T &b, const Tfactor &f)
 
template<class T >
csSquare (const T &x)
 
CS_FORCEINLINE bool csFinite (float f)
 Checks if a floating point value is finite. More...
 
CS_FORCEINLINE bool csFinite (double d)
 Checks if a double-precision floating point value is finite. More...
 
CS_FORCEINLINE bool csNaN (float f)
 Checks if a floating point value is not-a-number. More...
 
CS_FORCEINLINE bool csNaN (double d)
 Checks if a double-precision floating point value is not-a-number. More...
 
CS_FORCEINLINE bool csNormal (float f)
 Checks if a floating point value is normal (not infinite or nan). More...
 
CS_FORCEINLINE bool csNormal (double d)
 Checks if a double-precision floating point value is normal. More...
 

Detailed Description

Function Documentation

template<class T >
T csClamp ( const T &  a,
max,
min 
)

Clamp a between max and min.

Definition at line 92 of file opmath.h.

References csMax(), and csMin().

93 {
94  return csMin (csMax (a, min), max);
95 }
CS_FORCEINLINE bool csFinite ( float  f)

Checks if a floating point value is finite.

Definition at line 139 of file opmath.h.

Referenced by csNormal().

140 {
141 #if defined (HAVE_FINITEF)
142  return finitef (f);
143 #elif defined (HAVE_STD__ISFINITE)
144  return std::isfinite (f);
145 #elif defined(HAVE_ISFINITE)
146  return (isfinite (f));
147 #elif defined (HAVE_FINITE)
148  return finite (f);
149 #elif defined (HAVE__FINITE)
150  return _finite (f) != 0;
151 #else
152 #error Your platform has no isfinite()-alike function!
153 #endif
154 }
CS_FORCEINLINE bool csFinite ( double  d)

Checks if a double-precision floating point value is finite.

Definition at line 156 of file opmath.h.

157 {
158 #if defined (HAVE_STD__ISFINITE)
159  return std::isfinite (d);
160 #elif defined(HAVE_ISFINITE)
161  return isfinite (d);
162 #elif defined (HAVE_FINITE)
163  return finite (d);
164 #elif defined (HAVE__FINITE)
165  return _finite (d) != 0;
166 #else
167 #error Your platform has no isfinite()-alike function!
168 #endif
169 }
template<class T , class Tfactor >
T csLerp ( const T &  a,
const T &  b,
const Tfactor &  f 
)

Performs a linear interpolation between a and b with the factor f.

Definition at line 123 of file opmath.h.

124 {
125  return (a + (b - a) * f);
126 }
template<class T >
const T& csMax ( const T &  a,
const T &  b 
)

Returns bigger of a and b. If they are equal, a or b can be returned.

Definition at line 47 of file opmath.h.

References a, and b.

Referenced by csClamp(), and csTerrainSegmentCellCollider::csTerrainSegmentCellCollider().

48 {
49  if (b < a) return a;
50  return b;
51 }
template<class T >
const T& csMin ( const T &  a,
const T &  b 
)

Returns smaller of a and b. If they are equal, a or b can be returned.

Definition at line 57 of file opmath.h.

References a, and b.

Referenced by csClamp(), and csTerrainSegmentCellCollider::csTerrainSegmentCellCollider().

58 {
59  if (a < b) return a;
60  return b;
61 }
CS_FORCEINLINE bool csNaN ( float  f)

Checks if a floating point value is not-a-number.

Definition at line 172 of file opmath.h.

Referenced by csNormal().

173 {
174 #if defined (HAVE_NANF)
175  return isnanf (f);
176 #elif defined (HAVE_STD__ISNAN)
177  return std::isnan (f);
178 #elif defined(HAVE_ISNAN)
179  return isnan (f);
180 #elif defined (HAVE__ISNAN)
181  return _isnan (f) != 0;
182 #else
183 #error Your platform has no isnan()-alike function!
184 #endif
185 }
CS_FORCEINLINE bool csNaN ( double  d)

Checks if a double-precision floating point value is not-a-number.

Definition at line 187 of file opmath.h.

188 {
189 #if defined (HAVE_STD__ISNAN)
190  return std::isnan (d);
191 #elif defined(HAVE_ISNAN)
192  return isnan (d);
193 #elif defined (HAVE__ISNAN)
194  return _isnan (d) != 0;
195 #else
196 #error Your platform has no isnan()-alike function!
197 #endif
198 }
CS_FORCEINLINE bool csNormal ( float  f)

Checks if a floating point value is normal (not infinite or nan).

Definition at line 201 of file opmath.h.

References csFinite(), and csNaN().

202 {
203 #if defined (HAVE_NORMALF)
204  return normalf (f);
205 #elif defined (HAVE_STD__ISNORMAL)
206  return std::isnormal (f);
207 #elif defined(HAVE_ISNORMAL)
208  return isnormal (f);
209 #else
210  return csFinite(f) && !csNaN(f);
211 #endif
212 }
CS_FORCEINLINE bool csNormal ( double  d)

Checks if a double-precision floating point value is normal.

Definition at line 214 of file opmath.h.

References csFinite(), and csNaN().

215 {
216 #if defined (HAVE_STD__ISNORMAL)
217  return std::isnormal (d);
218 #elif defined(HAVE_ISNORMAL)
219  return isnormal (d);
220 #else
221  return csFinite(d) && !csNaN(d);
222 #endif
223 }
template<class T >
T csSmoothStep ( const T &  a,
max,
min 
)

Performs a smooth interpolation of a on range min to max.

Returns
Smooth interporlated value if min < a < max, and 0 resp. 1 if a is smaller than min resp. larger than max.

Definition at line 103 of file opmath.h.

References min().

104 {
105  T tmp, tmp2;
106  if (a <= min)
107  tmp = 0.0f;
108  else if (a >= max)
109  tmp = 1.0f;
110  else
111  {
112  tmp2 = (a - min) / (max-min);
113  tmp = tmp2*tmp2 * (3.0 - 2.0*tmp2);
114  }
115  return tmp;
116 }
template<class T >
void csSort ( T &  a,
T &  b 
)

Sort a and b in order of size.

Definition at line 67 of file opmath.h.

References CS::Swap().

68 {
69  if (b < a)
70  CS::Swap (a, b);
71 }
template<class T , class U >
void csSort ( T &  a,
T &  b,
U &  x,
U &  y 
)

Sort a and b in order of size. If swapping them, also swap x and y

Definition at line 78 of file opmath.h.

References CS::Swap().

79 {
80  if (b < a)
81  {
82  CS::Swap (a, b);
83  CS::Swap (x, y);
84  }
85 }
template<class T >
T csSquare ( const T &  x)

Returns the square of the argument

Definition at line 132 of file opmath.h.

References x.

133 {
134  return x * x;
135 }