graphical exception [temporary solution]
performance fixes minor changes
This commit is contained in:
26
geo/Angle.h
26
geo/Angle.h
@@ -5,6 +5,8 @@
|
||||
#include "../Assertions.h"
|
||||
#include "Point2.h"
|
||||
|
||||
#define PI ((float) M_PI)
|
||||
|
||||
struct Angle {
|
||||
|
||||
|
||||
@@ -14,7 +16,7 @@ public:
|
||||
static float getRAD_2PI(const float x1, const float y1, const float x2, const float y2) {
|
||||
Assert::isFalse( (x1==x2)&&(y1==y2), "(x1,y1) must not equal (x2,y2)!!");
|
||||
const float tmp = std::atan2(y2-y1, x2-x1);
|
||||
return (tmp < 0) ? (tmp + 2*M_PI) : (tmp);
|
||||
return (tmp < 0) ? (tmp + 2*PI) : (tmp);
|
||||
}
|
||||
|
||||
/** get the radians from (0,0) to (p.x,p.y) between 0 (to-the-right) and <2_PI */
|
||||
@@ -34,10 +36,10 @@ public:
|
||||
* - as a change-in-direction between [0:PI]
|
||||
*/
|
||||
static float getDiffRAD_2PI_PI(const float r1, const float r2) {
|
||||
Assert::isBetween(r1, 0.0f, (float)(2*M_PI), "r1 out of bounds");
|
||||
Assert::isBetween(r2, 0.0f, (float)(2*M_PI), "r2 out of bounds");
|
||||
Assert::isBetween(r1, 0.0f, (2*PI), "r1 out of bounds");
|
||||
Assert::isBetween(r2, 0.0f, (2*PI), "r2 out of bounds");
|
||||
float tmp = std::abs(r1-r2);
|
||||
return (tmp <= M_PI) ? (tmp) : (2*M_PI-tmp);
|
||||
return (tmp <= PI) ? (tmp) : (2*PI-tmp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,23 +48,23 @@ public:
|
||||
* - as a change-in-direction between [-PI:+PI]
|
||||
*/
|
||||
static float getSignedDiffRAD_2PI(const float r1, const float r2) {
|
||||
Assert::isBetween(r1, 0.0f, (float)(2*M_PI), "r1 out of bounds"); // [0:360] deg
|
||||
Assert::isBetween(r2, 0.0f, (float)(2*M_PI), "r2 out of bounds"); // [0:360] deg
|
||||
Assert::isBetween(r1, 0.0f, (float)(2*PI), "r1 out of bounds"); // [0:360] deg
|
||||
Assert::isBetween(r2, 0.0f, (float)(2*PI), "r2 out of bounds"); // [0:360] deg
|
||||
float diff = r1-r2;
|
||||
if (diff > +M_PI) {diff = -(2*M_PI - diff);}
|
||||
else if (diff < -M_PI) {diff = +(2*M_PI + diff);}
|
||||
Assert::isBetween(diff, (float)-M_PI, (float)(+M_PI), "result out of bounds"); // [-180:+180] deg
|
||||
if (diff > +PI) {diff = -(2*PI - diff);}
|
||||
else if (diff < -PI) {diff = +(2*PI + diff);}
|
||||
Assert::isBetween(diff, -PI, (float)(+PI), "result out of bounds"); // [-180:+180] deg
|
||||
return diff;
|
||||
}
|
||||
|
||||
/** convert degrees to radians */
|
||||
static constexpr inline float degToRad(const float deg) {
|
||||
return deg / 180.0f * M_PI;
|
||||
return deg / 180.0f * PI;
|
||||
}
|
||||
|
||||
/** convert radians to degrees */
|
||||
static constexpr inline float radToDeg(const float rad) {
|
||||
return rad * 180.0f / M_PI;
|
||||
return rad * 180.0f / PI;
|
||||
}
|
||||
|
||||
/** get a pointer vector (length 1) pointing to the given angle (in radians) */
|
||||
@@ -74,4 +76,6 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#undef PI
|
||||
|
||||
#endif // ANGLE_H
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
struct Heading {
|
||||
|
||||
#define _2PI (2*M_PI)
|
||||
#define _2PI (2*(float)M_PI)
|
||||
|
||||
private:
|
||||
|
||||
@@ -105,10 +105,10 @@ public:
|
||||
};
|
||||
|
||||
namespace Headings {
|
||||
static const Heading RIGHT = Heading(M_PI*0/2);
|
||||
static const Heading UP = Heading(M_PI*1/2);
|
||||
static const Heading LEFT = Heading(M_PI*2/2);
|
||||
static const Heading DOWN = Heading(M_PI*3/2);
|
||||
static const Heading RIGHT = Heading((float)M_PI*0.0f/2.0f);
|
||||
static const Heading UP = Heading((float)M_PI*1.0f/2.0f);
|
||||
static const Heading LEFT = Heading((float)M_PI*2.0f/2.0f);
|
||||
static const Heading DOWN = Heading((float)M_PI*3.0f/2.0f);
|
||||
}
|
||||
|
||||
#endif // HEADING_H
|
||||
|
||||
Reference in New Issue
Block a user