Add distance2 for point
This commit is contained in:
parent
2ef2554316
commit
6d879a96de
10
point.cpp
10
point.cpp
@ -29,9 +29,15 @@ using namespace util;
|
|||||||
|
|
||||||
double
|
double
|
||||||
point::distance (const point &other) const {
|
point::distance (const point &other) const {
|
||||||
return sqrt ((x - other.x) * (x - other.x) +
|
return sqrt (distance2 (other));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
point::distance2 (const point &other) const {
|
||||||
|
return (x - other.x) * (x - other.x) +
|
||||||
(y - other.y) * (y - other.y) +
|
(y - other.y) * (y - other.y) +
|
||||||
(z - other.z) * (z - other.z));
|
(z - other.z) * (z - other.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ namespace util {
|
|||||||
double x, y, z;
|
double x, y, z;
|
||||||
|
|
||||||
double distance (const point &) const;
|
double distance (const point &) const;
|
||||||
|
double distance2 (const point &) const;
|
||||||
double manhattan (const point &) const;
|
double manhattan (const point &) const;
|
||||||
|
|
||||||
point& operator*= (double);
|
point& operator*= (double);
|
||||||
|
Loading…
Reference in New Issue
Block a user