CARLA
Position.h
Go to the documentation of this file.
1 // Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include <type_traits>
10 
11 namespace MapGen {
12 
13  template<typename T>
14  class Position {
15  public:
16  using number_type = T;
17 
18  static_assert(
19  std::is_arithmetic<number_type>::value &&
20  !std::is_same<number_type, bool>::value, "not a valid number type");
21 
22  number_type x;
23 
25 
26  Position() = default;
27 
28  constexpr Position(T X, T Y) : x(X), y(Y) {}
29 
30  constexpr bool operator==(const Position &rhs) const {
31  return (x == rhs.x) && (y == rhs.y);
32  }
33 
34  constexpr bool operator!=(const Position &rhs) const {
35  return !(*this == rhs);
36  }
37 
38  Position &operator+=(const Position &rhs) {
39  x += rhs.x;
40  y += rhs.y;
41  return *this;
42  }
43 
44  friend Position operator+(Position lhs, const Position &rhs) {
45  lhs += rhs;
46  return lhs;
47  }
48 
49  Position &operator-=(const Position &rhs) {
50  x -= rhs.x;
51  y -= rhs.y;
52  return *this;
53  }
54 
55  friend Position operator-(Position lhs, const Position &rhs) {
56  lhs -= rhs;
57  return lhs;
58  }
59  };
60 
61 } // namespace MapGen
Position & operator+=(const Position &rhs)
Definition: Position.h:38
Position()=default
Position & operator-=(const Position &rhs)
Definition: Position.h:49
number_type x
Definition: Position.h:20
constexpr Position(T X, T Y)
Definition: Position.h:28
constexpr bool operator==(const Position &rhs) const
Definition: Position.h:30
friend Position operator+(Position lhs, const Position &rhs)
Definition: Position.h:44
constexpr bool operator!=(const Position &rhs) const
Definition: Position.h:34
friend Position operator-(Position lhs, const Position &rhs)
Definition: Position.h:55
number_type y
Definition: Position.h:24