Skip to content

Commit

Permalink
python: expose missing Transform3s::Random
Browse files Browse the repository at this point in the history
  • Loading branch information
lmontaut committed Sep 16, 2024
1 parent 7b2e7b3 commit 3e481af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 7 additions & 5 deletions include/coal/math/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ class COAL_DLLAPI Transform3s {
}

/// @brief return a random transform
static Transform3s Random() { return Transform3s().setRandom(); }
static Transform3s Random() {
Transform3s tf = Transform3s();
tf.setRandom();
return tf;
}

/// @brief set the transform to a random transform
Transform3s& setRandom();
inline void setRandom();

bool operator==(const Transform3s& other) const {
return (R == other.getRotation()) && (T == other.getTranslation());
Expand Down Expand Up @@ -247,12 +251,10 @@ inline Quatf uniformRandomQuaternion() {
return q;
}

inline Transform3s& Transform3s::setRandom() {
inline void Transform3s::setRandom() {
const Quatf q = uniformRandomQuaternion();
this->rotation() = q.matrix();
this->translation().setRandom();

return *this;
}

/// @brief Construct othonormal basis from vector.
Expand Down
4 changes: 4 additions & 0 deletions python/math.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ void exposeMaths() {
.def(dv::member_func("Identity", &Transform3s::Identity))
.staticmethod("Identity")

.def(dv::member_func("setRandom", &Transform3s::setRandom))
.def(dv::member_func("Random", &Transform3s::Random))
.staticmethod("Random")

.def(dv::member_func("transform", &Transform3s::transform<Vec3s>))
.def("inverseInPlace", &Transform3s::inverseInPlace,
return_internal_reference<>(),
Expand Down

0 comments on commit 3e481af

Please sign in to comment.