Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

point3i.H

Go to the documentation of this file.
00001 #ifndef POINT3I_H_IS_INCLUDED
00002 #define POINT3I_H_IS_INCLUDED
00003 
00004 /*!
00005  *  \file Point3i.H
00006  *  \brief Contains the definition of the Point3i class.
00007  *  \ingroup group_MLIB
00008  *
00009  */
00010 
00011 #include <cmath>
00012 #include "std/support.H"
00013 
00014 namespace mlib {
00015 
00016 class Point3i;
00017 
00018 //! \brief Shortcut for const Point3i
00019 //! \relates Point3i
00020 typedef const Point3i Cpoint3i;
00021 
00022 /*!
00023  *  \brief A 3D point class with integer components.
00024  *  \ingroup group_MLIB
00025  *
00026  */
00027 class Point3i
00028 {
00029    
00030    protected:
00031    
00032       int _x, _y, _z;
00033 
00034    public:
00035    
00036       //! \name Constructors
00037       //@{
00038 
00039       //! \brief Default constructor.  Creates a point at the origin.
00040       Point3i()                     : _x(0), _y(0), _z(0) {}
00041       
00042       //! \brief Constructor that creates a point with the components given in
00043       //! the arguments.
00044       Point3i(int x, int y, int z)  : _x(x), _y(y), _z(z) {}
00045       
00046       //! \brief Constructor that creates a point with the values from a
00047       //! 3-element array.
00048       Point3i(int *v)               : _x(v[0]), _y(v[1]), _z(v[2]) {}
00049       
00050       //    Point3i(Cpoint3 &p)      : _x(round(p[0])), _y(round(p[1])) {}
00051       //    Point3i(Cpoint2 &p)      : _x(round(p[0])), _y(round(p[1])) {}
00052       
00053       //@}
00054       
00055       //! \name Descriptive interface
00056       //@{
00057          
00058       typedef int value_type;
00059       static int dim() { return 3; }
00060       
00061       //@} 
00062       
00063       //! \name Element Access Functions
00064       //@{
00065          
00066       //! \brief Returns the components as a 3-element array of integers.
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       //! \name Overloaded Arithmetic Operators
00075       //@{
00076       
00077       Point3i  operator  +(Cpoint3i &p) const { return Point3i(_x+p[0], _y+p[1], _z+p[2]); }
00078       //    Point3i  operator  +(Cvec3i   &v) const { return Point3i(_x+v[0], _y+v[1], _z+v[2]); }
00079       //    Vec3i    operator  -(Cpoint3i &p) const { return Vec3i  (_x-p[0], _y-p[1], _z-p[2]); }
00080       //    Point3i  operator  -(Cvec3i   &v) const { return Point3i(_x-v[0], _y-v[1], _z-v[2]); }
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       //    void     operator +=(Cvec3i   &v)        { _x += v[0]; _y += v[1];_z+=v[2];}
00085       void     operator -=(Cpoint3i &p)        { _x -= p[0]; _y -= p[1];_z-=p[2];}
00086       //    void     operator -=(Cvec3i   &v)        { _x -= v[0]; _y -= v[1];_z-=v[2];}
00087       
00088       //@}
00089       
00090       //! \name Point Property Queries
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       //! \name Two Point Operations
00101       //@{
00102       
00103       //! \brief Computes the distance squared between two points.
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       //! \brief Computes the distance between two points.
00110       double   dist       (Cpoint3i &p)  const
00111          {return sqrt((double) dist_sqrd(p)); }
00112       
00113       //@}
00114       
00115       //! \name Overloaded Comparison Operators
00116       //@{
00117       
00118       //! \brief Are the two points exactly equal?
00119       int      operator ==(Cpoint3i &p)  const
00120          { return _x == p._x && _y == p._y  && _z == p._z;}
00121       
00122       //! \brief Are the two points not equal?
00123       int      operator !=(Cpoint3i &p)  const
00124          { return _x != p._x || _y != p._y  ||  _z != p._z;}
00125          
00126       //@}
00127       
00128       //! \name Overloaded Stream Operators
00129       //@{
00130       
00131       //! \brief Stream insertion operator for the Point3i class.
00132       friend  ostream &operator <<(ostream &os, const Point3i &p) 
00133          { os << "<"<<p._x<<","<<p._y<<","<<p._z<<">"; return os; }
00134                        
00135       //@}
00136       
00137 }; // class Point3i
00138 
00139 } // namespace mlib
00140 
00141 #endif // POINT3I_H_IS_INCLUDED
00142 
00143 /* end of file Point3i.H */
00144 

Generated on Mon Sep 18 11:39:33 2006 for jot by  doxygen 1.4.4