CARLA
Loading...
Searching...
No Matches
geom/Location.h
Go to the documentation of this file.
1// Copyright (c) 2026 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
10#include "carla/geom/Vector3D.h"
12#include "carla/geom/Math.h"
13
14#ifdef LIBCARLA_INCLUDED_FROM_UE4
16#include "Math/Vector.h"
18#endif // LIBCARLA_INCLUDED_FROM_UE4
19
20namespace carla {
21namespace geom {
22
23 struct Location : Vector3D {
24
25 // =========================================================================
26 // -- Constructors ---------------------------------------------------------
27 // =========================================================================
28
29 Location() = default;
30
32
33 Location(Vector3D rhs) : Vector3D(rhs) {}
34
35 constexpr Location(Vector3DInt rhs) :
36 Vector3D(static_cast<float>(rhs.x),
37 static_cast<float>(rhs.y),
38 static_cast<float>(rhs.z)) {
39 }
40
41 // =========================================================================
42 // -- Other methods --------------------------------------------------------
43 // =========================================================================
44
45 constexpr auto DistanceSquared(Location loc) const {
46 return Math::DistanceSquared(*this, loc);
47 }
48
49 inline auto Distance(Location loc) const {
50 return Math::Distance(*this, loc);
51 }
52
53 // =========================================================================
54 // -- Right-handed (ROS / FLU) boundary ------------------------------------
55 // =========================================================================
56
57 /// This location expressed in a right-handed, x-forward / y-**left** /
58 /// z-up frame (ROS REP-103 "FLU"): `(x, -y, z)`.
60 return RightHandedVector3D(*this);
61 }
62
63 /// Inverse of `ToRightHanded()`. Mirroring Y is an involution, so this is
64 /// the same `(x, -y, z)` map read the other way.
65 static constexpr Location FromRightHanded(const RightHandedVector3D &rhs) {
66 return Location(rhs.x, -rhs.y, rhs.z);
67 }
68
69 // =========================================================================
70 // -- Arithmetic operators -------------------------------------------------
71 // =========================================================================
72
73 constexpr Location &operator+=(Location rhs) {
74 static_cast<Vector3D &>(*this) += rhs;
75 return *this;
76 }
77
78 constexpr friend Location operator+(Location lhs, Location rhs) {
79 lhs += rhs;
80 return lhs;
81 }
82
83 constexpr Location &operator-=(Location rhs) {
84 static_cast<Vector3D &>(*this) -= rhs;
85 return *this;
86 }
87
88 constexpr friend Location operator-(Location lhs, Location rhs) {
89 lhs -= rhs;
90 return lhs;
91 }
92
93 // =========================================================================
94 // -- Conversions to UE4 types ---------------------------------------------
95 // =========================================================================
96
97#ifdef LIBCARLA_INCLUDED_FROM_UE4
98
99 Location(const FVector &vector) // from centimeters to meters.
100 : Location(1e-2f * vector.X, 1e-2f * vector.Y, 1e-2f * vector.Z) {}
101
102 operator FVector() const {
103 return FVector{1e2f * x, 1e2f * y, 1e2f * z}; // from meters to centimeters.
104 }
105
106#endif // LIBCARLA_INCLUDED_FROM_UE4
107 };
108
109 // =========================================================================
110 // -- Comparison operators -------------------------------------------------
111 // =========================================================================
112
113 constexpr bool operator==(Location lhs, Location rhs) {
114 return static_cast<Vector3D>(lhs) == static_cast<Vector3D>(rhs);
115 }
116
117 constexpr bool operator!=(Location lhs, Location rhs) {
118 return !(lhs == rhs);
119 }
120
121} // namespace geom
122} // namespace carla
static constexpr 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
constexpr bool operator!=(Location lhs, Location rhs)
constexpr bool operator==(Location lhs, Location rhs)
This file contains definitions of common data structures used in traffic manager.
constexpr Location & operator+=(Location rhs)
constexpr RightHandedVector3D ToRightHanded() const
This location expressed in a right-handed, x-forward / y-**left** / z-up frame (ROS REP-103 "FLU"): (...
Location(Vector3D rhs)
constexpr friend Location operator-(Location lhs, Location rhs)
constexpr friend Location operator+(Location lhs, Location rhs)
constexpr Location & operator-=(Location rhs)
constexpr auto DistanceSquared(Location loc) const
auto Distance(Location loc) const
constexpr Location(Vector3DInt rhs)
Location(const FVector &vector)
static constexpr Location FromRightHanded(const RightHandedVector3D &rhs)
Inverse of ToRightHanded().
Internal adapter that holds a Vector3D in a right-handed coordinate frame.