GLYCAM-Web / gmml2

Glycam Molecular Modeling Library
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Optimization in distance function #4

Closed gitoliver closed 4 months ago

gitoliver commented 8 months ago

From Tobias: what i meant is that distance or length is the sqrt of the sum of squares but if you square both sides of the statement, you don't need the square root at all you only have to calculate the sum of squares let's say we have a - operator in coordinates, which returns a coordinate(x - coord.x, y - coord.y, z - coord.z) you can do

bool Coordinate::withinDistance(const Coordinate &coordinate, const double distance) const { Coordinate diff = this->operator-(coordinate); return (std::abs(diff.x) < distance) && (std::abs(diff.y) < distance) && (std::abs(diff.z) < distance) && (diff.x diff.x + diff.y diff.y + diff.z diff.z < distance distance); }

now that last line should be a function call, but i inlined the function to illustrate that sqrt isn't neccessary

vraid commented 4 months ago

Has been implemented!