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