Make points be three dimensional
This commit is contained in:
parent
14597ebba2
commit
8c995c22ac
13
point.cpp
13
point.cpp
@ -25,23 +25,28 @@ using namespace std;
|
||||
using namespace util;
|
||||
|
||||
|
||||
point::point (double _x, double _y):
|
||||
// Unused components are zeroed so that higher dimensional operations can
|
||||
// operate without fear of triggering NaNs or other such complications.
|
||||
point::point (double _x, double _y, double _z):
|
||||
x (_x),
|
||||
y (_y)
|
||||
y (_y),
|
||||
z (_z)
|
||||
{ ; }
|
||||
|
||||
|
||||
double
|
||||
point::distance (const point &other) const {
|
||||
return sqrt ((x - other.x) * (x - other.x) +
|
||||
(y - other.y) * (y - other.y));
|
||||
(y - other.y) * (y - other.y) +
|
||||
(z - other.z) * (z - other.z));
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
point::manhattan (const point &other) const {
|
||||
return fabs (x - other.x) +
|
||||
fabs (y - other.y);
|
||||
fabs (y - other.y) +
|
||||
fabs (z - other.z);
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,11 +21,11 @@
|
||||
#define __UTIL_POINT_HPP
|
||||
|
||||
namespace util {
|
||||
/// A two dimensional position in space
|
||||
/// A three dimensional position in space.
|
||||
struct point {
|
||||
double x, y;
|
||||
double x, y, z;
|
||||
|
||||
point (double x, double y);
|
||||
point (double x, double y, double z = 0.0);
|
||||
|
||||
double distance (const point &) const;
|
||||
double manhattan (const point &) const;
|
||||
|
Loading…
Reference in New Issue
Block a user