new geo functions

changed the walkers
added moving average
fixed the interpolator
new test-cases
This commit is contained in:
2016-01-30 19:49:18 +01:00
parent da0bd43fe0
commit ec86b07c43
8 changed files with 185 additions and 15 deletions

View File

@@ -1,6 +1,8 @@
#ifndef POINT2_H
#define POINT2_H
#include <cmath>
/**
* 2D Point
*/
@@ -15,10 +17,35 @@ struct Point2 {
/** ctor */
Point2(const float x, const float y) : x(x), y(y) {;}
Point2 operator + (const Point2& o) const {return Point2(x+o.x, y+o.y);}
Point2 operator - (const Point2& o) const {return Point2(x-o.x, y-o.y);}
Point2 operator * (const float v) const {return Point2(v*x, v*y);}
Point2 operator / (const float v) const {return Point2(x/v, y/v);}
Point2& operator *= (const float v) {x*=v; y*=v; return *this;}
Point2& operator /= (const float v) {x/=v; y/=v; return *this;}
Point2& operator += (const Point2& o) {x+=o.x; y+=o.y; return *this;}
Point2& operator -= (const Point2& o) {x-=o.x; y-=o.y; return *this;}
bool operator == (const Point2& o) const {return x==o.x && y==o.y;}
/** get the distance between this point and the other one */
float getDistance(const Point2& o) const {
const float dx = x - o.x;
const float dy = y - o.y;
return std::sqrt(dx*dx + dy*dy);
}
};
#endif // POINT2_H

View File

@@ -3,6 +3,7 @@
#include "../Assertions.h"
#include <cmath>
#include "Point2.h"
/**
* 3D Point
@@ -29,6 +30,7 @@ struct Point3 {
Point3 operator / (const float v) const {return Point3(x/v, y/v, z/v);}
Point3& operator *= (const float v) {x*=v; y*=v; z*=v; return *this;}
Point3& operator /= (const float v) {x/=v; y/=v; z/=v; return *this;}
@@ -37,8 +39,11 @@ struct Point3 {
Point3& operator -= (const Point3& o) {x-=o.x; y-=o.y; z-=o.z; return *this;}
bool operator == (const Point3& o) const {return x==o.x && y==o.y && z==o.z;}
Point2 xy() const {return Point2(x,y);}
/** read-only array access */
float operator [] (const int idx) const {
Assert::isBetween(idx, 0, 2, "index out of bounds");