GCC Code Coverage Report


Directory: ./
File: include/multicontact-api/bindings/python/scenario/contact-patch.hpp
Date: 2025-03-10 16:17:01
Exec Total Coverage
Lines: 32 32 100.0%
Branches: 26 52 50.0%

Line Branch Exec Source
1 // Copyright (c) 2015-2018, CNRS
2 // Authors: Justin Carpentier <jcarpent@laas.fr>
3
4 #ifndef __multicontact_api_python_scenario_contact_patch_hpp__
5 #define __multicontact_api_python_scenario_contact_patch_hpp__
6
7 #include <string>
8
9 #include "multicontact-api/bindings/python/serialization/archive.hpp"
10 #include "multicontact-api/bindings/python/utils/printable.hpp"
11 #include "multicontact-api/scenario/contact-patch.hpp"
12
13 namespace multicontact_api {
14 namespace python {
15
16 namespace bp = boost::python;
17
18 template <typename ContactPatch>
19 struct ContactPatchPythonVisitor
20 : public boost::python::def_visitor<
21 ContactPatchPythonVisitor<ContactPatch> > {
22 typedef typename ContactPatch::Scalar Scalar;
23 typedef typename ContactPatch::SE3 SE3;
24 typedef typename ContactPatch::ContactModel ContactModel;
25
26 template <class PyClass>
27 3 void visit(PyClass& cl) const {
28
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
3 cl.def(bp::init<>(bp::arg(""), "Default constructor."))
29
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def(
30
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
6 bp::init<SE3>(bp::arg("placement"), "Init with a given placement."))
31
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
6 .def(bp::init<SE3, Scalar>(
32 bp::args("placement", "friction"),
33 "Init with a given placement and friction coefficient."))
34
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
6 .def(bp::init<SE3, ContactModel>(
35 bp::args("placement", "contact_model"),
36 "Init with a given placement and contact model."))
37
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
6 .def(bp::init<ContactPatch>(bp::arg("other"), "Copy contructor."))
38
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 .add_property(
39 "placement",
40 // getter require to use "make_function" to pass the
41 // return_internal_reference policy (return ref to custom object)
42 3 bp::make_function(&getPlacement, bp::return_internal_reference<>()),
43 &setPlacement,
44 "Placement of the patch represented as a pinocchio SE3 object.")
45
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .add_property("friction", &getFriction, &setFriction,
46 "Friction coefficient between the robot and the "
47 "environment for this contact.")
48
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def_readwrite("contact_model", &ContactPatch::m_contact_model,
49 "The contact model defining this contact.")
50
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 .def(bp::self == bp::self)
51
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
6 .def(bp::self != bp::self)
52
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def("copy", &copy, "Returns a copy of *this.");
53 3 }
54
55 3 static void expose(const std::string& class_name) {
56
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::string doc = "Contact Patch";
57
1/2
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
3 bp::class_<ContactPatch>(class_name.c_str(), doc.c_str(), bp::no_init)
58
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def(ContactPatchPythonVisitor<ContactPatch>())
59
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def(SerializableVisitor<ContactPatch>())
60
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 .def(PrintableVisitor<ContactPatch>());
61 3 }
62
63 protected:
64 // define setter and getter
65 18 static SE3& getPlacement(ContactPatch& self) { return self.placement(); }
66 1 static void setPlacement(ContactPatch& self, const SE3& placement) {
67 1 self.placement() = placement;
68 1 }
69 8 static Scalar getFriction(ContactPatch& self) { return self.friction(); }
70 7 static void setFriction(ContactPatch& self, const Scalar& friction) {
71 7 self.friction() = friction;
72 7 }
73 1 static ContactPatch copy(const ContactPatch& self) {
74 1 return ContactPatch(self);
75 }
76 };
77 } // namespace python
78 } // namespace multicontact_api
79
80 #endif // ifndef __multicontact_api_python_scenario_contact_patch_hpp__
81