00001 #include <assert.h>
00002
00003 inline Point getOnes()
00004 {
00005 int ones[DIM];
00006 for (int k = 0 ; k < DIM; k++)
00007 {
00008 ones[k] = 1;
00009 }
00010 return Point(ones);
00011 };
00012 inline Point getZeros()
00013 {
00014 int zeros[DIM];
00015 for (int k = 0 ; k < DIM; k++)
00016 {
00017 zeros[k] = 0;
00018 }
00019 return Point(zeros);
00020 };
00021 inline Point getBasisV(int idir)
00022 {
00023 Point retval = getZeros();
00024 retval[idir] = 1;
00025 return retval;
00026 }
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 Point::Point(){};
00039 Point::Point(const int a_tuple[DIM])
00040 {
00041 for (int j = 0; j < DIM; j++)
00042 {
00043 m_tuple[j]=a_tuple[j];
00044 }
00045 };
00046 Point::Point(const array<int,DIM> a_tuple)
00047 {
00048 for (int j = 0; j < DIM; j++)
00049 {
00050 m_tuple[j]=a_tuple[j];
00051 }
00052 };
00053 Point::Point(const Point& a_pt)
00054 {
00055 *this = a_pt;
00056 };
00057
00058
00059 bool Point::operator<(const Point& a_rhs) const
00060 {
00061 for (int i = 0; i < DIM; i++)
00062 {
00063 if (m_tuple[i] < a_rhs[i])
00064 {
00065 return true;
00066 }
00067 else if (m_tuple[i] > a_rhs[i])
00068 {
00069 return false;
00070 }
00071 }
00072 return false;
00073 }
00074
00075 Point Point::operator+(const Point& a_rhsPoint) const
00076 {
00077 int tuple[DIM];
00078 for (int j = 0; j < DIM; j++)
00079 {
00080 tuple[j] = m_tuple[j]+a_rhsPoint.m_tuple[j];
00081 }
00082 Point ret(tuple);
00083 return ret;
00084 };
00085 Point Point::operator-(const Point& a_rhsPoint) const
00086 {
00087 int tuple[DIM];
00088 for (int j = 0; j < DIM; j++)
00089 {
00090 tuple[j] = m_tuple[j]-a_rhsPoint.m_tuple[j];
00091 }
00092 Point ret(tuple);
00093 return ret;
00094 };
00095 Point Point::operator*(const Point& a_rhsPoint) const
00096 {
00097 int tuple[DIM];
00098 for (int j = 0; j < DIM; j++)
00099 {
00100 tuple[j] = m_tuple[j]*a_rhsPoint.m_tuple[j];
00101 }
00102 Point ret(tuple);
00103 return ret;
00104 };
00105 Point Point::operator/(const Point& a_rhsPoint) const
00106 {
00107 int tuple[DIM];
00108 for (int j = 0; j < DIM; j++)
00109 {
00110 assert(a_rhsPoint[j]!=0);
00111 if (m_tuple[j]*a_rhsPoint[j] >= 0)
00112 {
00113 tuple[j] = m_tuple[j]/a_rhsPoint[j];
00114 }
00115 else
00116 {
00117 tuple[j] = -(-m_tuple[j]/a_rhsPoint[j]);
00118 }
00119 }
00120 Point ret(tuple);
00121 return ret;
00122
00123 };
00124 Point Point::operator*(int a_nref) const
00125 {
00126 int tuple[DIM];
00127 for (int j = 0; j < DIM; j++)
00128 {
00129 tuple[j] = m_tuple[j]*a_nref;
00130 }
00131 Point ret(tuple);
00132 return ret;
00133 };
00134 Point Point::operator/(int a_nref) const
00135 {
00136 int tuple[DIM];
00137 assert(a_nref != 0);
00138 for (int j = 0; j < DIM; j++)
00139 {
00140
00141 if (m_tuple[j]*a_nref >= 0)
00142 {
00143 tuple[j] = m_tuple[j]/a_nref;
00144 }
00145 else
00146 {
00147 tuple[j] = -(-m_tuple[j]/a_nref);
00148 }
00149 }
00150 Point ret(tuple);
00151 return ret;
00152 };
00153 void Point::operator+=(const Point& a_rhsPoint)
00154 {
00155 for (int j = 0; j < DIM; j++)
00156 {
00157 m_tuple[j] = m_tuple[j]+a_rhsPoint.m_tuple[j];
00158 }
00159 };
00160 void Point::operator-=(const Point& a_rhsPoint)
00161 {
00162 for (int j = 0; j < DIM; j++)
00163 {
00164 m_tuple[j] = m_tuple[j]-a_rhsPoint.m_tuple[j];
00165 }
00166 };
00167 void Point::operator*=(const Point& a_rhsPoint)
00168 {
00169 for (int j = 0; j < DIM; j++)
00170 {
00171 m_tuple[j] = m_tuple[j]*a_rhsPoint.m_tuple[j];
00172 }
00173 };
00174 void Point::operator/=(const Point& a_rhsPoint)
00175 {
00176 for (int j = 0; j < DIM; j++)
00177 {
00178 assert(a_rhsPoint[j]!=0);
00179 if (m_tuple[j]*a_rhsPoint[j] >= 0)
00180 {
00181 m_tuple[j] = m_tuple[j]/a_rhsPoint[j];
00182 }
00183 else
00184 {
00185 m_tuple[j] = -(-m_tuple[j]/a_rhsPoint[j]);
00186 }
00187 }
00188 };
00189 void Point::operator+=(int a_nref)
00190 {
00191 for (int j = 0; j < DIM; j++)
00192 {
00193 m_tuple[j] = m_tuple[j]+a_nref;
00194 }
00195 };
00196 void Point::operator-=(int a_nref)
00197 {
00198 for (int j = 0; j < DIM; j++)
00199 {
00200 m_tuple[j] = m_tuple[j]-a_nref;
00201 }
00202 };
00203 void Point::operator*=(int a_nref)
00204 {
00205 for (int j = 0; j < DIM; j++)
00206 {
00207 m_tuple[j] = m_tuple[j]*a_nref;
00208 }
00209 };
00210 void Point::operator/=(int a_nref)
00211 {
00212 assert(a_nref!=0);
00213 for (int j = 0; j < DIM; j++)
00214 {
00215
00216 if (m_tuple[j]*a_nref >= 0)
00217 {
00218 m_tuple[j] = m_tuple[j]/a_nref;
00219 }
00220 else
00221 {
00222 m_tuple[j] = -(-m_tuple[j]/a_nref);
00223 }
00224 }
00225 };
00226 bool Point::operator==(const Point& a_rhsPoint) const
00227 {
00228 bool ret = true;
00229 for (int j = 0; j < DIM; j++)
00230 {
00231 if (m_tuple[j] != a_rhsPoint[j]) ret=false;
00232 }
00233 return ret;
00234 };
00235 bool Point::operator!=(const Point& a_rhsPoint) const
00236 {
00237 return !(*this == a_rhsPoint);
00238 };
00239
00240
00241
00242
00243
00244