GCC Code Coverage Report


Directory: ./
File: include/hpp/pinocchio/liegroup/vector-space.hh
Date: 2025-05-04 12:09:19
Exec Total Coverage
Lines: 6 7 85.7%
Branches: 1 14 7.1%

Line Branch Exec Source
1 // Copyright (c) 2017, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28
29 #ifndef HPP_PINOCCHIO_LIEGROUP_VECTOR_SPACE_OPERATION_HH
30 #define HPP_PINOCCHIO_LIEGROUP_VECTOR_SPACE_OPERATION_HH
31
32 #include <hpp/pinocchio/fwd.hh>
33 #include <hpp/util/exception-factory.hh>
34 #include <pinocchio/multibody/liegroup/vector-space.hpp>
35
36 namespace hpp {
37 namespace pinocchio {
38 namespace liegroup {
39 /// \cond
40 namespace details {
41 template <bool Test>
42 struct assign_if {
43 template <class D1, class D2>
44 static void run(const Eigen::MatrixBase<D1>& /*Jin*/,
45 const Eigen::MatrixBase<D2>& /*Jout*/) {}
46 };
47 template <>
48 struct assign_if<true> {
49 template <class D1, class D2>
50 static void run(const Eigen::MatrixBase<D1>& Jin,
51 const Eigen::MatrixBase<D2>& Jout) {
52 const_cast<Eigen::MatrixBase<D2>&>(Jout) = Jin;
53 }
54 };
55 } // namespace details
56 /// \endcond
57
58 template <int Size, bool rot>
59 struct VectorSpaceOperation
60 : public ::pinocchio::VectorSpaceOperationTpl<Size, value_type> {
61 typedef ::pinocchio::VectorSpaceOperationTpl<Size, value_type> Base;
62 enum { BoundSize = Size, NR = (rot ? Size : 0), NT = (rot ? 0 : Size) };
63
64 /// Constructor
65 /// \param size size of the vector space: should be the equal to
66 /// template argument for static sized vector-spaces.
67 2321687 VectorSpaceOperation(int size = std::max(0, Size)) : Base(size) {}
68
69 template <class ConfigL_t, class ConfigR_t>
70 double squaredDistance(const Eigen::MatrixBase<ConfigL_t>& q0,
71 const Eigen::MatrixBase<ConfigR_t>& q1) {
72 return Base::squaredDistance(q0, q1);
73 }
74
75 template <class ConfigL_t, class ConfigR_t>
76 double squaredDistance(const Eigen::MatrixBase<ConfigL_t>& q0,
77 const Eigen::MatrixBase<ConfigR_t>& q1,
78 const typename ConfigL_t::Scalar& w) {
79 if (rot)
80 return w * squaredDistance(q0, q1);
81 else
82 return squaredDistance(q0, q1);
83 }
84
85 template <class ConfigIn_t, class ConfigOut_t>
86 120 static void setBound(const Eigen::MatrixBase<ConfigIn_t>& bounds,
87 const Eigen::MatrixBase<ConfigOut_t>& out) {
88
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 60 times.
120 if (bounds.size() != BoundSize) {
89 HPP_THROW(std::invalid_argument, "Expected vector of size "
90 << (int)BoundSize << ", got size "
91 << bounds.size());
92 }
93 120 const_cast<Eigen::MatrixBase<ConfigOut_t>&>(out) = bounds;
94 }
95
96 template <class JacobianIn_t, class JacobianOut_t>
97 static void getRotationSubJacobian(
98 const Eigen::MatrixBase<JacobianIn_t>& Jin,
99 const Eigen::MatrixBase<JacobianOut_t>& Jout) {
100 details::assign_if<rot>::run(Jin, Jout);
101 }
102
103 template <class ConfigIn_t>
104 787060 static bool isNormalized(const Eigen::MatrixBase<ConfigIn_t>&,
105 const value_type&) {
106 787060 return true;
107 }
108 };
109 } // namespace liegroup
110 } // namespace pinocchio
111 } // namespace hpp
112
113 namespace pinocchio {
114 template <int Size, bool rot>
115 struct traits<hpp::pinocchio::liegroup::VectorSpaceOperation<Size, rot> >
116 : public traits<typename hpp::pinocchio::liegroup::VectorSpaceOperation<
117 Size, rot>::Base> {};
118 } // namespace pinocchio
119
120 #endif // HPP_PINOCCHIO_LIEGROUP_VECTOR_SPACE_OPERATION_HH
121