This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/grid/GridPoint.h
FrankE 99ee95ce7b worked on signal-strength-estimation
add this information to grid nodes
evaluate this information
new test-cases
2016-07-15 15:29:07 +02:00

75 lines
1.8 KiB
C++
Executable File

#ifndef GRIDPOINT_H
#define GRIDPOINT_H
#include <cmath>
#include "../geo/Point3.h"
#include "../Assertions.h"
struct GridPoint {
/** x-position (in centimeter) */
float x_cm;
/** y-position (in centimeter) */
float y_cm;
/** z-position (in centimeter) */
float z_cm;
/** empty ctor */
GridPoint() : x_cm(0), y_cm(0), z_cm(0) {;}
/** ctor */
GridPoint(const float x_cm, const float y_cm, const float z_cm) : x_cm(x_cm), y_cm(y_cm), z_cm(z_cm) {;}
/** equal? */
bool operator == (const GridPoint& o) const {
return x_cm == o.x_cm && y_cm == o.y_cm && z_cm == o.z_cm;
}
/** not equal? */
bool operator != (const GridPoint& o) const {
return x_cm != o.x_cm || y_cm != o.y_cm || z_cm != o.z_cm;
}
/** get the distance (in meter) betwen this and the given point */
float getDistanceInMeter(const GridPoint& other) const {
return getDistanceInCM(other) / 100.0f;
}
/** get the distance (in centimeter) betwen this and the given point */
float getDistanceInCM(const GridPoint& other) const {
const int dx = x_cm - other.x_cm;
const int dy = y_cm - other.y_cm;
const int dz = z_cm - other.z_cm;
return std::sqrt(dx*dx + dy*dy + dz*dz);
}
///** cast to Point3 */
//operator Point3() const {return Point3(x_cm, y_cm, z_cm);}
/** convert to Point3 in centimeter */
Point3 inCentimeter() const {return Point3(x_cm, y_cm, z_cm);}
/** convert to Point3 in meter */
Point3 inMeter() const {return Point3(x_cm/100.0f, y_cm/100.0f, z_cm/100.0f);}
/** cast to string */
operator std::string() const {return "(" + std::to_string(x_cm) + "," + std::to_string(y_cm) + "," + std::to_string(z_cm) + ")";}
/** read-only array access */
float operator [] (const int idx) const {
Assert::isBetween(idx, 0, 2, "index out of bounds");
if (0 == idx) {return x_cm;}
if (1 == idx) {return y_cm;}
{return z_cm;}
}
};
#endif // GRIDPOINT_H