Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
e-kwsm committed Jul 14, 2023
1 parent f495cc6 commit 9d62150
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions src/math/vector3.cpp
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 @@ -222,32 +221,25 @@ namespace OpenBabel
OBAPI double CalcTorsionAngle(const vector3 &a, const vector3 &b,
const vector3 &c, const vector3 &d)
{

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

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

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

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 9d62150

Please sign in to comment.