summaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/README.txt1
-rw-r--r--src/math/all.h1
-rw-r--r--src/math/const.h1
-rw-r--r--src/math/func.h7
-rw-r--r--src/math/geometry.h1
-rw-r--r--src/math/intpoint.h1
-rw-r--r--src/math/matrix.h17
-rw-r--r--src/math/point.h16
-rw-r--r--src/math/vector.h19
9 files changed, 39 insertions, 25 deletions
diff --git a/src/math/README.txt b/src/math/README.txt
index 26069aa..fcc204f 100644
--- a/src/math/README.txt
+++ b/src/math/README.txt
@@ -10,3 +10,4 @@
* This namespace was created to avoid clashing with old code, but now it still serves,
* defining a border between math and non-math-related code.
*/
+
diff --git a/src/math/all.h b/src/math/all.h
index 10c17a9..7d716c8 100644
--- a/src/math/all.h
+++ b/src/math/all.h
@@ -28,3 +28,4 @@
#include "math/vector.h"
#include "math/matrix.h"
#include "math/geometry.h"
+
diff --git a/src/math/const.h b/src/math/const.h
index 8318b7a..fee635e 100644
--- a/src/math/const.h
+++ b/src/math/const.h
@@ -53,3 +53,4 @@ const float LOG_2 = log(2.0f);
} // namespace Math
+
diff --git a/src/math/func.h b/src/math/func.h
index 413b5d9..98111c5 100644
--- a/src/math/func.h
+++ b/src/math/func.h
@@ -128,6 +128,12 @@ inline float Rand()
return static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
}
+//! Returns whether \a x is an even power of 2
+inline bool IsPowerOfTwo(unsigned int x)
+{
+ return x && !(x & (x - 1));
+}
+
//! Returns the next nearest power of two to \a x
inline int NextPowerOfTwo(int x)
{
@@ -257,3 +263,4 @@ inline float Bounce(float progress, float middle = 0.3f, float bounce = 0.4f)
} // namespace Math
+
diff --git a/src/math/geometry.h b/src/math/geometry.h
index 23c149c..9dcb447 100644
--- a/src/math/geometry.h
+++ b/src/math/geometry.h
@@ -643,3 +643,4 @@ inline Math::Vector RotateView(Math::Vector center, float angleH, float angleV,
} // namespace Math
+
diff --git a/src/math/intpoint.h b/src/math/intpoint.h
index 010b0fb..872e614 100644
--- a/src/math/intpoint.h
+++ b/src/math/intpoint.h
@@ -59,3 +59,4 @@ struct IntPoint
} // namespace Math
+
diff --git a/src/math/matrix.h b/src/math/matrix.h
index e0cf492..f139517 100644
--- a/src/math/matrix.h
+++ b/src/math/matrix.h
@@ -73,10 +73,10 @@ struct Matrix
//! Creates the matrix from 1D array
/** \a m matrix values in column-major order */
- inline explicit Matrix(const float (&m)[16])
+ inline explicit Matrix(const float (&_m)[16])
{
for (int i = 0; i < 16; ++i)
- this->m[i] = m[i];
+ m[i] = _m[i];
}
//! Creates the matrix from 2D array
@@ -84,21 +84,21 @@ struct Matrix
* The array's first index is row, second is column.
* \param m array with values
*/
- inline explicit Matrix(const float (&m)[4][4])
+ inline explicit Matrix(const float (&_m)[4][4])
{
for (int c = 0; c < 4; ++c)
{
for (int r = 0; r < 4; ++r)
{
- this->m[4*c+r] = m[r][c];
+ m[4*c+r] = _m[r][c];
}
}
}
//! Sets value in given row and col
/**
- * \param row row (0 to 3)
- * \param col column (0 to 3)
+ * \param row row (1 to 4)
+ * \param col column (1 to 4)
* \param value value
*/
inline void Set(int row, int col, float value)
@@ -108,8 +108,8 @@ struct Matrix
//! Returns the value in given row and col
/**
- * \param row row (0 to 3)
- * \param col column (0 to 3)
+ * \param row row (1 to 4)
+ * \param col column (1 to 4)
* \returns value
*/
inline float Get(int row, int col)
@@ -462,3 +462,4 @@ inline Math::Vector MatrixVectorMultiply(const Math::Matrix &m, const Math::Vect
} // namespace Math
+
diff --git a/src/math/point.h b/src/math/point.h
index 456fe1e..edb902b 100644
--- a/src/math/point.h
+++ b/src/math/point.h
@@ -52,16 +52,15 @@ struct Point
//! Constructs a zero point: (0,0)
inline Point()
- {
- LoadZero();
- }
+ : x(0.0f)
+ , y(0.0f)
+ {}
//! Constructs a point from given coords: (x,y)
- inline explicit Point(float x, float y)
- {
- this->x = x;
- this->y = y;
- }
+ inline explicit Point(float _x, float _y)
+ : x(_x)
+ , y(_y)
+ {}
//! Sets the zero point: (0,0)
inline void LoadZero()
@@ -191,3 +190,4 @@ inline float Distance(const Point &a, const Point &b)
} // namespace Math
+
diff --git a/src/math/vector.h b/src/math/vector.h
index 73e8e44..6827785 100644
--- a/src/math/vector.h
+++ b/src/math/vector.h
@@ -57,17 +57,17 @@ struct Vector
//! Creates a zero vector (0, 0, 0)
inline Vector()
- {
- LoadZero();
- }
+ : x(0.0f)
+ , y(0.0f)
+ , z(0.0f)
+ {}
//! Creates a vector from given values
- inline explicit Vector(float x, float y, float z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- }
+ inline explicit Vector(float _x, float _y, float _z)
+ : x(_x)
+ , y(_y)
+ , z(_z)
+ {}
//! Loads the zero vector (0, 0, 0)
inline void LoadZero()
@@ -281,3 +281,4 @@ inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max)
} // namespace Math
+