78 lines
1.8 KiB
C++
78 lines
1.8 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#ifndef LINEARACCELERATIONDATA_H
|
||
#define LINEARACCELERATIONDATA_H
|
||
|
||
#include <cmath>
|
||
#include <sstream>
|
||
|
||
|
||
/** data received from an accelerometer sensor */
|
||
struct LinearAccelerationData {
|
||
|
||
float x;
|
||
float y;
|
||
float z;
|
||
|
||
LinearAccelerationData() : x(0), y(0), z(0) {;}
|
||
|
||
LinearAccelerationData(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
|
||
|
||
float magnitude() const {
|
||
return std::sqrt( x*x + y*y + z*z );
|
||
}
|
||
|
||
LinearAccelerationData& operator += (const LinearAccelerationData& o) {
|
||
this->x += o.x;
|
||
this->y += o.y;
|
||
this->z += o.z;
|
||
return *this;
|
||
}
|
||
|
||
LinearAccelerationData& operator -= (const LinearAccelerationData& o) {
|
||
this->x -= o.x;
|
||
this->y -= o.y;
|
||
this->z -= o.z;
|
||
return *this;
|
||
}
|
||
|
||
LinearAccelerationData operator - (const LinearAccelerationData& o) const {
|
||
return LinearAccelerationData(x-o.x, y-o.y, z-o.z);
|
||
}
|
||
|
||
LinearAccelerationData operator / (const float val) const {
|
||
return LinearAccelerationData(x/val, y/val, z/val);
|
||
}
|
||
|
||
std::string asString() const {
|
||
std::stringstream ss;
|
||
ss << "(" << x << "," << y << "," << z << ")";
|
||
return ss.str();
|
||
}
|
||
|
||
bool isValid() const {
|
||
return (x == x) && (y == y) && (z == z);
|
||
}
|
||
|
||
bool operator == (const LinearAccelerationData& o ) const {
|
||
return EQ_OR_NAN(x, o.x) &&
|
||
EQ_OR_NAN(y, o.y) &&
|
||
EQ_OR_NAN(z, o.z);
|
||
}
|
||
|
||
private:
|
||
|
||
static inline bool EQ_OR_NAN(const float a, const float b) {return (a==b) || ( (a!=a) && (b!=b) );}
|
||
|
||
};
|
||
|
||
#endif // LINEARACCELERATIONDATA_H
|