CARLA
 
载入中...
搜索中...
未找到
geom/Location.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// 位置类
5//
6// This work is licensed under the terms of the MIT license.
7// For a copy, see <https://opensource.org/licenses/MIT>.
8
9#pragma once // 这是一个预处理指令,作用是确保该头文件在整个编译过程中只会被包含一次,
10// 避免因多次包含同一头文件而导致的重复定义等编译错误。
11
12#include "carla/geom/Vector3D.h" // 包含名为"carla/geom/Vector3D.h"的头文件,通常这个头文件中会定义三维向量相关的结构体、类或者函数等,
13// 可能是用于表示空间中的向量信息,是当前代码实现功能所依赖的外部声明所在的头文件之一,
14// 这里的位置类可能会基于三维向量的相关概念来构建其功能。
15#include "carla/geom/Vector3DInt.h" // 包含名为"carla/geom/Vector3DInt.h"的头文件,推测里面定义了整数类型的三维向量相关内容,
16// 可能用于在某些特定场景下(比如涉及到坐标的整数表示等情况)与位置相关的操作,同样是当前代码依赖的外部声明所在的头文件。
17#include "carla/geom/Math.h"
18
19#ifdef LIBCARLA_INCLUDED_FROM_UE4
21#include "Math/Vector.h"
23#endif // LIBCARLA_INCLUDED_FROM_UE4
24
25namespace carla {
26namespace geom {
27
28 class Location : public Vector3D {
29 public:
30
31 // =========================================================================
32 // -- 构造函数 -------------------------------------------------------------
33 // =========================================================================
34
35 Location() = default;
36
37 using Vector3D::Vector3D; // 这行代码使用了"using"声明,它将"Vector3D"类的构造函数引入到"Location"类中,
38 // 使得"Location"类可以使用"Vector3D"类的构造函数来进行对象的初始化,方便复用已有的构造逻辑。
39
40 Location(const Vector3D &rhs) : Vector3D(rhs) {} // 这是一个拷贝构造函数,它接受一个"Vector3D"类型的参数"rhs",通过调用基类("Vector3D")的拷贝构造函数,
41 // 将传入的"rhs"对象的内容复制到当前正在创建的"Location"类对象中,实现了从"Vector3D"类型对象到"Location"类对象的初始化。
42
43 Location(const Vector3DInt &rhs) :
44 Vector3D(static_cast<float>(rhs.x),
45 static_cast<float>(rhs.y),
46 static_cast<float>(rhs.z)) {}
47
48 // =========================================================================
49 // -- 其他方法 --------------------------------------------------------------
50 // =========================================================================
51
52 auto DistanceSquared(const Location &loc) const {
53 return Math::DistanceSquared(*this, loc);
54 }
55
56 auto Distance(const Location &loc) const {
57 return Math::Distance(*this, loc);
58 }
59
60 // =========================================================================
61 // -- 算术运算符 ------------------------------------------------------------
62 // =========================================================================
63
65 static_cast<Vector3D &>(*this) += rhs;
66 return *this;
67 }
68
69 friend Location operator+(Location lhs, const Location &rhs) {
70 lhs += rhs;
71 return lhs;
72 }
73
75 static_cast<Vector3D &>(*this) -= rhs;
76 return *this;
77 }
78
79 friend Location operator-(Location lhs, const Location &rhs) {
80 lhs -= rhs;
81 return lhs;
82 }
83
84 // =========================================================================
85 // -- 比较运算符 ------------------------------------------------------------
86 // =========================================================================
87
88 // 等于
89 bool operator==(const Location &rhs) const {
90 return static_cast<const Vector3D &>(*this) == rhs;
91 }
92
93 // 不等于
94 bool operator!=(const Location &rhs) const {
95 return !(*this == rhs);
96 }
97
98 // =========================================================================
99 // -- 转换为 UE4 类型 -------------------------------------------------------
100 // =========================================================================
101
102#ifdef LIBCARLA_INCLUDED_FROM_UE4
103
104 Location(const FVector &vector) // 从厘米到米(乘以0.01)。
105 : Location(1e-2f * vector.X, 1e-2f * vector.Y, 1e-2f * vector.Z) {}
106
107 operator FVector() const {
108 return FVector{1e2f * x, 1e2f * y, 1e2f * z}; // 从米到厘米(乘以100)。
109 }
110
111#endif // LIBCARLA_INCLUDED_FROM_UE4
112 };
113
114} // namespace geom
115} // 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:80
static auto Distance(const Vector3D &a, const Vector3D &b)
Definition Math.h:90
CARLA模拟器的主命名空间。
Definition Carla.cpp:139