ipoint3.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: ipoint3.h
00004 
00005     DESCRIPTION: Class definitions for IPoint3
00006 
00007     CREATED BY: Dan Silva
00008 
00009     HISTORY:
00010 
00011  *> Copyright (c) 1994, All Rights Reserved.
00012  **********************************************************************/
00013 #pragma once
00014 
00015 #include "GeomExport.h"
00016 #include "maxheap.h"
00017 #include <iosfwd>
00018 #include <math.h>
00019 
00028 class IPoint3: public MaxHeapOperators {
00029 public:
00030     int x,y,z;
00031 
00032     // Constructors
00034     IPoint3(){}
00037     IPoint3(int X, int Y, int Z)  { x = X; y = Y; z = Z;  }
00040     IPoint3(const IPoint3& a) { x = a.x; y = a.y; z = a.z; } 
00043     IPoint3(int ai[3]) { x = ai[0]; y = ai[1]; z = ai[2]; }
00044 
00045     // Access operators
00048     int& operator[](int i) { return (&x)[i]; }     
00051     const int& operator[](int i) const { return (&x)[i]; }  
00052     
00053     // Conversion function
00055     operator int*() { return(&x); }
00056 
00057     // Unary operators
00059     IPoint3 operator-() const { return(IPoint3(-x,-y,-z)); } 
00061     IPoint3 operator+() const { return *this; } 
00062 
00063     // Assignment operators
00065     GEOMEXPORT IPoint3& operator-=(const IPoint3&);
00067     GEOMEXPORT IPoint3& operator+=(const IPoint3&);
00068 
00069     // Binary operators
00071     GEOMEXPORT IPoint3 operator-(const IPoint3&) const;
00073     GEOMEXPORT IPoint3 operator+(const IPoint3&) const;
00075     GEOMEXPORT int operator*(const IPoint3&) const;    // DOT PRODUCT
00077     GEOMEXPORT int DotProd(const IPoint3&) const;    // DOT PRODUCT
00079     GEOMEXPORT IPoint3 operator^(const IPoint3&) const;   // CROSS PRODUCT
00083     GEOMEXPORT IPoint3 CrossProd(const IPoint3&) const;   // CROSS PRODUCT
00084 
00085     // Relational operators
00089     int operator==(const IPoint3& p) const { return (x == p.x && y == p.y && z == p.z); }
00090     int operator!=(const IPoint3& p) const { return ( (x != p.x) || (y != p.y) || (z != p.z) ); }
00091     };
00092 
00093     // friends, so you can write Length(A) instead of A.Length(), etc.
00096 GEOMEXPORT int MaxComponent(const IPoint3&);  // the component with the maximum abs value
00099 GEOMEXPORT int MinComponent(const IPoint3&);  // the component with the minimum abs value
00100      
00101 GEOMEXPORT std::ostream &operator<<(std::ostream&, const IPoint3&); 
00102 
00103 
00104 // Inlines:
00105 
00108 inline float Length(const IPoint3& v) { 
00109     return (float)sqrt((double)(v.x*v.x+v.y*v.y+v.z*v.z));
00110     }
00111 
00112 inline IPoint3& IPoint3::operator-=(const IPoint3& a) { 
00113     x -= a.x;   y -= a.y;   z -= a.z;
00114     return *this;
00115     }
00116 
00117 inline IPoint3& IPoint3::operator+=(const IPoint3& a) {
00118     x += a.x;   y += a.y;   z += a.z;
00119     return *this;
00120     }
00121 
00122 inline IPoint3 IPoint3::operator-(const IPoint3& b) const {
00123     return(IPoint3(x-b.x,y-b.y,z-b.z));
00124     }
00125 
00126 inline IPoint3 IPoint3::operator+(const IPoint3& b) const {
00127     return(IPoint3(x+b.x,y+b.y,z+b.z));
00128     }
00129 
00130 inline int IPoint3::operator*(const IPoint3& b) const {  
00131     return(x*b.x+y*b.y+z*b.z);  
00132     }
00133 
00134 inline int IPoint3::DotProd(const IPoint3& b)  const { 
00135     return(x*b.x+y*b.y+z*b.z);  
00136     }
00137 
00138