CARLA
 
载入中...
搜索中...
未找到
geom/Location.h
浏览该文件的文档.
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
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
19namespace carla {
20namespace geom {
21
22 class Location : public Vector3D {
23 public:
24
25 // =========================================================================
26 // -- Constructors ---------------------------------------------------------
27 // =========================================================================
28
29 Location() = default;
30
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
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
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
Location & operator-=(const Location &rhs)
friend Location operator+(Location lhs, const Location &rhs)
bool operator==(const Location &rhs) const
Location(const Vector3DInt &rhs)
Location(const FVector &vector)
auto Distance(const Location &loc) const
Location & operator+=(const Location &rhs)
bool operator!=(const Location &rhs) const
auto DistanceSquared(const Location &loc) const
Location(const Vector3D &rhs)
friend Location operator-(Location lhs, const Location &rhs)
static auto DistanceSquared(const Vector3D &a, const Vector3D &b)
Definition Math.h:70
static auto Distance(const Vector3D &a, const Vector3D &b)
Definition Math.h:78
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133