#import <math.h>
Defines | |
#define | CC3Cyclic(value, period) (fmodf((value), (period))) |
#define | CLAMP(val, min, max) (MIN(MAX((val), (min)), (max))) |
#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 | |
static float | CC3CyclicAngle (float angle) |
static float | CC3CyclicDifference (float minuend, float subtrahend, float period) |
static bool | CC3IsWithinTolerance (float value, float benchmarkValue, float aTolerance) |
static float | CC3PositiveCyclic (float value, float period) |
static double | CC3RandomDouble () |
static double | CC3RandomDoubleBetween (double min, double max) |
static float | CC3RandomFloat () |
static float | CC3RandomFloatBetween (float min, float max) |
static unsigned int | CC3RandomUInt () |
static unsigned int | CC3RandomUIntBelow (unsigned int max) |
static float | CC3SemiCyclicAngle (float angle) |
#define CC3Cyclic | ( | value, | |
period | |||
) | (fmodf((value), (period))) |
Returns the positive or negative modulo remainder of value divided by period.
#define CLAMP | ( | val, | |
min, | |||
max | |||
) | (MIN(MAX((val), (min)), (max))) |
Returns the value clamped to be between the min and max values.
#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.
static float CC3CyclicAngle | ( | float | angle ) | [inline, static] |
Converts the specified angle, to an equivalent angle between +/-360 degrees.
The result may be positive or negative, but will always be between -360 and +360 degrees.
For example:
static float CC3CyclicDifference | ( | float | minuend, |
float | subtrahend, | ||
float | period | ||
) | [inline, static] |
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 CC3CyclicDifference(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, CC3CyclicDifference(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).
For angles in degrees, consider using CC3SemiCyclicAngle instead.
static bool CC3IsWithinTolerance | ( | float | value, |
float | benchmarkValue, | ||
float | aTolerance | ||
) | [inline, static] |
Returns whether the specified value is as close or closer to the specified benchmark value than the specified tolerance.
If tolerance is zero, returns YES only if the two values are identical.
static float CC3PositiveCyclic | ( | float | value, |
float | period | ||
) | [inline, static] |
Returns the positive modulo remainder of value divided by period.
This function is similar to CC3Cyclic(), 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 CC3Cyclic(-2.0, 12.0) will return 10.0 rather than -2.0.
static double CC3RandomDouble | ( | ) | [inline, static] |
Returns a random double between 0.0 inclusive and 1.0 exclusive.
static double CC3RandomDoubleBetween | ( | double | min, |
double | max | ||
) | [inline, static] |
Returns a random double between the specified min inclusive and the specified max exclusive.
static float CC3RandomFloat | ( | ) | [inline, static] |
Returns a random float between 0.0 inclusive and 1.0 exclusive.
static float CC3RandomFloatBetween | ( | float | min, |
float | max | ||
) | [inline, static] |
Returns a random float between the specified min inclusive and the specified max exclusive.
static unsigned int CC3RandomUInt | ( | ) | [inline, static] |
Returns a random unsigned integer over the full unsigned interger range (between 0 and 0xFFFFFFFF).
static unsigned int CC3RandomUIntBelow | ( | unsigned int | max ) | [inline, static] |
Returns a random unsigned integer between 0 inclusive and the specified max exclusive.
static float CC3SemiCyclicAngle | ( | float | angle ) | [inline, static] |
Converts the specified angle, to an equivalent angle between +/-180 degrees.
The result may be positive or negative, but will always be between -180 and +180 degrees.
For example: