#import <math.h>
Defines | |
#define | CLAMP(val, min, max) (MIN(MAX((val), (min)), (max))) |
#define | Cyclic(value, period) (fmodf((value), (period))) |
#define | DegreesToRadiansFactor 0.017453292519943f |
#define | SIGN(A) ((A) < 0 ? -1 :((A) > 0 ? 1 : 0)) |
#define | WAVG(val1, val2, weight) ((val1) + (((val2) - (val1)) * CLAMP(weight, 0.0, 1.0))) |
Functions | |
float | CyclicDifference (float minuend, float subtrahend, float period) |
float | PositiveCyclic (float value, float period) |
double | RandomDouble () |
double | RandomDoubleBetween (double min, double max) |
float | RandomFloat () |
float | RandomFloatBetween (float min, float max) |
unsigned int | RandomUInt () |
unsigned int | RandomUIntBelow (unsigned int max) |
#define CLAMP | ( | val, | |
min, | |||
max | |||
) | (MIN(MAX((val), (min)), (max))) |
Returns the value clamped to be between the min and max values.
#define Cyclic | ( | value, | |
period | |||
) | (fmodf((value), (period))) |
Returns the positive or negative modulo remainder of value divided by period.
#define DegreesToRadiansFactor 0.017453292519943f |
Conversion between degrees and radians.
#define SIGN | ( | A ) | ((A) < 0 ? -1 :((A) > 0 ? 1 : 0)) |
Returns -1, 0 or +1 if the arguement is negative, zero or positive respectively.
#define WAVG | ( | val1, | |
val2, | |||
weight | |||
) | ((val1) + (((val2) - (val1)) * CLAMP(weight, 0.0, 1.0))) |
Returns a weighted average of the two values, where weight is between zero and one, inclusive.
float CyclicDifference | ( | float | minuend, |
float | subtrahend, | ||
float | period | ||
) |
Returns the difference between the specified minuend and subtrahend, in terms of the minimum difference within the specified periodic cycle.
Therefore, the result may be positive or negative, but will always be between (+period/2) and (-period/2).
For example, for the numbers on a compass, the period is 360, and CyclicDifference(350, 10, 360) will yield -20 (ie- the smallest change from 10 degrees to 350 degrees is -20 degrees) rather than +340 (from simple subtraction). Similarly, CyclicDifference(10, 350, 360) will yield +20 (ie- the smallest change from 350 degrees to 10 degrees is +20 degrees) rather than -340 (from simple subtraction).
float PositiveCyclic | ( | float | value, |
float | period | ||
) |
Returns the positive modulo remainder of value divided by period.
This function is similar to Cyclic(), but converts a negative result into a positive value that is the same distance away from the end of the cycle as the result was below zero. In this sense, this function behaves like the numbers on a clock, and Cyclic(-2.0, 12.0) will return 10.0 rather than -2.0.
double RandomDouble | ( | ) |
Returns a random double between 0.0 inclusive and 1.0 exclusive.
double RandomDoubleBetween | ( | double | min, |
double | max | ||
) |
Returns a random double between the specified min inclusive and the specified max exclusive.
float RandomFloat | ( | ) |
Returns a random float between 0.0 inclusive and 1.0 exclusive.
float RandomFloatBetween | ( | float | min, |
float | max | ||
) |
Returns a random float between the specified min inclusive and the specified max exclusive.
unsigned int RandomUInt | ( | ) |
Returns a random unsigned integer over the full unsigned interger range (between 0 and 0xFFFFFFFF).
unsigned int RandomUIntBelow | ( | unsigned int | max ) |
Returns a random unsigned integer between 0 inclusive and the specified max exclusive.