Skip to content

Commit

Permalink
Fix #522: float-guard the identity matrix test
Browse files Browse the repository at this point in the history
Provide floating-point error margins in testing whether or not a matrix
is the identity matrix. This is done on a component by component basis.
Previously, matrix components were compared with exactly '0' and '1', so
the test could fail on account of roundoff errors on the components.
  • Loading branch information
jw3126 authored and ftessier committed Jan 15, 2020
1 parent 300a37a commit 011c307
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions HEN_HOUSE/egs++/egs_transformations.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,23 @@ class EGS_EXPORT EGS_RotationMatrix {
(rzx == m.rxz) && (rzy == m.rzy) && (rzz == m.rzz)) ? true : false;
};

/*! \brief Returns \c true, if this object is a unity matrix, \a false
/*! \brief Returns \c true, if this object is approximately the unit matrix, \a false
otherwise */
bool isI() const {
return (rxx == 1 && rxy == 0 && rxz == 0 && ryx == 0 && ryy == 1 &&
ryz == 0 && rzx == 0 && rzy == 0 && rzz == 1);

// compare with unit matrix components
if (fabs(rxy) < epsilon &&
fabs(rxz) < epsilon &&
fabs(ryx) < epsilon &&
fabs(ryz) < epsilon &&
fabs(rzx) < epsilon &&
fabs(rzy) < epsilon &&
fabs(rxx-1) < epsilon &&
fabs(ryy-1) < epsilon &&
fabs(rzz-1) < epsilon ) {
return true;
}
return false;
};

/*! \brief Returns the rotated a vector \f$ R \cdot \vec{v}\f$ */
Expand Down

0 comments on commit 011c307

Please sign in to comment.