Make points be three dimensional

This commit is contained in:
Danny Robson 2011-09-13 15:12:09 +10:00
parent 14597ebba2
commit 8c995c22ac
2 changed files with 12 additions and 7 deletions

View File

@ -25,23 +25,28 @@ using namespace std;
using namespace util; 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), x (_x),
y (_y) y (_y),
z (_z)
{ ; } { ; }
double double
point::distance (const point &other) const { point::distance (const point &other) const {
return sqrt ((x - other.x) * (x - other.x) + 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 double
point::manhattan (const point &other) const { point::manhattan (const point &other) const {
return fabs (x - other.x) + return fabs (x - other.x) +
fabs (y - other.y); fabs (y - other.y) +
fabs (z - other.z);
} }

View File

@ -21,11 +21,11 @@
#define __UTIL_POINT_HPP #define __UTIL_POINT_HPP
namespace util { namespace util {
/// A two dimensional position in space /// A three dimensional position in space.
struct point { 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 distance (const point &) const;
double manhattan (const point &) const; double manhattan (const point &) const;