January 2018
Intermediate to advanced
374 pages
9h 53m
English
Now, let's create the proxy object for distances between points: DistProxy. A point distance simply consists of the squared distance between two points and a comparison to a distance. The actual squared distance is never exposed in order to prevent the library user from mixing the squared distance with the regular distance. That is, if we do not take precaution, the user of the code might accidentally write the following:
auto a = Point{23, 45};
auto b = Point{55, 66};
auto spot = Point{34, 55};
// Subtle bug below as distance is compared to distance_squared
bool a_is_nearest = a.distance(spot) < b.distance_squared(spot);
Thus, he may end up accidentally comparing the squared distance with the real distance, ...
Read now
Unlock full access