Small performance optimization in Vector::Equals.

This function showed up surprisingly high on a CPU time profile
when the GUI was unresponsive "doing things". Removed a duplicated
difference in the not-equal case, and switched to abs and a single compare
instead of two compares with a negation. It seems to have moved the
function further down in the profile.
pull/409/head
Ryan A. Pavlik 2019-05-13 10:02:50 -05:00 committed by whitequark
parent 838126f81f
commit 52a481cd1e
1 changed files with 5 additions and 4 deletions

View File

@ -441,11 +441,12 @@ double Vector::Element(int i) const {
bool Vector::Equals(Vector v, double tol) const {
// Quick axis-aligned tests before going further
double dx = v.x - x; if(dx < -tol || dx > tol) return false;
double dy = v.y - y; if(dy < -tol || dy > tol) return false;
double dz = v.z - z; if(dz < -tol || dz > tol) return false;
const Vector dv = this->Minus(v);
if (fabs(dv.x) > tol) return false;
if (fabs(dv.y) > tol) return false;
if (fabs(dv.z) > tol) return false;
return (this->Minus(v)).MagSquared() < tol*tol;
return dv.MagSquared() < tol*tol;
}
bool Vector::EqualsExactly(Vector v) const {