added corresponding test-cases switched to newer version of tinyxml due to some issues adjusted affected code-parts accordingly for better re-use, moved ceiling-calculation to a new class some minor fixes new helper methods worked on wifi-opt
72 lines
1.6 KiB
C++
72 lines
1.6 KiB
C++
#ifndef POINT2_H
|
|
#define POINT2_H
|
|
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
|
|
/**
|
|
* 2D Point
|
|
*/
|
|
struct Point2 {
|
|
|
|
float x;
|
|
float y;
|
|
|
|
/** ctor */
|
|
Point2() : x(0), y(0) {;}
|
|
|
|
/** ctor */
|
|
Point2(const float x, const float y) : x(x), y(y) {;}
|
|
|
|
Point2 operator - () const {return Point2(-x, -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;}
|
|
|
|
bool operator != (const Point2& o) const {return x!=o.x || y!=o.y;}
|
|
|
|
|
|
Point2 perpendicular() const {return Point2(-y, x);}
|
|
|
|
float length() const {return std::sqrt(x*x + y*y);}
|
|
|
|
Point2 normalized() const {return (*this) / length();}
|
|
|
|
Point2 rotated(const float rad) const {
|
|
return Point2(x*std::cos(rad)-y*std::sin(rad), x*std::sin(rad)+y*std::cos(rad));
|
|
}
|
|
|
|
/** 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);
|
|
}
|
|
|
|
};
|
|
|
|
inline void swap(Point2& p1, Point2& p2) {
|
|
std::swap(p1.x, p2.x);
|
|
std::swap(p1.y, p2.y);
|
|
}
|
|
|
|
#endif // POINT2_H
|