📄 mathutils.h
字号:
#ifndef __MATH_UTILS_H
#define __MATH_UTILS_H
#include <e32math.h>
// __USE_TLS should be enabled if project is built as an APP (DLL)
// It should be disabled for an EXE
// #define __USE_TLS
//
// Static class of utils
//
/*
* Pregenerated sin and cos tables
*/
#include "sincostables.h"
/*
MathUtils - For when Math is just not fast enoug
*/
class MathUtils
{
public:
// Fast Square root
static TInt32 SquareRoot(TInt32 aNum);
// Distance between two integer points
static TInt Distance(const TPoint& aA, const TPoint& aB);
inline static TReal Sin(TReal aNumber);
inline static TReal Cos(TReal aNumber);
// Fast Cos for whole angles between 0 and 360
static inline TReal Cos(TInt aAngle);
// Fast Sin for whole angles between 0 and 360
static inline TReal Sin(TInt aAngle);
// Fast Cos for whole angles between 0 and 360
static void ConstructL();
static inline TInt Round(TReal aNumber);
inline static TInt Random(TInt aA, TInt aB);
// return x bounded between a and b
template<class T>
inline T Bound(T x, T a, T b);
static void Reset();
static TBool Intersect(TPoint l1p1, TPoint l1p2, TPoint l2p1, TPoint l2p2);
};
inline TReal MathUtils::Sin(TReal aNumber)
{
TReal result;
Math::Sin(result, aNumber);
return result;
}
inline TReal MathUtils::Cos(TReal aNumber)
{
TReal result;
Math::Cos(result, aNumber);
return result;
}
/*
Fast Cos for whole angles between 0 and 360
*/
inline TReal MathUtils::Cos(TInt aAngle)
{
return KCosLookup[aAngle%360];
}
/*
Fast Sin for whole angles between 0 and 360
*/
inline TReal MathUtils::Sin(TInt aAngle)
{
return KSinLookup[aAngle%360];
}
/*
Faster replacement for Math::Round
*/
inline TInt MathUtils::Round(TReal aNumber)
{
TInt whole = (TInt)aNumber;
TReal frac = aNumber-whole;
if(frac>=0.5)
return whole+1;
else
return whole;
}
// Random number between a and b
TInt MathUtils::Random(TInt aA, TInt aB)
{
if(aA == aB)
return aA;
return Math::Random()%(aB - aA) + aA;
}
// return x bounded between a and b
template<class T>
T MathUtils::Bound(T x, T a, T b)
{
if(x<a) x=0;
if(x>b) x=b;
return x;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -