00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MATH_LIB_INC_POINT3i_H
00024 #define MATH_LIB_INC_POINT3i_H
00025
00026 #include <math.h>
00027 #include "std/config.H"
00028
00029 typedef const class point3i cpoint3i;
00030 class point3i {
00031 protected:
00032 int _x, _y, _z;
00033
00034 public:
00035
00036 point3i() : _x(0), _y(0), _z(0) {}
00037 point3i(int x, int y, int z) : _x(x), _y(y), _z(z) {}
00038 point3i(int *v) : _x(v[0]), _y(v[1]), _z(v[2]) {}
00039
00040 const int *data() const { return &_x; }
00041 point3i operator %(cpoint3i &p) const { return point3i(_x+p[0],
00042 _y+p[1], _z+p[2]);}
00043 point3i operator -() const { return point3i(-_x, -_y, -_z); }
00044
00045
00046 int operator [](int index) const { return (&_x)[index]; }
00047 int& operator [](int index) { return (&_x)[index]; }
00048
00049 double length () const {return sqrt((double)(_x*_x+_y*_y+_z*_z));}
00050 int lengthSqrd () const { return _x*_x+_y*_y+_z*_z; }
00051
00052 int distSqrd (cpoint3i &p) const { return (_x-p._x) * (_x-p._x) +
00053 (_y-p._y) * (_y-p._y) +
00054 (_z-p._z) * (_z-p._z); }
00055 double dist(cpoint3i &p) const {return sqrt((double)distSqrd(p));}
00056
00057 void operator +=(cpoint3i &p) { _x += p[0]; _y += p[1];_z+=p[2];}
00058 void operator -=(cpoint3i &p) { _x -= p[0]; _y -= p[1];_z-=p[2];}
00059
00060 int operator ==(cpoint3i &p) const { return _x == p._x && _y == p._y
00061 && _z == p._z;}
00062 int operator !=(cpoint3i &p) const { return _x != p._x || _y != p._y
00063 || _z != p._z;}
00064
00065 };
00066
00067 inline ostream &
00068 operator <<(ostream &os, cpoint3i &p) {
00069 return os << "< " << p[0] << " " << p[1] << " " << p[2] << " > ";
00070 }
00071
00072 inline istream &
00073 operator>>(istream &is, point3i &p)
00074 {
00075 char dummy;
00076 return is >> dummy >> p[0] >> p[1] >> p[2] >> dummy;
00077 }
00078
00079 typedef ARRAY<point3i> point3i_list;
00080
00081 #endif // MATH_LIB_INC_Point3i_H
00082
00083
00084