Skip to content

Commit e1503ef

Browse files
committed
core: Allow to use SE3Tpl::isApprox with custom scalar
1 parent ce05895 commit e1503ef

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

include/pinocchio/algorithm/constraints/cone-base.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef __pinocchio_algorithm_constraints_cone_base_hpp__
66
#define __pinocchio_algorithm_constraints_cone_base_hpp__
77

8+
#include "pinocchio/math/matrix.hpp"
9+
810
#include "pinocchio/algorithm/constraints/fwd.hpp"
911
#include "pinocchio/algorithm/constraints/set-base.hpp"
1012

@@ -37,7 +39,7 @@ namespace pinocchio
3739
{
3840
assert(x.size() == scale.size() && " x and scale should have the same size.");
3941
assert(
40-
scale.isApprox(scale(0) * VectorLikeIn2::Ones(scale.size()))
42+
pinocchio::isApprox(scale, scale(0) * VectorLikeIn2::Ones(scale.size()))
4143
&& "Only scalar scaling are supported.");
4244
PINOCCHIO_UNUSED_VARIABLE(scale); // the cone is preserved when scaled by a scalar
4345
return project(x, x_proj);

include/pinocchio/math/matrix.hpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,63 @@ namespace pinocchio
542542
internal::arrayMinAlgo<M, Res>::run(x, min, res);
543543
}
544544

545+
namespace internal
546+
{
547+
template<
548+
typename MatrixLike1,
549+
typename MatrixLike2,
550+
bool value = is_floating_point<typename MatrixLike1::Scalar>::value
551+
&& is_floating_point<typename MatrixLike2::Scalar>::value>
552+
struct isApproxAlgo
553+
{
554+
typedef typename MatrixLike1::RealScalar RealScalar;
555+
556+
static bool run(
557+
const Eigen::MatrixBase<MatrixLike1> & m1,
558+
const Eigen::MatrixBase<MatrixLike2> & m2,
559+
const RealScalar & prec = Eigen::NumTraits<RealScalar>::dummy_precision())
560+
{
561+
return m1.isApprox(m2, prec);
562+
}
563+
};
564+
565+
template<typename MatrixLike1, typename MatrixLike2>
566+
struct isApproxAlgo<MatrixLike1, MatrixLike2, false>
567+
{
568+
typedef typename MatrixLike1::RealScalar RealScalar;
569+
570+
static bool run(
571+
const Eigen::MatrixBase<MatrixLike1> & m1,
572+
const Eigen::MatrixBase<MatrixLike2> & m2,
573+
const RealScalar & prec = Eigen::NumTraits<RealScalar>::dummy_precision())
574+
{
575+
PINOCCHIO_UNUSED_VARIABLE(m1);
576+
PINOCCHIO_UNUSED_VARIABLE(m2);
577+
PINOCCHIO_UNUSED_VARIABLE(prec);
578+
return true;
579+
}
580+
};
581+
} // namespace internal
582+
583+
///
584+
/// \brief Check whether two matrix are approximately the same
585+
///
586+
/// \param[in] m1 Input matrix
587+
/// \param[in] m2 Input matrix
588+
/// \param[in] prec Required precision
589+
///
590+
/// \returns true if m1 and m2 are approximately the same given precision prec.
591+
///
592+
template<typename MatrixLike1, typename MatrixLike2>
593+
inline bool isApprox(
594+
const Eigen::MatrixBase<MatrixLike1> & m1,
595+
const Eigen::MatrixBase<MatrixLike2> & m2,
596+
const typename MatrixLike1::RealScalar & prec =
597+
Eigen::NumTraits<typename MatrixLike1::Scalar>::dummy_precision())
598+
{
599+
return internal::isApproxAlgo<MatrixLike1, MatrixLike2>::run(m1, m2, prec);
600+
}
601+
545602
template<typename XprType, typename DestType>
546603
inline void evalTo(const XprType & xpr, DestType & dest)
547604
{

include/pinocchio/spatial/se3-tpl.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "pinocchio/spatial/se3-base.hpp"
1111

1212
#include "pinocchio/math/quaternion.hpp"
13+
#include "pinocchio/math/matrix.hpp"
1314
#include "pinocchio/math/rotation.hpp"
1415
#include "pinocchio/spatial/cartesian-axis.hpp"
1516

@@ -332,8 +333,8 @@ namespace pinocchio
332333
const SE3Tpl<Scalar, O2> & m2,
333334
const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision()) const
334335
{
335-
return rotation().isApprox(m2.rotation(), prec)
336-
&& translation().isApprox(m2.translation(), prec);
336+
return pinocchio::isApprox(rotation(), m2.rotation(), prec)
337+
&& pinocchio::isApprox(translation(), m2.translation(), prec);
337338
}
338339

339340
bool isIdentity(const Scalar & prec = Eigen::NumTraits<Scalar>::dummy_precision()) const

0 commit comments

Comments
 (0)