CARLA
geom/Location.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 "carla/geom/Vector3D.h"
10 #include "carla/geom/Vector3DInt.h"
11 #include "carla/geom/Math.h"
12 
13 #ifdef LIBCARLA_INCLUDED_FROM_UE4
14 # include "Math/Vector.h"
15 #endif // LIBCARLA_INCLUDED_FROM_UE4
16 
17 namespace carla {
18 namespace geom {
19 
20  class Location : public Vector3D {
21  public:
22 
23  // =========================================================================
24  // -- Constructors ---------------------------------------------------------
25  // =========================================================================
26 
27  Location() = default;
28 
29  using Vector3D::Vector3D;
30 
31  Location(const Vector3D &rhs) : Vector3D(rhs) {}
32 
33  Location(const Vector3DInt &rhs) :
34  Vector3D(static_cast<float>(rhs.x),
35  static_cast<float>(rhs.y),
36  static_cast<float>(rhs.z)) {}
37 
38  // =========================================================================
39  // -- Other methods --------------------------------------------------------
40  // =========================================================================
41 
42  auto Distance(const Location &loc) const {
43  return Math::Distance(*this, loc);
44  }
45 
46  // =========================================================================
47  // -- Arithmetic operators -------------------------------------------------
48  // =========================================================================
49 
50  Location &operator+=(const Location &rhs) {
51  static_cast<Vector3D &>(*this) += rhs;
52  return *this;
53  }
54 
55  friend Location operator+(Location lhs, const Location &rhs) {
56  lhs += rhs;
57  return lhs;
58  }
59 
60  Location &operator-=(const Location &rhs) {
61  static_cast<Vector3D &>(*this) -= rhs;
62  return *this;
63  }
64 
65  friend Location operator-(Location lhs, const Location &rhs) {
66  lhs -= rhs;
67  return lhs;
68  }
69 
70  // =========================================================================
71  // -- Comparison operators -------------------------------------------------
72  // =========================================================================
73 
74  bool operator==(const Location &rhs) const {
75  return static_cast<const Vector3D &>(*this) == rhs;
76  }
77 
78  bool operator!=(const Location &rhs) const {
79  return !(*this == rhs);
80  }
81 
82  // =========================================================================
83  // -- Conversions to UE4 types ---------------------------------------------
84  // =========================================================================
85 
86 #ifdef LIBCARLA_INCLUDED_FROM_UE4
87 
88  Location(const FVector &vector) // from centimeters to meters.
89  : Location(1e-2f * vector.X, 1e-2f * vector.Y, 1e-2f * vector.Z) {}
90 
91  operator FVector() const {
92  return FVector{1e2f * x, 1e2f * y, 1e2f * z}; // from meters to centimeters.
93  }
94 
95 #endif // LIBCARLA_INCLUDED_FROM_UE4
96  };
97 
98 } // namespace geom
99 } // namespace carla
static auto Distance(const Vector3D &a, const Vector3D &b)
Definition: Math.h:78
Location & operator+=(const Location &rhs)
Definition: geom/Location.h:50
bool operator==(const Location &rhs) const
Definition: geom/Location.h:74
bool operator!=(const Location &rhs) const
Definition: geom/Location.h:78
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
friend Location operator-(Location lhs, const Location &rhs)
Definition: geom/Location.h:65
Location(const Vector3D &rhs)
Definition: geom/Location.h:31
auto Distance(const Location &loc) const
Definition: geom/Location.h:42
Location(const Vector3DInt &rhs)
Definition: geom/Location.h:33
Location & operator-=(const Location &rhs)
Definition: geom/Location.h:60
friend Location operator+(Location lhs, const Location &rhs)
Definition: geom/Location.h:55