10#define d2Sqrt(x) sqrtf(x)
11#define d2Atan2(y, x) atan2f(y, x)
12#define d2Abs(x) ((x) > 0.0F ? (x) : -(x))
14#define PI 3.14159265359f
15#define TAU 6.28318530718f
35 void Zero() { x = 0.0F; y = 0.0F; }
62 real length = Lenght();
64 result.
x = x / length;
65 result.
y = y / length;
224 explicit d2Rot(
real angle) : s(sinf(angle)), c(cosf(angle)) {}
274 real temp_s = s * other.
c + c * other.
s;
275 real temp_c = c * other.
c - s * other.
s;
282 d2Rot result = *
this;
295 real aSin = sinf(angle);
296 real aCos = cosf(angle);
297 real temp_s = s * aCos + c * aSin;
298 real temp_c = c * aCos - s * aSin;
299 s = temp_s; c = temp_c;
355 return a < b ? a : b;
367 return a > b ? a : b;
387 return {s * v.
x, s * v.
y};
d2Vec2 d2Rotate(const d2Rot &rot, const d2Vec2 &v)
Definition d2Math.h:392
d2Vec2 operator*(real s, const d2Vec2 &v)
Definition d2Math.h:385
T d2Min(T a, T b)
Definition d2Math.h:353
#define d2Atan2(y, x)
Definition d2Math.h:11
#define d2Sqrt(x)
Definition d2Math.h:10
T d2Clamp(T value, T lower, T upper)
Definition d2Math.h:378
T d2Max(T a, T b)
Definition d2Math.h:365
float real
Definition d2Types.h:10
#define D2_API
Definition d2api.h:27
Represents an MxN matrix.
Definition d2Math.h:161
d2MatMN(int M, int N)
Constructor that initializes the matrix with given number of rows and columns.
d2MatMN(const d2MatMN &m)
void Zero()
Sets all components of the matrix to zero.
int M
The number of rows in the matrix.
Definition d2Math.h:197
const d2MatMN & operator=(const d2MatMN &m)
int N
The number of columns in the matrix.
Definition d2Math.h:198
static d2VecN SolveGaussSeidel(const d2MatMN &A, const d2VecN &b)
Solves a system of linear equations using the Gauss-Seidel method.
d2MatMN Transpose() const
Transposes the matrix.
d2VecN operator*(const d2VecN &v) const
d2MatMN operator*(const d2MatMN &m) const
d2VecN * rows
The rows of the matrix.
Definition d2Math.h:199
Represents a rotation in 2D space.
Definition d2Math.h:207
d2Rot()
Default constructor.
Definition d2Math.h:218
real c
The cosine of the rotation angle.
Definition d2Math.h:212
d2Rot(real angle)
Constructor that initializes the rotation with given angle in radians.
Definition d2Math.h:224
void Add(const d2Rot &other)
Adds the rotation of another d2Rot object to this object.
Definition d2Math.h:272
d2Rot & operator+=(const d2Rot &other)
Definition d2Math.h:287
real s
The sine of the rotation angle.
Definition d2Math.h:209
void Set(real angle)
Set the rotation angle from a given angle in radians.
Definition d2Math.h:237
d2Vec2 GetXAxis() const
Get the x-axis of the rotation.
Definition d2Math.h:260
d2Rot operator+(const d2Rot &other) const
Definition d2Math.h:280
d2Rot & operator+=(real angle)
Definition d2Math.h:293
d2Vec2 GetYAxis() const
Get the y-axis of the rotation.
Definition d2Math.h:266
void SetIdentity()
Set the rotation angle as identity.
Definition d2Math.h:244
real GetAngle() const
Get the rotation angle in radians.
Definition d2Math.h:254
d2Rot(real s, real c)
Constructor that initializes the rotation with given sine and cosine values.
Definition d2Math.h:231
Represents a 2D vector.
Definition d2Math.h:22
d2Vec2 & operator*=(const real n)
real Dot(const d2Vec2 &v) const
Calculates the dot product with another vector.
Definition d2Math.h:81
real y
Definition d2Math.h:106
d2Vec2 operator*(const real n) const
d2Vec2 & operator-=(const d2Vec2 &v)
bool operator!=(const d2Vec2 &v) const
d2Vec2 operator*(const d2Vec2 &v) const
d2Vec2 operator/(const real n) const
d2Vec2(real x, real y)
Constructor that initializes the vector with given x and y components.
Definition d2Math.h:30
d2Vec2 operator-(const d2Vec2 &v) const
d2Vec2()
Definition d2Math.h:23
d2Vec2 & operator*=(const d2Vec2 &v)
d2Vec2 & Normalize()
Normalizes the vector.
real Lenght() const
Calculates the magnitude of the vector.
Definition d2Math.h:41
d2Vec2 & operator+=(const d2Vec2 &v)
d2Vec2 UnitVector() const
Calculates the unit vector.
Definition d2Math.h:59
void Zero()
Sets all components of the vector to zero.
Definition d2Math.h:35
real LenghtSquared() const
Calculates the squared magnitude of the vector.
Definition d2Math.h:47
d2Vec2 operator+(const d2Vec2 &v) const
real Cross(const d2Vec2 &v) const
Calculates the cross product with another vector.
Definition d2Math.h:88
d2Vec2 & operator/=(const real n)
real x
Definition d2Math.h:106
bool operator==(const d2Vec2 &v) const
d2Vec2 Normal() const
Calculates the normal of the vector.
Definition d2Math.h:74
d2Vec2 & operator=(const d2Vec2 &v)
Represents an N-dimensional vector.
Definition d2Math.h:114
real & operator[](const int index)
real operator[](const int index) const
real * data
The data of the vector.
Definition d2Math.h:153
d2VecN operator-(const d2VecN &v) const
d2VecN operator*(const real n) const
void Zero()
Sets all components of the vector to zero.
const d2VecN & operator+=(const d2VecN &v)
const d2VecN & operator-=(const d2VecN &v)
d2VecN(const d2VecN &v)
Copy constructor.
d2VecN operator+(const d2VecN &v) const
int N
The dimension of the vector.
Definition d2Math.h:152
d2VecN & operator=(const d2VecN &v)
real Dot(const d2VecN &v) const
Calculates the dot product with another vector.
const d2VecN & operator*=(const real n)
d2VecN(int N)
Constructor that initializes the vector with given dimension.