Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef NAV_GRID_INDEX_H
00036 #define NAV_GRID_INDEX_H
00037
00038 #include <string>
00039
00040 namespace nav_grid
00041 {
00046 template <typename NumericType>
00047 struct GenericIndex
00048 {
00049 NumericType x, y;
00050 explicit GenericIndex(const NumericType& x = 0, const NumericType& y = 0) : x(x), y(y) {}
00051
00055 bool operator == (const GenericIndex& other) const
00056 {
00057 return x == other.x && y == other.y;
00058 }
00059
00060 bool operator != (const GenericIndex& other) const
00061 {
00062 return !operator==(other);
00063 }
00064
00068 bool operator < (const GenericIndex& other) const
00069 {
00070 return x < other.x || (x == other.x && y < other.y);
00071 }
00072
00073
00074 bool operator > (const GenericIndex& other) const { return other < *this; }
00075 bool operator <= (const GenericIndex& other) const { return !(*this > other); }
00076 bool operator >= (const GenericIndex& other) const { return !(*this < other); }
00077
00081 std::string toString() const
00082 {
00083 return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
00084 }
00085 };
00086
00087 template <typename NumericType>
00088 inline std::ostream& operator<<(std::ostream& stream, const GenericIndex<NumericType>& index)
00089 {
00090 stream << index.toString();
00091 return stream;
00092 }
00093
00094 using SignedIndex = GenericIndex<int>;
00095 using Index = GenericIndex<unsigned int>;
00096
00097 }
00098
00099 #endif // NAV_GRID_INDEX_H