Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

point3i.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 2000, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 /* end of file point3i.H */
00084 

Generated on Mon Sep 15 16:25:57 2003 for gluebase by doxygen1.2.18