Skip to content

Commit

Permalink
(kdl) add eps argument to Norm functions
Browse files Browse the repository at this point in the history
eps is used to determine when to set norm to zero
  • Loading branch information
MatthijsBurgh committed May 4, 2020
1 parent f23632f commit a6fbd38
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion orocos_kdl/src/frameacc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class VectorAcc
IMETHOD VectorAcc& operator -= (const VectorAcc& arg);
IMETHOD static VectorAcc Zero();
IMETHOD void ReverseSign();
IMETHOD doubleAcc Norm();
IMETHOD doubleAcc Norm(double eps=epsilon);
IMETHOD friend VectorAcc operator + (const VectorAcc& r1,const VectorAcc& r2);
IMETHOD friend VectorAcc operator - (const VectorAcc& r1,const VectorAcc& r2);
IMETHOD friend VectorAcc operator + (const Vector& r1,const VectorAcc& r2);
Expand Down
4 changes: 2 additions & 2 deletions orocos_kdl/src/frameacc.inl
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ void VectorAcc::ReverseSign() {
dv.ReverseSign();
}

doubleAcc VectorAcc::Norm() {
doubleAcc VectorAcc::Norm(double eps) {
doubleAcc res;
res.t = p.Norm();
res.t = p.Norm(eps);
res.d = dot(p,v)/res.t;
res.dd = (dot(p,dv)+dot(v,v)-res.d*res.d)/res.t;
return res;
Expand Down
10 changes: 5 additions & 5 deletions orocos_kdl/src/frames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ namespace KDL {
);
}

double Vector2::Norm() const
double Vector2::Norm(double eps) const
{
double tmp1 = fabs(data[0]);
double tmp2 = fabs(data[1]);

if (tmp1 == 0.0 && tmp2 == 0.0)
return 0.0;
if (tmp1 < eps && tmp2 < eps)
return 0;

if (tmp1 > tmp2) {
return tmp1*sqrt(1+sqr(data[1]/data[0]));
Expand All @@ -115,7 +115,7 @@ namespace KDL {


// do some effort not to lose precision
double Vector::Norm() const
double Vector::Norm(double eps) const
{
double tmp1;
double tmp2;
Expand All @@ -124,7 +124,7 @@ namespace KDL {
if (tmp1 >= tmp2) {
tmp2=fabs(data[2]);
if (tmp1 >= tmp2) {
if (tmp1 == 0) {
if (tmp1 < eps) {
// only to everything exactly zero case, all other are handled correctly
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions orocos_kdl/src/frames.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Vector
double Normalize(double eps=epsilon);

//! @return the norm of the vector
double Norm() const;
double Norm(double eps=epsilon) const;



Expand Down Expand Up @@ -1015,7 +1015,7 @@ class Vector2
double Normalize(double eps=epsilon);

//! @return the norm of the vector
double Norm() const;
double Norm(double eps=epsilon) const;

//! projects v in its XY plane, and sets *this to these values
inline void Set3DXY(const Vector& v);
Expand Down
2 changes: 1 addition & 1 deletion orocos_kdl/src/framevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class VectorVel
IMETHOD VectorVel& operator -= (const VectorVel& arg);
IMETHOD static VectorVel Zero();
IMETHOD void ReverseSign();
IMETHOD doubleVel Norm() const;
IMETHOD doubleVel Norm(double eps=epsilon) const;
IMETHOD friend VectorVel operator + (const VectorVel& r1,const VectorVel& r2);
IMETHOD friend VectorVel operator - (const VectorVel& r1,const VectorVel& r2);
IMETHOD friend VectorVel operator + (const Vector& r1,const VectorVel& r2);
Expand Down
5 changes: 3 additions & 2 deletions orocos_kdl/src/framevel.inl
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,10 @@ void VectorVel::ReverseSign() {
p.ReverseSign();
v.ReverseSign();
}
doubleVel VectorVel::Norm() const {
doubleVel VectorVel::Norm(double eps) const {
double n = p.Norm();
return doubleVel(n,n ? dot(p,v)/n : 0); // Setting norm of p to 0 in case norm of v is 0
return doubleVel((n < eps) ? 0 : n,
(n < eps) ? 0 : dot(p,v)/n); // Setting norm of p to 0 in case norm of v is 0
}

bool Equal(const VectorVel& r1,const VectorVel& r2,double eps) {
Expand Down

1 comment on commit a6fbd38

@jbohren-hbr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this change breaks ABI compatibility with v1.4.0 as KDL::Vector::Norm() is no longer defined.

Please sign in to comment.