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
parent
838126f81f
commit
52a481cd1e
|
@ -441,11 +441,12 @@ double Vector::Element(int i) const {
|
||||||
|
|
||||||
bool Vector::Equals(Vector v, double tol) const {
|
bool Vector::Equals(Vector v, double tol) const {
|
||||||
// Quick axis-aligned tests before going further
|
// Quick axis-aligned tests before going further
|
||||||
double dx = v.x - x; if(dx < -tol || dx > tol) return false;
|
const Vector dv = this->Minus(v);
|
||||||
double dy = v.y - y; if(dy < -tol || dy > tol) return false;
|
if (fabs(dv.x) > tol) return false;
|
||||||
double dz = v.z - z; if(dz < -tol || dz > 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 {
|
bool Vector::EqualsExactly(Vector v) const {
|
||||||
|
|
Loading…
Reference in New Issue