luma::numbers Namespace Reference


Detailed Description

Namespace for the Numbers library.

(See the main page.)


Classes

class  AbstractFilteredNumber
class  AbstractFilteredNumber< T, sampleCount, 0 >
 This specialisation is provided for completeness' sake and should generally not be used. More...
class  AbstractFunction
 Simply a class that implements the function call operator, and used to implement (mathematical) functions. More...
class  BufferedBool
 This class can be used instead of a bool to get smoother (less eratic) transitions, that is, the value stays true or false longer. More...
class  BufferedNumber
 This class mimicks a float, but ensures smooth transitions. More...
class  BufferedState
 This class handles buffered states transitions, that is, it can be used to reduce state flickering. More...
class  BufferedStep
 This class combines ideas from BufferedBool and BufferedState; it represents a linear progression of buffered states. More...
class  ClampedNumber
 Class that represents a number that is always clamped in a range. More...
class  CyclicNumber
 A cyclic number is a number that is always in a given range, and wraps around when it would exceed this range. More...
class  DifferentiableNumber
 A DifferentiableNumber is a number that keeps track of its own derivatives. More...
class  DifferentiableNumber< T, 0 >
 This specialisation is provided for completeness' sake and should generally not be used. More...
class  DifferentiableNumber< T, 1 >
 This is the stop class for the recursive template definition of DifferentiableNumber. More...
class  IntegrableNumber
 An integral number is a number that keeps track of itw own integrals. More...
class  IntegrableNumber< T, sampleCount, 0 >
 This specialisation is provided for completeness' sake and should generally not be used. More...
class  IntegrableNumber< T, sampleCount, 1 >
 This is the stop class for the recursive template definition of IntegrableNumber. More...
class  NumberWrapper
 This class is a drop-in substitute for RangedNumbers, except that it has no logic wrapped around it's value - that is, gertValue will always returned the last value passed to setValue. More...
class  PIDBufferedNumber
 A PIDBufferedNumber is a simple PID controller. More...
class  PingPongNumber
 A PingPongNumber is a number that can grow (or shrink) up to a point, and then starts shrinking (or growing) again. More...
class  RangedNumber
 This class is the base class of numbers that fall in a given range. More...
class  ResponseCurve
 This class is described in AI Programming Wisdom 1, "The Beauty of Response Curves", by Bob Alexander. More...
class  UpdateableNumber
 Updateable numbers are used when a value is updated regularly, and logic should be performed on every update. More...
class  XYResponseCurve
 Similar to ResponseCurve, but allows sample points to be unevenly spaced. More...

Functions

template<class T>
clamp (const T &value, const T &minValue, const T &maxValue)
 Returns the given value clamped between the given minimum and maximum.
template<class T>
extreme (T v1, T v2, T center)
 Returns the value furthest from the center.
template<class T>
floor (T x)
 Returns the largest integer smaller than the argument given.
template<class T>
frac (T x)
 Returns the fractional part of a float or double.
template<unsigned int n, class T>
void integrate (T samples[])
 Integrates a sequence of numbers.
template<class T>
lerp (const T &value, const T &inputMin, const T &inputMax, const T &outputMin, const T &outputMax)
 Linearly interpolates a value between a given range.
template<class T>
line (const T &value, const T &inputMin, const T &inputMax, const T &outputMin, const T &outputMax)
 Otherwise, the returned value is outputMin + ((value - inputMin) / (inputMax - inputMin)) * (outputMax - outputMin).
template<class T>
max (const T &v1, const T &v2)
template<class T>
min (const T &v1, const T &v2)
template<class T>
mod (const T &value, const T &minValue, const T &maxValue)
 Returns the modulus of a number in a specified range, that is (min + value mod (max - min)).
template<class T>
ramp (const T &value, const T &inputMin, const T &inputMax, const T &outputMin, const T &outputMax)
 If the value is below the inputMin, the outputMin is returned.
template<class T>
reflect (const T &value, const T &minValue, const T &maxValue)
 Returns a number reflected between the bounds.
template<class T>
sigmoid (const T &value, const T &inputMin, const T &inputMax, const T &outputMin, const T &outputMax)
 This function is a smooth aproximation for lerp.
template<class T>
step (const T &input, const T &inputThreshold, const T &outputMin, const T &outputMax)
 Returns the one of two outputs, depending on whether the input value exceeds a given threshold.

Variables

const float frameRate = FRAME_RATE


Function Documentation

T clamp ( const T &  value,
const T &  minValue,
const T &  maxValue 
) [inline]

Returns the given value clamped between the given minimum and maximum.

Parameters:
T Any type that is supported by the standard min and max functions.
value The value to clamp.
minValue The minimum value of the output.
maxValue The maximum vakue of the output.
Returns:
A value clamped between minValue and maxValue.
Note:
The range of this function includes the maxValue.

Definition at line 181 of file utils.h.

References max(), and min().

Referenced by ClampedNumber::dec(), ClampedNumber::getValidValue(), ClampedNumber::inc(), ClampedNumber::operator++(), ClampedNumber::operator+=(), ClampedNumber::operator--(), and ClampedNumber::operator-=().

T extreme ( v1,
v2,
center = 0 
) [inline]

Returns the value furthest from the center.

For example,

   extreme(-1, 5, 0) == 5
   extreme(1, -5, 0) == -5

This is useful, for example when deciding on which of two (polar opposite) inputs to use to make a decision.

Definition at line 262 of file utils.h.

T floor ( x  )  [inline]

Returns the largest integer smaller than the argument given.

See also:
frac()

Definition at line 256 of file utils.h.

T frac ( x  )  [inline]

Returns the fractional part of a float or double.

Guarenteed always to lie between 0 and 1, even if the input is negative.

Note:
: the following identity hold (within floating point threshold):
      x == frac(c) + floor(x)
See also:
floor()

Definition at line 250 of file utils.h.

void integrate ( samples[]  )  [inline]

Integrates a sequence of numbers.

Same as accumulating the sequence in place. For example, the array {0, 1, 2, 3} will be set to {0, 1, 3, 6}.

Definition at line 276 of file utils.h.

T lerp ( const T &  value,
const T &  inputMin,
const T &  inputMax,
const T &  outputMin,
const T &  outputMax 
) [inline]

Linearly interpolates a value between a given range.

If the value is below the inputMin, the outputMin is returned. If the value is above the inputMax, the outputMax is returned.

Otherwise, the returned value is outputMin + ((value - inputMin) / (inputMax - inputMin)) * (outputMax - outputMin).

Author:
Luke Lamothe (luke@luma.co.za)

Definition at line 214 of file utils.h.

References ramp().

Referenced by ResponseCurve::operator()().

T line ( const T &  value,
const T &  inputMin,
const T &  inputMax,
const T &  outputMin,
const T &  outputMax 
) [inline]

Otherwise, the returned value is outputMin + ((value - inputMin) / (inputMax - inputMin)) * (outputMax - outputMin).

Definition at line 244 of file utils.h.

Referenced by ramp().

T max ( const T &  v1,
const T &  v2 
) [inline]

Definition at line 174 of file utils.h.

Referenced by clamp(), and XYResponseCurve::findInputIndex().

T min ( const T &  v1,
const T &  v2 
) [inline]

Definition at line 168 of file utils.h.

Referenced by clamp(), and XYResponseCurve::findInputIndex().

T mod ( const T &  value,
const T &  minValue,
const T &  maxValue 
) [inline]

Returns the modulus of a number in a specified range, that is (min + value mod (max - min)).

For example,

   for (int i = 0; i < 10; i++)
   {
      int r = mod(i, 2, 5);
      cout << i << " ";
   }
prints 3 4 2 3 4 2 3 4 2 3

Note:
The range of this function excludes the maxValue.

Definition at line 187 of file utils.h.

Referenced by CyclicNumber::dec(), CyclicNumber::getValidValue(), CyclicNumber::inc(), PeriodicResponseCurve::operator()(), CyclicNumber::operator+=(), CyclicNumber::operator-=(), CyclicNumber::operator=(), and reflect().

T ramp ( const T &  value,
const T &  inputMin,
const T &  inputMax,
const T &  outputMin,
const T &  outputMax 
) [inline]

If the value is below the inputMin, the outputMin is returned.

Otherwise, the returned value is outputMin + ((value - inputMin) / (inputMax - inputMin)) * (outputMax - outputMin).

Definition at line 233 of file utils.h.

References line().

Referenced by lerp().

T reflect ( const T &  value,
const T &  minValue,
const T &  maxValue 
) [inline]

Returns a number reflected between the bounds.

For example,

   for (int i = 0; i < 10; i++)
   {
      int r = reflect(i, 0, 3);
      cout << i << " ";
   }
prints 0 1 2 3 2 1 0 1 2 3

Note:
The range of this function includes the maxValue.

Definition at line 204 of file utils.h.

References mod().

T sigmoid ( const T &  value,
const T &  inputMin,
const T &  inputMax,
const T &  outputMin,
const T &  outputMax 
) [inline]

This function is a smooth aproximation for lerp.

Definition at line 225 of file utils.h.

T step ( const T &  input,
const T &  inputThreshold,
const T &  outputMin,
const T &  outputMax 
) [inline]

Returns the one of two outputs, depending on whether the input value exceeds a given threshold.

Definition at line 268 of file utils.h.


Variable Documentation

const float frameRate = FRAME_RATE


Generated on Sun Sep 21 20:49:08 2008 for Numbers by  doxygen 1.5.6