From 436316bbdf974eda51e3344306af0e66df1f547a Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Fri, 9 Feb 2024 16:19:12 +0000 Subject: [PATCH] Set vector components to zero if sufficiently close. [closes #159] --- corelib/src/libs/SireVol/triclinicbox.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/corelib/src/libs/SireVol/triclinicbox.cpp b/corelib/src/libs/SireVol/triclinicbox.cpp index a5d45b045..bbc483016 100644 --- a/corelib/src/libs/SireVol/triclinicbox.cpp +++ b/corelib/src/libs/SireVol/triclinicbox.cpp @@ -251,6 +251,27 @@ void TriclinicBox::rotate(double precision) this->is_rotated = false; } + // Some codes assert reduced form by checking that certain box vector + // components are exactly zero. As such, we need to convert any that + // are sufficiently close to exactly zero. + + // First vector must lie along the x-axis. + if (std::abs(this->v0.y()) < 1e-8) + { + this->v0.setY(0); + } + if (std::abs(this->v0.z()) < 1e-8) + { + this->v0.setZ(0); + } + + // Second must lie in the x-y plane. + if (std::abs(this->v1.z()) < 1e-8) + { + this->v1.setZ(0); + } + + // Now set the box attributes. this->setAttributes(); }