Skip to content

Commit

Permalink
Perform OB_OLD_MATH_CHECKS when NDEBUG is not defined
Browse files Browse the repository at this point in the history
and minor clean-up
  • Loading branch information
e-kwsm committed Nov 24, 2019
1 parent 6af03f1 commit d5680c2
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions src/math/vector3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,19 @@ namespace OpenBabel
*/
double vector3::operator[] ( unsigned int i) const
{
#ifdef OB_OLD_MATH_CHECKS
if (i > 2)
{
cerr << "ERROR in OpenBabel::vector3::operator[]" << endl
<< "The method has been called with an illegal index i=" << i << "." << endl
switch (i) {
case 0u:
return _vx;
case 1u:
return _vy;
case 2u:
return _vz;
default:
cerr << "ERROR in OpenBabel::vector3::operator[]\n"
<< "The method has been called with an illegal index i=" << i << ".\n"
<< "Please contact the author of the offending program immediately." << endl;
return 0.0;
}
#endif
if (i == 0)
return _vx;
if (i == 1)
return _vy;
else return _vz;
}
}

/*! Replaces *this with a random unit vector, which is (supposed
Expand Down Expand Up @@ -218,32 +217,25 @@ namespace OpenBabel
OBAPI double CalcTorsionAngle(const vector3 &a, const vector3 &b,
const vector3 &c, const vector3 &d)
{
vector3 b1 = a - b;
vector3 b2 = b - c;
vector3 b3 = c - d;

double torsion;
vector3 b1,b2,b3,c1,c2,c3;

b1 = a - b;
b2 = b - c;
b3 = c - d;

#ifdef OB_OLD_MATH_CHECKS
c1 = cross(b1,b2);
c2 = cross(b2,b3);
c3 = cross(c1,c2);

#if defined(OB_OLD_MATH_CHECKS) || !defined(NDEBUG)
vector3 c1 = cross(b1, b2);
vector3 c2 = cross(b2, b3);

if (c1.length() * c2.length() < 0.001)
{
torsion = 0.0;
return torsion;
return 0.0;
}
#endif

double rb2 = sqrt(dot(b2, b2));

vector3 b2xb3 = cross(b2, b3);
vector3 b1xb2 = cross(b1, b2);
torsion = - atan2(dot(rb2 * b1, b2xb3), dot(b1xb2, b2xb3));
double torsion = - atan2(dot(rb2 * b1, b2xb3), dot(b1xb2, b2xb3));

return(torsion * RAD_TO_DEG);
}
Expand Down

0 comments on commit d5680c2

Please sign in to comment.