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__QUATERNION__OPERATOR_HPP_
16 #define GEOMETRY__QUATERNION__OPERATOR_HPP_
17 
19 #include <geometry_msgs/msg/quaternion.hpp>
20 
21 namespace math
22 {
23 namespace geometry
24 {
25 template <
26  typename T, typename U,
27  std::enable_if_t<std::conjunction_v<IsLikeQuaternion<T>, IsLikeQuaternion<U>>, std::nullptr_t> =
28  nullptr>
29 auto operator+(const T & a, const U & b)
30 {
31  auto v = T();
32  v.x = a.x + b.x;
33  v.y = a.y + b.y;
34  v.z = a.z + b.z;
35  v.w = a.w + b.w;
36  return v;
37 }
38 
39 template <
40  typename T, typename U,
41  std::enable_if_t<std::conjunction_v<IsLikeQuaternion<T>, IsLikeQuaternion<U>>, std::nullptr_t> =
42  nullptr>
43 auto operator-(const T & a, const U & b)
44 {
45  auto v = T();
46  v.x = a.x - b.x;
47  v.y = a.y - b.y;
48  v.z = a.z - b.z;
49  v.w = a.w - b.w;
50  return v;
51 }
52 
53 template <
54  typename T, typename U,
55  std::enable_if_t<std::conjunction_v<IsLikeQuaternion<T>, IsLikeQuaternion<U>>, std::nullptr_t> =
56  nullptr>
57 auto operator*(const T & a, const U & b)
58 {
59  auto v = T();
60  v.x = a.w * b.x - a.z * b.y + a.y * b.z + a.x * b.w;
61  v.y = a.z * b.x + a.w * b.y - a.x * b.z + a.y * b.w;
62  v.z = -a.y * b.x + a.x * b.y + a.w * b.z + a.z * b.w;
63  v.w = -a.x * b.x - a.y * b.y - a.z * b.z + a.w * b.w;
64  return v;
65 }
66 
67 template <
68  typename T, typename U,
69  std::enable_if_t<std::conjunction_v<IsLikeQuaternion<T>, IsLikeQuaternion<U>>, std::nullptr_t> =
70  nullptr>
71 auto operator+=(T & a, const U & b) -> decltype(auto)
72 {
73  a.x += b.x;
74  a.y += b.y;
75  a.z += b.z;
76  a.w += b.w;
77  return a;
78 }
79 } // namespace geometry
80 } // namespace math
81 
82 #endif // GEOMETRY__QUATERNION__OPERATOR_HPP_
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