#import <Foundation/Foundation.h>
#import <math.h>
Macros | |
#define | CC3Cyclic(value, period) (fmodf((value), (period))) |
#define | CC3IntIsEven(INT) (!CC3IntIsOdd(INT)) |
#define | CC3IntIsOdd(INT) ((INT) & 1) |
#define | CC3WeightedAverage(val1, val2, weight) |
#define | CLAMP(val, min, max) |
#define | kCC3DegToRadFactor 0.0174532925199433f |
#define | SIGN(A) |
#define | XOR(exp1, exp2) ((exp1) ? !(exp2) : (exp2)) |
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 NSUInteger | CC3RandomUInt () |
static NSUInteger | CC3RandomUIntBelow (NSUInteger 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 CC3IntIsEven | ( | INT) | (!CC3IntIsOdd(INT)) |
Returns whether the specified integer value is even.
#define CC3IntIsOdd | ( | INT) | ((INT) & 1) |
Returns whether the specified integer value is odd.
#define CC3WeightedAverage | ( | val1, | |
val2, | |||
weight | |||
) |
Returns a weighted average of the two values, where weight is between zero and one, inclusive.
#define CLAMP | ( | val, | |
min, | |||
max | |||
) |
Returns the value clamped to be between the min and max values.
#define kCC3DegToRadFactor 0.0174532925199433f |
Conversion between degrees and radians.
#define SIGN | ( | A) |
Returns -1, 0 or +1 if the arguement is negative, zero or positive respectively.
#define XOR | ( | exp1, | |
exp2 | |||
) | ((exp1) ? !(exp2) : (exp2)) |
Returns the logical exclusive-OR of the specified two expressions.
For logical expressions, this is more precise than the bitwise ^ operator, because it works correctly even if either exp1 or exp2 evaluates to a value that is not explicitly either YES (1) or NO (0). Furthermore, it is efficient, as it evaluates each expression only once.
|
inlinestatic |
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:
|
inlinestatic |
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.
|
inlinestatic |
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.
|
inlinestatic |
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.
|
inlinestatic |
Returns a random double between 0.0 inclusive and 1.0 exclusive.
|
inlinestatic |
Returns a random double between the specified min inclusive and the specified max exclusive.
|
inlinestatic |
Returns a random float between 0.0 inclusive and 1.0 exclusive.
|
inlinestatic |
Returns a random float between the specified min inclusive and the specified max exclusive.
|
inlinestatic |
Returns a random unsigned integer over the full unsigned interger range (between 0 and 0xFFFFFFFF).
|
inlinestatic |
Returns a random unsigned integer between 0 inclusive and the specified max exclusive.
|
inlinestatic |
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: