Commit cf608808 authored by jcarpent's avatar jcarpent
Browse files

[Spatial] Add default operator{*,/} for Force and Motion classes

parent 46050c85
......@@ -86,6 +86,10 @@ namespace se3
.def(bp::self == bp::self)
.def(bp::self != bp::self)
.def(bp::self * Scalar())
.def(Scalar() * bp::self)
.def(bp::self / Scalar())
.def("isApprox",(bool (Force::*)(const Force & other, const Scalar & prec) const) &Force::isApprox,bp::args("other","prec"),"Returns true if *this is approximately equal to other, within the precision given by prec.")
.def("isApprox",isApprox,bp::args("other"),"Returns true if *this is approximately equal to other.")
......
......@@ -100,6 +100,10 @@ namespace se3
.def(bp::self == bp::self)
.def(bp::self != bp::self)
.def(bp::self * Scalar())
.def(Scalar() * bp::self)
.def(bp::self / Scalar())
.def("isApprox",(bool (Motion::*)(const Motion & other, const Scalar & prec) const) &Motion::isApprox,bp::args("other","prec"),"Returns true if *this is approximately equal to other, within the precision given by prec.")
.def("isApprox",isApprox,bp::args("other"),"Returns true if *this is approximately equal to other.")
......
......@@ -135,9 +135,15 @@ namespace se3
*/
Derived operator+(const Derived & phi) const { return derived().__plus__(phi); }
/** \return an expression of *this scaled by the double factor a
/** \return an expression of *this scaled by the factor alpha
*/
Derived operator*(const Scalar alpha) const { return derived().__mult__(alpha); }
template<typename OtherScalar>
ForcePlain operator*(const OtherScalar & alpha) const { return derived().__mult__(alpha); }
/** \return an expression of *this divided by the factor alpha
*/
template<typename OtherScalar>
ForcePlain operator/(const OtherScalar & alpha) const { return derived().__div__(alpha); }
/** \return an expression of the opposite of *this
*/
......
......@@ -91,8 +91,7 @@ namespace se3
template<typename M1>
Derived & operator-=(const ForceDense<M1> & v) { return derived().__mequ__(v.derived()); }
ForcePlain operator*(const Scalar alpha) const { return derived().__mult__(alpha); }
ForcePlain __minus__() const { return ForcePlain(-linear(),-angular()); }
template<typename M1>
......@@ -111,10 +110,14 @@ namespace se3
Derived & __mequ__(const ForceDense<M1> & v)
{ linear() -= v.linear(); angular() -= v.angular(); return derived(); }
template<typename S1>
ForcePlain __mult__(const S1 alpha) const
template<typename OtherScalar>
ForcePlain __mult__(const OtherScalar & alpha) const
{ return ForcePlain(alpha*linear(),alpha*angular()); }
template<typename OtherScalar>
ForcePlain __div__(const OtherScalar & alpha) const
{ return derived().__mult__((OtherScalar)(1)/alpha); }
template<typename F1>
Scalar dot(const MotionDense<F1> & phi) const
{ return phi.linear().dot(linear()) + phi.angular().dot(angular()); }
......
......@@ -59,7 +59,11 @@ namespace se3
MotionPlain operator-(const Derived & v) const { return derived().__minus__(v); }
Derived & operator+=(const Derived & v) { return derived().__pequ__(v); }
Derived & operator-=(const Derived & v) { return derived().__mequ__(v); }
MotionPlain operator*(const Scalar alpha) const { return derived().__mult__(alpha); }
template<typename OtherScalar>
MotionPlain operator*(const OtherScalar & alpha) const { return derived().__mult__(alpha); }
template<typename OtherScalar>
MotionPlain operator/(const OtherScalar & alpha) const { return derived().__div__(alpha); }
template<typename D>
typename internal::MotionAlgebraAction<D>::ReturnType cross(const D & d) const
......
......@@ -111,8 +111,7 @@ namespace se3
template<typename M1>
Derived & operator-=(const MotionDense<M1> & v) { return derived().__mequ__(v.derived()); }
MotionPlain operator*(const Scalar alpha) const { return derived().__mult__(alpha); }
MotionPlain __minus__() const { return MotionPlain(-linear(),-angular()); }
template<typename M1>
......@@ -131,10 +130,14 @@ namespace se3
Derived & __mequ__(const MotionDense<M1> & v)
{ linear() -= v.linear(); angular() -= v.angular(); return derived(); }
template<typename S1>
MotionPlain __mult__(const S1 alpha) const
template<typename OtherScalar>
MotionPlain __mult__(const OtherScalar & alpha) const
{ return MotionPlain(alpha*linear(),alpha*angular()); }
template<typename OtherScalar>
MotionPlain __div__(const OtherScalar & alpha) const
{ return derived().__mult__((OtherScalar)(1)/alpha); }
template<typename F1>
Scalar dot(const ForceBase<F1> & phi) const
{ return phi.linear().dot(linear()) + phi.angular().dot(angular()); }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment