summaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/const.h11
-rw-r--r--src/math/func.h8
-rw-r--r--src/math/geometry.h4
-rw-r--r--src/math/intsize.h15
-rw-r--r--src/math/size.h9
5 files changed, 39 insertions, 8 deletions
diff --git a/src/math/const.h b/src/math/const.h
index dd7ab0f..b08a400 100644
--- a/src/math/const.h
+++ b/src/math/const.h
@@ -20,6 +20,8 @@
#pragma once
+#include <cmath>
+
// Math module namespace
namespace Math
@@ -30,12 +32,12 @@ namespace Math
const float TOLERANCE = 1e-6f;
//! Very small number (used in testing/returning some values)
-const float VERY_SMALL = 1e-6f;
+const float VERY_SMALL_NUM = 1e-6f;
//! Very big number (used in testing/returning some values)
-const float VERY_BIG = 1e6f;
+const float VERY_BIG_NUM = 1e6f;
//! Huge number
-const float HUGE = 1.0e+38f;
+const float HUGE_NUM = 1.0e+38f;
//! PI
const float PI = 3.14159265358979323846f;
@@ -45,6 +47,9 @@ const float DEG_TO_RAD = 0.01745329251994329547f;
//! Radians to degrees multiplier
const float RAD_TO_DEG = 57.29577951308232286465f;
+//! Natural logarithm of 2
+const float LOG_2 = log(2.0f);
+
/* @} */ // end of group
}; // namespace Math
diff --git a/src/math/func.h b/src/math/func.h
index 2127d1a..e97d990 100644
--- a/src/math/func.h
+++ b/src/math/func.h
@@ -127,6 +127,14 @@ inline float Rand()
return static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
}
+//! Returns the next nearest power of two to \a x
+inline int NextPowerOfTwo(int x)
+{
+ double logbase2 = log(static_cast<float>(x)) / Math::LOG_2;
+ return static_cast<int>(pow(2, ceil(logbase2)) + 0.5);
+}
+
+
//! Returns a normalized angle, that is in other words between 0 and 2 * PI
inline float NormAngle(float angle)
{
diff --git a/src/math/geometry.h b/src/math/geometry.h
index 61d1868..3a31ad6 100644
--- a/src/math/geometry.h
+++ b/src/math/geometry.h
@@ -45,9 +45,9 @@ inline float MidPoint(const Math::Point &a, const Math::Point &b, float px)
if (IsEqual(a.x, b.x))
{
if (a.y < b.y)
- return HUGE;
+ return Math::HUGE_NUM;
else
- return -HUGE;
+ return -Math::HUGE_NUM;
}
return (b.y-a.y) * (px-a.x) / (b.x-a.x) + a.y;
}
diff --git a/src/math/intsize.h b/src/math/intsize.h
index f4b2431..d53de85 100644
--- a/src/math/intsize.h
+++ b/src/math/intsize.h
@@ -20,6 +20,9 @@
#pragma once
+#include "math/intpoint.h"
+
+
// Math module namespace
namespace Math
{
@@ -31,9 +34,9 @@ namespace Math
struct IntSize
{
//! Width
- int w;
+ long w;
//! Height
- int h;
+ long h;
//! Constructs a zero size: (0,0)
inline IntSize()
@@ -42,7 +45,7 @@ struct IntSize
}
//! Constructs a size from given dimensions: (w,h)
- inline explicit IntSize(int w, int h)
+ inline explicit IntSize(long w, long h)
{
this->w = w;
this->h = h;
@@ -53,6 +56,12 @@ struct IntSize
{
w = h = 0;
}
+
+ //! Converts Point to Size
+ inline static Math::IntSize FromIntPoint(Math::IntPoint p)
+ {
+ return Math::IntSize(p.x, p.y);
+ }
}; // struct Size
diff --git a/src/math/size.h b/src/math/size.h
index 781b9a4..03cffaa 100644
--- a/src/math/size.h
+++ b/src/math/size.h
@@ -20,6 +20,9 @@
#pragma once
+#include "math/point.h"
+
+
// Math module namespace
namespace Math
{
@@ -58,6 +61,12 @@ struct Size
{
w = h = 0.0f;
}
+
+ //! Converts Point to Size
+ inline static Math::Size FromPoint(Math::Point p)
+ {
+ return Math::Size(p.x, p.y);
+ }
}; // struct Size