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 
19 #include <geometry_msgs/msg/point.hpp>
20 #include <geometry_msgs/msg/quaternion.hpp>
21 #include <geometry_msgs/msg/vector3.hpp>
22 
23 namespace math
24 {
25 namespace geometry
26 {
27 template <
28  typename T, typename U,
29  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, IsLikeVector3<U>>, std::nullptr_t> =
30  nullptr>
31 auto operator+(const T & a, const U & b)
32 {
33  if constexpr (std::is_same_v<T, geometry_msgs::msg::Vector3>) {
34  geometry_msgs::msg::Vector3 v;
35  v.x = a.x + b.x;
36  v.y = a.y + b.y;
37  v.z = a.z + b.z;
38  return v;
39  } else {
40  geometry_msgs::msg::Point v;
41  v.x = a.x + b.x;
42  v.y = a.y + b.y;
43  v.z = a.z + b.z;
44  return v;
45  }
46 }
47 
48 template <
49  typename T, typename U,
50  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, IsLikeVector3<U>>, std::nullptr_t> =
51  nullptr>
52 auto operator-(const T & a, const U & b)
53 {
54  if constexpr (std::is_same_v<T, geometry_msgs::msg::Vector3>) {
55  geometry_msgs::msg::Vector3 v;
56  v.x = a.x - b.x;
57  v.y = a.y - b.y;
58  v.z = a.z - b.z;
59  return v;
60  } else {
61  geometry_msgs::msg::Point v;
62  v.x = a.x - b.x;
63  v.y = a.y - b.y;
64  v.z = a.z - b.z;
65  return v;
66  }
67 }
68 
69 template <
70  typename T, typename U,
71  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, std::is_scalar<U>>, std::nullptr_t> =
72  nullptr>
73 auto operator*(const T & a, const U & b)
74 {
75  if constexpr (std::is_same_v<T, geometry_msgs::msg::Vector3>) {
76  geometry_msgs::msg::Vector3 v;
77  v.x = a.x * b;
78  v.y = a.y * b;
79  v.z = a.z * b;
80  return v;
81  } else {
82  geometry_msgs::msg::Point v;
83  v.x = a.x * b;
84  v.y = a.y * b;
85  v.z = a.z * b;
86  return v;
87  }
88 }
89 
90 template <
91  typename T, typename U,
92  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, std::is_scalar<U>>, std::nullptr_t> =
93  nullptr>
94 auto operator/(const T & a, const U & b)
95 {
96  if constexpr (std::is_same_v<T, geometry_msgs::msg::Vector3>) {
97  geometry_msgs::msg::Vector3 v;
98  v.x = a.x / b;
99  v.y = a.y / b;
100  v.z = a.z / b;
101  return v;
102  } else {
103  geometry_msgs::msg::Point v;
104  v.x = a.x / b;
105  v.y = a.y / b;
106  v.z = a.z / b;
107  return v;
108  }
109 }
110 
111 template <
112  typename T, typename U,
113  std::enable_if_t<std::conjunction_v<IsLikeVector3<T>, IsLikeVector3<U>>, std::nullptr_t> =
114  nullptr>
115 auto operator+=(T & a, const U & b) -> decltype(auto)
116 {
117  a.x += b.x;
118  a.y += b.y;
119  a.z += b.z;
120  return a;
121 }
122 } // namespace geometry
123 } // namespace math
124 
125 #endif // GEOMETRY__VECTOR3__OPERATOR_HPP_
auto operator/(const T &a, const U &b)
Definition: operator.hpp:94
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