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