00001 #ifndef POINT3I_H_IS_INCLUDED
00002 #define POINT3I_H_IS_INCLUDED
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <cmath>
00012 #include "std/support.H"
00013
00014 namespace mlib {
00015
00016 class Point3i;
00017
00018
00019
00020 typedef const Point3i Cpoint3i;
00021
00022
00023
00024
00025
00026
00027 class Point3i
00028 {
00029
00030 protected:
00031
00032 int _x, _y, _z;
00033
00034 public:
00035
00036
00037
00038
00039
00040 Point3i() : _x(0), _y(0), _z(0) {}
00041
00042
00043
00044 Point3i(int x, int y, int z) : _x(x), _y(y), _z(z) {}
00045
00046
00047
00048 Point3i(int *v) : _x(v[0]), _y(v[1]), _z(v[2]) {}
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 typedef int value_type;
00059 static int dim() { return 3; }
00060
00061
00062
00063
00064
00065
00066
00067 const int *data() const { return &_x; }
00068
00069 int operator [](int index) const { return (&_x)[index]; }
00070 int& operator [](int index) { return (&_x)[index]; }
00071
00072
00073
00074
00075
00076
00077 Point3i operator +(Cpoint3i &p) const { return Point3i(_x+p[0], _y+p[1], _z+p[2]); }
00078
00079
00080
00081 Point3i operator -() const { return Point3i(-_x, -_y, -_z); }
00082
00083 void operator +=(Cpoint3i &p) { _x += p[0]; _y += p[1];_z+=p[2];}
00084
00085 void operator -=(Cpoint3i &p) { _x -= p[0]; _y -= p[1];_z-=p[2];}
00086
00087
00088
00089
00090
00091
00092
00093 double length () const
00094 { return sqrt((double) (_x*_x+_y*_y+_z*_z)); }
00095 int length_sqrd () const
00096 { return _x*_x+_y*_y+_z*_z; }
00097
00098
00099
00100
00101
00102
00103
00104 int dist_sqrd (Cpoint3i &p) const
00105 { return (_x-p._x) * (_x-p._x) +
00106 (_y-p._y) * (_y-p._y) +
00107 (_z-p._z) * (_z-p._z); }
00108
00109
00110 double dist (Cpoint3i &p) const
00111 {return sqrt((double) dist_sqrd(p)); }
00112
00113
00114
00115
00116
00117
00118
00119 int operator ==(Cpoint3i &p) const
00120 { return _x == p._x && _y == p._y && _z == p._z;}
00121
00122
00123 int operator !=(Cpoint3i &p) const
00124 { return _x != p._x || _y != p._y || _z != p._z;}
00125
00126
00127
00128
00129
00130
00131
00132 friend ostream &operator <<(ostream &os, const Point3i &p)
00133 { os << "<"<<p._x<<","<<p._y<<","<<p._z<<">"; return os; }
00134
00135
00136
00137 };
00138
00139 }
00140
00141 #endif // POINT3I_H_IS_INCLUDED
00142
00143
00144