Defines and includes common Math data types and functions. More...
#include <cmath>
#include <algorithm>
#include <vector>
#include <limits>
#include <float.h>
#include "Math/Point.h"
#include "Math/Vector.h"
#include "Math/Matrix.h"
Classes | |
struct | Rect_t< T > |
A 2D rectangle. More... | |
struct | Line |
A 2D Line segment. More... | |
class | Ray |
A 2D Ray. More... | |
class | AABB |
2D Axis Aligned Bounding Box. More... | |
Defines | |
#define | BIT(x) (1 << (x)) |
Constructs an integer with one bit set. | |
Typedefs | |
typedef Rect_t< float > | Rectf |
A Template instantiation of the Rect_t template using the float data type. | |
typedef Rect_t< double > | Rectd |
A Template instantiation of the Rect_t template using the double data type. | |
typedef Rect_t< int > | Recti |
A Template instantiation of the Rect_t template using the int data type. | |
Functions | |
float | ClosestPoints (const Line &l1, const Line &l2, Point2f &out1, Point2f &out2) |
Computes the closest points between the two given lines. | |
int | Intersect (const Ray &r, const Circle &c, float &t1, float &t2) |
Intersects a Ray with a Circle and finds the enter and exit time. | |
int | Intersect (const Line &l, const Circle &c, float &t1, float &t2) |
Intersects a Line with a Circle and finds the enter and exit time. | |
template<class T , class U > | |
T | lerp (const T &t1, const T &t2, U t) |
Linear interpolates between two objects of type T. | |
template<class T > | |
AABB | RectToAABB (const Rect_t< T > &r) |
Converts a Rect to an AABB. | |
template<class T > | |
Rect_t< T > | AABBToRect (const AABB &aabb) |
Converts an AABB to a Rect. | |
template<class T > | |
Rect_t< T > | ExpandRect (const Rect_t< T > &r, float dx, float dy) |
Expands (or contracts) the size of the given rectangle about the center. | |
template<class T > | |
bool | InsideRect (const Rect_t< T > &r, const Point2< T > &p) |
Tests if the given point is inside the given rect. | |
template<class T > | |
void | ClampInPlace (T &val, const T &low, const T &high) |
Clamps a given value into a given range. | |
template<class T > | |
T | Clamp (const T &val, const T &low, const T &high) |
Clamps a given value into a given range. | |
template<class T > | |
void | ClampLow (T &val, const T &low) |
Clamps a given value into a given range. | |
template<class T > | |
void | ClampHigh (T &val, const T &high) |
Clamps a given value into a given range. | |
template<class T > | |
T | Sign (const T &val) |
Determines the sign of the given value. | |
template<class T > | |
T | SignZero (const T &val) |
Determines the sign of the given value. | |
template<class T > | |
T | Minimum (const T &v1, const T &v2) |
Determines the minimum of two elements. | |
template<class T > | |
T | Maximum (const T &v1, const T &v2) |
Determines the maximum of two elements. | |
template<class T > | |
void | Swap (T &v1, T &v2) |
Swaps the given two values. | |
float | RadToDeg (float a) |
Converts an angle in Radians to Degrees. | |
float | DegToRad (float a) |
Converts an angle in Degrees to Radians. | |
bool | Close (float a, float b, float tol=0.00001f) |
Tests if two floating point values are within a given tolerance. | |
float | RandomFloat (float min, float max) |
Computes a random float in a given range. | |
uint | TimeSeed () |
Computes a pretty good seed for a random number generator using the system time. | |
void | Transform (Poly &p, const Matrixf &m) |
Transforms the given polygon. | |
void | Transform (Point2f *p, uint n, const Matrixf &m) |
Transforms the given points. | |
Point2f | ScreenToNormCoords (const Point2f &p) |
Converts a point in absolute Screen coordinates to normalized device coordinates. | |
Point2f | NormToScreenCoords (const Point2f &p) |
Converts a point in normalized device coordinates to absolute Screen coordinates. | |
AABB | ScreenToNormCoords (const AABB &a) |
Converts an AABB in normalized device coordinates to absolute Screen coordinates. | |
AABB | NormToScreenCoords (const AABB &a) |
Converts an AABB in normalized device coordinates to absolute Screen coordinates. | |
Variables | |
const float | PI = 3.141592653589793f |
const float | PI_2 = PI / 2.0f |
const float | PI_4 = PI / 4.0f |
const float | _2PI = 2.0f * PI |
const float | INV_PI = 1.0f / PI |
const float | E = 2.718281828459045f |
const float | SQRT2 = 1.414213562373095f |
const float | INV_SQRT2 = 1.0f / SQRT2 |
const float | SQRT2_2 = 0.707106781186547f |
const float | RAD_TO_DEG = 180.0f / PI |
const float | DEG_TO_RAD = PI / 180.0f |
const float | EPSILON = 0.0001f |
Defines and includes common Math data types and functions.
#define BIT | ( | x | ) | (1 << (x)) |
Constructs an integer with one bit set.
[in] | x | the xth bit in the integer to set. |
Converts an AABB to a Rect.
T | the data type of the Rect. If T is not float data may be truncated. |
[in] | aabb | The AABB to convert. |
T Clamp | ( | const T & | val, | |
const T & | low, | |||
const T & | high | |||
) | [inline] |
void ClampHigh | ( | T & | val, | |
const T & | high | |||
) | [inline] |
void ClampInPlace | ( | T & | val, | |
const T & | low, | |||
const T & | high | |||
) | [inline] |
void ClampLow | ( | T & | val, | |
const T & | low | |||
) | [inline] |
bool Close | ( | float | a, | |
float | b, | |||
float | tol = 0.00001f | |||
) | [inline] |
Tests if two floating point values are within a given tolerance.
[in] | a | the first value. |
[in] | b | the second value. |
[in] | tol | the tolerance. Defaults to 0.00001f. |
Computes the closest points between the two given lines.
[in] | l1 | the first line. |
[in] | l2 | the second line. |
[out] | out1 | the closest point on the first line. |
[out] | out2 | the closest point on the second line. |
pg 149
float DegToRad | ( | float | a | ) | [inline] |
Converts an angle in Degrees to Radians.
[in] | a | the angle in Degrees to convert. |
Expands (or contracts) the size of the given rectangle about the center.
T | the data type of the Rect. If T is not float data may be truncated. |
[in] | r | the Rect to expand. |
[in] | dx | the amount to expand in the x direction. |
[in] | dy | the amount to expand in the y direction. |
Tests if the given point is inside the given rect.
T | the data type of the Rect and the Point2 |
[in] | r | the Rect to check against. |
[in] | p | the point to test. |
int Intersect | ( | const Line & | l, | |
const Circle & | c, | |||
float & | t1, | |||
float & | t2 | |||
) |
Intersects a Line with a Circle and finds the enter and exit time.
[in] | l | the Line. |
[in] | c | the circle. |
[out] | t1 | the time the Line l enters the Circle c. |
[out] | t2 | the time the Line l exits the Circle c. |
int Intersect | ( | const Ray & | r, | |
const Circle & | c, | |||
float & | t1, | |||
float & | t2 | |||
) |
Intersects a Ray with a Circle and finds the enter and exit time.
[in] | r | the Ray. |
[in] | c | the circle. |
[out] | t1 | the time the Ray r enters the Circle c. |
[out] | t2 | the time the Ray r exits the Circle c. |
pg 178
T lerp | ( | const T & | t1, | |
const T & | t2, | |||
U | t | |||
) | [inline] |
Linear interpolates between two objects of type T.
T | the data type to linearly interpolate between. The type must support the following operators:
| |
U | the data type time takes. Usually float or double . |
[in] | t1 | the starting point to interpolate from. |
[in] | t2 | the ending point to interpolate to. |
[in] | t | the time to interpolate to. |
T Maximum | ( | const T & | v1, | |
const T & | v2 | |||
) | [inline] |
Determines the maximum of two elements.
T | the data type of used. |
[in] | v1 | the first value. |
[in] | v2 | the second value. |
T Minimum | ( | const T & | v1, | |
const T & | v2 | |||
) | [inline] |
Determines the minimum of two elements.
T | the data type of used. |
[in] | v1 | the first value. |
[in] | v2 | the second value. |
Converts a point in normalized device coordinates to absolute Screen coordinates.
[in] | p | the point to convert. |
float RadToDeg | ( | float | a | ) | [inline] |
Converts an angle in Radians to Degrees.
[in] | a | the angle in Radians to convert. |
float RandomFloat | ( | float | min, | |
float | max | |||
) | [inline] |
Computes a random float in a given range.
[in] | min | the minimum end of the range. |
[in] | max | the maximum end of the range. |
Converts a Rect to an AABB.
T | the data type of the Rect. If T is not float data may be truncated. |
[in] | r | The Rect to convert. |
Converts a point in absolute Screen coordinates to normalized device coordinates.
[in] | p | the point to convert. |
T Sign | ( | const T & | val | ) | [inline] |
Determines the sign of the given value.
T | the data type of used. |
[in] | val | the value to determine the sign of. |
T SignZero | ( | const T & | val | ) | [inline] |
Determines the sign of the given value.
T | the data type of used. |
[in] | val | the value to determine the sign of. |
void Swap | ( | T & | v1, | |
T & | v2 | |||
) | [inline] |
Swaps the given two values.
T | the data type of the values to Swap. |
[in,out] | v1 | will be set to v2. |
[in,out] | v2 | will be set to v1. |
uint TimeSeed | ( | ) |
Computes a pretty good seed for a random number generator using the system time.
Transforms the given points.
[in,out] | p | the points to be transformed. |
[in] | n | the number of points. |
[in] | m | the transformation matrix. |
void Transform | ( | Poly & | p, | |
const Matrixf & | m | |||
) | [inline] |
Transforms the given polygon.
[in,out] | p | the polygon to be transformed. |
[in] | m | the transformation matrix. |
const float _2PI = 2.0f * PI |
const float DEG_TO_RAD = PI / 180.0f |
Degrees to Radians constant
const float E = 2.718281828459045f |
const float EPSILON = 0.0001f |
Small floating point value.
const float INV_PI = 1.0f / PI |
const float INV_SQRT2 = 1.0f / SQRT2 |
const float PI = 3.141592653589793f |
const float RAD_TO_DEG = 180.0f / PI |
Radians to Degrees constant
const float SQRT2 = 1.414213562373095f |
const float SQRT2_2 = 0.707106781186547f |