Skip to content

Commit 9e4b792

Browse files
authored
Merge pull request #271 from jcarpent/devel
Fix memory issue with Quaternion::normalized
2 parents 6338510 + c17d870 commit 9e4b792

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

include/eigenpy/quaternion.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,19 @@ namespace eigenpy
185185
"Returns the quaternion describing the inverse rotation.")
186186
.def("setIdentity",&Quaternion::setIdentity,
187187
bp::arg("self"),
188-
"Set *this to the idendity rotation.",bp::return_self<>())
188+
"Set *this to the identity rotation.",
189+
bp::return_self<>())
189190
.def("norm",&Quaternion::norm,
190191
bp::arg("self"),
191192
"Returns the norm of the quaternion's coefficients.")
192193
.def("normalize",&Quaternion::normalize,
193194
bp::arg("self"),
194-
"Normalizes the quaternion *this.")
195-
.def("normalized",&Quaternion::normalized,
195+
"Normalizes the quaternion *this.",
196+
bp::return_self<>())
197+
.def("normalized",&normalized,
196198
bp::arg("self"),
197-
"Returns a normalized copy of *this.")
199+
"Returns a normalized copy of *this.",
200+
bp::return_value_policy<bp::manage_new_object>())
198201
.def("squaredNorm",&Quaternion::squaredNorm,
199202
bp::arg("self"),
200203
"Returns the squared norm of the quaternion's coefficients.")
@@ -251,6 +254,11 @@ namespace eigenpy
251254
;
252255
}
253256
private:
257+
258+
static Quaternion * normalized(const Quaternion & self)
259+
{
260+
return new Quaternion(self.normalized());
261+
}
254262

255263
template<int i>
256264
static void setCoeff(Quaternion & self, Scalar value) { self.coeffs()[i] = value; }

src/quaternion.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/*
22
* Copyright 2014-2019, CNRS
3-
* Copyright 2018-2019, INRIA
3+
* Copyright 2018-2022, INRIA
44
*/
55

66
#include "eigenpy/memory.hpp"
77
#include "eigenpy/geometry.hpp"
8-
#include "eigenpy/quaternion.hpp"
8+
9+
#include <Eigen/Geometry>
910

1011
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(Eigen::Quaterniond)
1112

13+
#include "eigenpy/quaternion.hpp"
14+
1215
namespace eigenpy
1316
{
1417
void exposeQuaternion()

0 commit comments

Comments
 (0)