#ifndef GRIDPOINT_H #define GRIDPOINT_H #include #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);} /** 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