scenario_simulator_v2 C++ API
operator.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GEOMETRY__VECTOR3__OPERATOR_HPP_
16 #define GEOMETRY__VECTOR3__OPERATOR_HPP_
17 
18 #include <Eigen/Dense>
20 #include <geometry_msgs/msg/point.hpp>
21 #include <geometry_msgs/msg/quaternion.hpp>
22 #include <geometry_msgs/msg/vector3.hpp>
23 
24 namespace math
25 {
26 namespace geometry
27 {
28 template <
29  typename T, std::enable_if_t<std::conjunction_v<IsLikeVector3<T>>, std::nullptr_t> = nullptr>
30 auto operator+(const T & v, const Eigen::Vector3d & eigen_v) -> T
31 {
32  T result;
33  result.x = v.x + eigen_v.x();
34  result.y = v.y + eigen_v.y();
35  result.z = v.z + eigen_v.z();
36  return result;
37 }
38 
39 template <
40  typename T, typename U,
41  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, IsLikeVector3<U>>, std::nullptr_t> =
42  nullptr>
43 auto operator+(const T & a, const U & b)
44 {
45  if constexpr (std::is_same_v<T, geometry_msgs::msg::Vector3>) {
47  v.x = a.x + b.x;
48  v.y = a.y + b.y;
49  v.z = a.z + b.z;
50  return v;
51  } else {
53  v.x = a.x + b.x;
54  v.y = a.y + b.y;
55  v.z = a.z + b.z;
56  return v;
57  }
58 }
59 
60 template <
61  typename T, typename U,
62  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, IsLikeVector3<U>>, std::nullptr_t> =
63  nullptr>
64 auto operator-(const T & a, const U & b)
65 {
66  if constexpr (std::is_same_v<T, geometry_msgs::msg::Vector3>) {
68  v.x = a.x - b.x;
69  v.y = a.y - b.y;
70  v.z = a.z - b.z;
71  return v;
72  } else {
74  v.x = a.x - b.x;
75  v.y = a.y - b.y;
76  v.z = a.z - b.z;
77  return v;
78  }
79 }
80 
81 template <
82  typename T, typename U,
83  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, std::is_scalar<U>>, std::nullptr_t> =
84  nullptr>
85 auto operator*(const T & a, const U & b)
86 {
87  if constexpr (std::is_same_v<T, geometry_msgs::msg::Vector3>) {
89  v.x = a.x * b;
90  v.y = a.y * b;
91  v.z = a.z * b;
92  return v;
93  } else {
95  v.x = a.x * b;
96  v.y = a.y * b;
97  v.z = a.z * b;
98  return v;
99  }
100 }
101 
102 template <
103  typename T, typename U,
104  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, std::is_scalar<U>>, std::nullptr_t> =
105  nullptr>
106 auto operator/(const T & a, const U & b)
107 {
108  if constexpr (std::is_same_v<T, geometry_msgs::msg::Vector3>) {
110  v.x = a.x / b;
111  v.y = a.y / b;
112  v.z = a.z / b;
113  return v;
114  } else {
116  v.x = a.x / b;
117  v.y = a.y / b;
118  v.z = a.z / b;
119  return v;
120  }
121 }
122 
123 template <
124  typename T, typename U,
125  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, IsLikeVector3<U>>, std::nullptr_t> =
126  nullptr>
127 auto operator+=(T & a, const U & b) -> decltype(auto)
128 {
129  a.x += b.x;
130  a.y += b.y;
131  a.z += b.z;
132  return a;
133 }
134 } // namespace geometry
135 } // namespace math
136 
137 #endif // GEOMETRY__VECTOR3__OPERATOR_HPP_
auto operator/(const T &a, const U &b)
Definition: operator.hpp:106
auto operator*(const T &a, const U &b)
Definition: operator.hpp:57
auto operator+=(T &a, const U &b) -> decltype(auto)
Definition: operator.hpp:71
auto operator-(const T &a, const U &b)
Definition: operator.hpp:43
auto operator+(const T &a, const U &b)
Definition: operator.hpp:29
Definition: bounding_box.hpp:32
geometry_msgs::msg::Point Point
Definition: lanelet_wrapper.hpp:64
geometry_msgs::msg::Vector3 Vector3
Definition: lanelet_wrapper.hpp:68