index.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef NAV_GRID_INDEX_H
36 #define NAV_GRID_INDEX_H
37 
38 #include <string>
39 
40 namespace nav_grid
41 {
46 template <typename NumericType>
48 {
49  NumericType x, y;
50  explicit GenericIndex(const NumericType& x = 0, const NumericType& y = 0) : x(x), y(y) {}
51 
55  bool operator == (const GenericIndex& other) const
56  {
57  return x == other.x && y == other.y;
58  }
59 
60  bool operator != (const GenericIndex& other) const
61  {
62  return !operator==(other);
63  }
64 
68  bool operator < (const GenericIndex& other) const
69  {
70  return x < other.x || (x == other.x && y < other.y);
71  }
72 
73  // Derived Comparators
74  bool operator > (const GenericIndex& other) const { return other < *this; }
75  bool operator <= (const GenericIndex& other) const { return !(*this > other); }
76  bool operator >= (const GenericIndex& other) const { return !(*this < other); }
77 
81  std::string toString() const
82  {
83  return "(" + std::to_string(x) + ", " + std::to_string(y) + ")";
84  }
85 };
86 
87 template <typename NumericType>
88 inline std::ostream& operator<<(std::ostream& stream, const GenericIndex<NumericType>& index)
89 {
90  stream << index.toString();
91  return stream;
92 }
93 
96 
97 } // namespace nav_grid
98 
99 #endif // NAV_GRID_INDEX_H
bool operator>=(const GenericIndex &other) const
Definition: index.h:76
bool operator==(const GenericIndex &other) const
comparison operator that requires equal x and y
Definition: index.h:55
bool operator<=(const GenericIndex &other) const
Definition: index.h:75
bool operator!=(const GenericIndex &other) const
Definition: index.h:60
NumericType x
Definition: index.h:49
bool operator>(const GenericIndex &other) const
Definition: index.h:74
std::string toString() const
String representation of this object.
Definition: index.h:81
NumericType y
Definition: index.h:49
A simple pair of x/y coordinates.
Definition: index.h:47
GenericIndex(const NumericType &x=0, const NumericType &y=0)
Definition: index.h:50
bool operator<(const GenericIndex &other) const
less than operator so object can be used in sets
Definition: index.h:68


nav_grid
Author(s):
autogenerated on Sun Jan 10 2021 04:08:26