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_POINT2i_H
00024 #define MATH_LIB_INC_POINT2i_H
00025
00026 #include <math.h>
00027 #include "std/config.H"
00028
00029
00030
00031
00032 typedef const class vec2i cvec2i;
00033 class vec2i {
00034 protected :
00035 int _x, _y;
00036
00037 public:
00038
00039 vec2i() : _x(0) , _y(0) {}
00040 vec2i(int x, int y) : _x(x) , _y(y) {}
00041
00042 vec2i operator + (cvec2i &v) const { return vec2i(_x+v._x, _y+v._y); }
00043 vec2i operator - (cvec2i &v) const { return vec2i(_x-v._x, _y-v._y); }
00044 int operator * (cvec2i &v) const { return _x*v._x+_y*v._y; }
00045 vec2i operator - () const { return vec2i(-_x, -_y); }
00046
00047 int operator [](int index) const { return (&_x)[index]; }
00048 int& operator [](int index) { return (&_x)[index]; }
00049
00050 double length () const { return sqrt((double)_x*_x+_y*_y);}
00051 int lengthSqrd () const { return _x*_x+_y*_y; }
00052
00053 vec2i perpend () const { return vec2i(-_y, _x); }
00054
00055 double dist (cvec2i &v) const { return (*this-v).length(); }
00056 int distSqrd (cvec2i &v) const { return (*this-v).lengthSqrd(); }
00057
00058 int isNull() const { return _x == 0 && _y == 0; }
00059
00060 void operator +=(cvec2i &v) { _x += v._x; _y += v._y; }
00061 void operator -=(cvec2i &v) { _x -= v._x; _y -= v._y; }
00062 int operator ==(cvec2i& v) const { return v._x == _x && v._y == _y;}
00063 int operator !=(cvec2i& v) const { return v._x != _x || v._y != _y;}
00064 };
00065
00066 inline ostream &
00067 operator<<(ostream &os, cvec2i &v)
00068 {
00069 return os << "{ " << v[0] << " " << v[1] << " } ";
00070 }
00071
00072 inline istream &
00073 operator>>(istream &is, vec2i &v)
00074 {
00075 char dummy;
00076 return is >> dummy >> v[0] >> v[1] >> dummy;
00077 }
00078
00079 typedef ARRAY<vec2i> vec2i_list;
00080
00081
00082
00083
00084 typedef const class point2i cpoint2i;
00085 class point2i {
00086 protected:
00087 int _x, _y;
00088
00089 public:
00090
00091 point2i() : _x(0), _y(0) {}
00092 point2i(int xx, int yy) : _x(xx), _y(yy) {}
00093
00094 const int *data() const { return &_x; }
00095 point2i operator %(cpoint2i &p) const { return point2i(_x+p[0],_y+p[1]);}
00096 point2i operator +(cvec2i &v) const { return point2i(_x+v[0],_y+v[1]);}
00097 vec2i operator -(cpoint2i &p) const { return vec2i (_x-p[0],_y-p[1]);}
00098 point2i operator -(cvec2i &v) const { return point2i(_x-v[0],_y-v[1]);}
00099 point2i operator -() const { return point2i(-_x, -_y); }
00100
00101 int operator [](int index) const { return (&_x)[index]; }
00102 int& operator [](int index) { return (&_x)[index]; }
00103
00104 double length () const { return sqrt((double) (_x*_x+_y*_y)); }
00105 int lengthSqrd () const { return _x*_x+_y*_y; }
00106
00107 int distSqrd(cpoint2i &p) const { return (_x-p._x) * (_x-p._x) +
00108 (_y-p._y) * (_y-p._y); }
00109 double dist (cpoint2i &p) const { return sqrt((double) distSqrd(p)); }
00110
00111 void operator +=(cpoint2i &p) { _x += p[0]; _y += p[1]; }
00112 void operator +=(cvec2i &v) { _x += v[0]; _y += v[1]; }
00113 void operator -=(cpoint2i &p) { _x -= p[0]; _y -= p[1]; }
00114 void operator -=(cvec2i &v) { _x -= v[0]; _y -= v[1]; }
00115
00116 int operator ==(cpoint2i &p) const { return _x == p._x && _y == p._y;}
00117 int operator !=(cpoint2i &p) const { return _x != p._x || _y != p._y;}
00118 };
00119
00120 inline ostream &
00121 operator<<(ostream &os, cpoint2i &p)
00122 {
00123 return os << "< " << p[0] << " " << p[1] << " > ";
00124 }
00125
00126 inline istream &
00127 operator>>(istream &is, point2i &p)
00128 {
00129 char dummy;
00130 return is >> dummy >> p[0] >> p[1] >> dummy;
00131 }
00132
00133 typedef ARRAY<point2i> point2i_list;
00134
00135 #endif // MATH_LIB_INC_Point2i_H
00136
00137
00138