started removing KLib related code:

- assertions
- distributions
new helper methods
worked on stairs
worked on grid-walkers
worked on navigation
This commit is contained in:
2016-01-27 20:03:58 +01:00
parent e6329e1db4
commit 0e05f4bef8
26 changed files with 408 additions and 109 deletions

View File

@@ -2,7 +2,7 @@
#define ANGLE_H
#include <cmath>
#include <KLib/Assertions.h>
#include "../Assertions.h"
struct Angle {
@@ -11,7 +11,7 @@ public:
/** get the radians from (x1,y1) to (x2,y2) between 0 (to-the-right) and <2_PI */
static float getRAD_2PI(const float x1, const float y1, const float x2, const float y2) {
_assertFalse( (x1==x2)&&(y1==y2), "(x1,y1) must not equal (x2,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);
}
@@ -27,8 +27,8 @@ public:
* - as a change-in-direction between [0:PI]
*/
static float getDiffRAD_2PI_PI(const float r1, const float r2) {
_assertBetween(r1, 0, (float)(2*M_PI), "r1 out of bounds");
_assertBetween(r2, 0, (float)(2*M_PI), "r2 out of bounds");
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");
float tmp = std::abs(r1-r2);
return (tmp <= M_PI) ? (tmp) : (2*M_PI-tmp);
}

View File

@@ -19,8 +19,12 @@ protected:
public:
/** empty ctor */
BBox2() : p1(MAX,MAX), p2(MIN,MIN) {;}
/** ctor */
BBox2(const Point2& p1, const Point2& p2) : p1(p1), p2(p2) {;}
/** adjust the bounding-box by adding this point */
void add(const Point2& p) {

View File

@@ -19,12 +19,12 @@ public:
/** ctor with radians */
Heading(const float rad) : rad(rad) {
_assertBetween(rad, 0, _2PI, "radians out of bounds");
Assert::isBetween(rad, 0.0f, (float)_2PI, "radians out of bounds");
}
/** ctor from(x1,y1) to(x2,y2) */
Heading(const float x1, const float y1, const float x2, const float y2) : rad(Angle::getRAD_2PI(x1,y1,x2,y2)) {
_assertBetween(rad, 0, _2PI, "radians out of bounds");
Assert::isBetween(rad, 0.0f, (float)_2PI, "radians out of bounds");
}
/** angular difference [0:PI] */
@@ -34,7 +34,7 @@ public:
/** update the angle but ensure we stay within [0:2PI] */
Heading& operator += (const float _rad) {
_assertBetween(_rad, -_2PI*0.99, +_2PI*0.99, "radians out of bounds");
Assert::isBetween(_rad, float(-_2PI*0.99), float(+_2PI*0.99), "radians out of bounds");
rad += _rad;
if (rad >= _2PI) {rad -= _2PI;}
else if (rad < 0) {rad += _2PI;}

View File

@@ -1,7 +1,7 @@
#ifndef POINT3_H
#define POINT3_H
#include <KLib/Assertions.h>
#include "../Assertions.h"
#include <cmath>
/**
@@ -37,7 +37,7 @@ struct Point3 {
/** read-only array access */
float operator [] (const int idx) const {
_assertBetween(idx, 0, 2, "index out of bounds");
Assert::isBetween(idx, 0, 2, "index out of bounds");
if (0 == idx) {return x;}
if (1 == idx) {return y;}
return z;