GCC Code Coverage Report


Directory: ./
File: include/multicontact-api/bindings/python/geometry/second-order-cone.hpp
Date: 2025-03-10 16:17:01
Exec Total Coverage
Lines: 28 32 87.5%
Branches: 31 68 45.6%

Line Branch Exec Source
1 // Copyright (c) 2015-2018, CNRS
2 // Authors: Justin Carpentier <jcarpent@laas.fr>
3
4 #ifndef __multicontact_api_python_geometry_second_order_cone_hpp__
5 #define __multicontact_api_python_geometry_second_order_cone_hpp__
6
7 #include <eigenpy/eigenpy.hpp>
8
9 #include "multicontact-api/bindings/python/serialization/archive.hpp"
10 #include "multicontact-api/geometry/second-order-cone.hpp"
11
12 namespace multicontact_api {
13 namespace python {
14
15 namespace bp = boost::python;
16
17 template <typename SOC>
18 struct SOCPythonVisitor
19 : public boost::python::def_visitor<SOCPythonVisitor<SOC> > {
20 typedef typename SOC::MatrixD MatrixD;
21 typedef typename SOC::VectorD VectorD;
22 typedef typename SOC::Scalar Scalar;
23
24 template <class PyClass>
25 12 void visit(PyClass &cl) const {
26
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 cl.def(bp::init<>("Default constructor."))
27
5/10
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 6 times.
✗ Branch 14 not taken.
24 .def(bp::init<MatrixD, VectorD>((bp::arg("Q"), bp::arg("direction"))))
28
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 .def("__str__", &toString)
29
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
24 .def("lhsValue", &SOC::lhsValue, bp::arg("vector"),
30 "Returns the lhs value of the conic inequality.")
31
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
24 .def("rhsValue", &SOC::rhsValue, bp::arg("vector"),
32 "Returns the rhs value of the conic inequality.")
33
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
24 .def("check", (bool(SOC::*)(const VectorD &) const) & SOC::check,
34
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
24 bp::arg("vector"),
35 "Checks if the vector given in argument belongs to the conic "
36 "constraint.")
37
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
24 .def("check",
38 (bool(SOC::*)(const VectorD &, const Scalar) const) & SOC::check,
39 bp::args("vector", "factor"),
40 "Checks if the vector given in argument belongs to the conic "
41 "constraint with a given reduction factor.")
42 24 .add_property("direction", &get_direction, &SOC::setDirection,
43 "Accessor to the direction property.")
44
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 .add_property("Q", &get_Q, &SOC::setQ, "Accessor to the Q property.")
45
3/6
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
24 .def("isApprox",
46 (bool(SOC::*)(const SOC &, const Scalar &) const) & SOC::isApprox,
47 bp::args("other", "prec"),
48 "Returns true if *this is approximately equal to other, within "
49 "the precision determined by prec.")
50
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 .def(bp::self == bp::self)
51
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 .def(bp::self != bp::self)
52
53
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
24 .def("RegularCone", &SOC::RegularCone, bp::args("mu", "direction"),
54 "Creates a regular cone from a given friction coefficient and a "
55 "direction.")
56
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 .staticmethod("RegularCone");
57 12 }
58
59 12 static void expose(const std::string &class_name) {
60
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 std::string doc = "SOC of dimension " + SOC::dim;
61
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 doc += " defined by its direction and its quadratic norm.";
62
1/2
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
12 bp::class_<SOC>(class_name.c_str(), doc.c_str(), bp::no_init)
63
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 .def(SOCPythonVisitor<SOC>())
64
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 .def(SerializableVisitor<SOC>());
65
66 // Expose related matrix types
67
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 ENABLE_SPECIFIC_MATRIX_TYPE(MatrixD);
68
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
12 ENABLE_SPECIFIC_MATRIX_TYPE(VectorD);
69 12 }
70
71 protected:
72 static std::string toString(const SOC &c) {
73 std::ostringstream s;
74 s << c;
75 return s.str();
76 }
77
78 2 static VectorD get_direction(const SOC &c) { return c.direction(); }
79 1 static MatrixD get_Q(const SOC &c) { return c.Q(); }
80 };
81
82 } // namespace python
83 } // namespace multicontact_api
84
85 #endif // ifnef __multicontact_api_python_geometry_second_order_cone_hpp__
86