Changeset 958 in Sophya for trunk/SophyaLib/NTools/poly.h
- Timestamp:
- Apr 18, 2000, 3:38:53 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/NTools/poly.h
r938 r958 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: poly.h,v 1. 7 2000-04-14 16:14:31ansari Exp $3 // $Id: poly.h,v 1.8 2000-04-18 13:38:36 ansari Exp $ 4 4 // 5 5 … … 21 21 22 22 ////////////////////////////////////////////////////////////////////////// 23 //! Class of 1 dimension polynomials P(x) 23 24 class Poly : public TVector<r_8> { 24 25 friend class ObjFileIO<Poly>; … … 27 28 Poly(Poly const& a); 28 29 30 //! Return degre of polynomials 29 31 inline int Degre() const {UpdateDegIfDirty(); return deg;} 30 32 33 //! Return space for a \b n degre polynomial 34 /*! 35 \param \b n : degre of new polynomial 36 \param \b force : force re-allocation if true,\ 37 if not allocation occurs only 38 if space needed is greater than the old one 39 */ 31 40 inline void Realloc(int n, bool force=false) 32 41 {TVector<r_8>::Realloc(n+1,force);} 33 42 34 43 // Pour compatibilite PEIDA - Reza 03/2000 44 //! Return coefficient of degre \b i 35 45 inline double Element(int i) const { return Elem(i,0,0,0,0); } 46 //! Return coefficient of degre \b i 36 47 inline double & Element(int i) { return Elem(i,0,0,0,0); } 37 48 49 //! Return coefficient of degre \b i 38 50 inline double operator[](int i) const {return Elem(i,0,0,0,0);} 51 //! Return coefficient of degre \b i 39 52 inline double& operator[](int i) {dirty = 1; return Elem(i,0,0,0,0);} 40 53 // Retourne le coefficient de degre i … … 87 100 }; 88 101 102 /*! \ingroup NTools \fn operator*(Poly const&,Poly const&) 103 \brief perform and return P(X) = a(x) * b(x) */ 89 104 inline Poly operator* (Poly const& a, Poly const& b) 90 105 { return a.Mult(b); } 91 106 107 /*! \ingroup NTools \fn operator+(Poly const&,Poly const&) 108 \brief perform and return P(X) = a(x) + b(x) */ 92 109 inline Poly operator+ (Poly const& a, Poly const& b) 93 110 { Poly c((a.Degre() > b.Degre())?(a.Degre()+1):(b.Degre()+1)); 94 111 c = a; c += b; return c; } 95 112 113 /*! \ingroup NTools \fn operator-(Poly const&,Poly const&) 114 \brief perform and return P(X) = a(x) - b(x) */ 96 115 inline Poly operator- (Poly const& a, Poly const& b) 97 116 { Poly c((a.Degre() > b.Degre())?(a.Degre()+1):(b.Degre()+1)); 98 117 c = a; c -= b; return c; } 99 118 119 /*! \ingroup NTools \fn operator*(double,Poly const&) 120 \brief perform and return P(X) = a * b(x) */ 100 121 inline Poly operator* (double a, Poly const& b) 101 122 { Poly c(b); c *= a; return c; } 102 123 124 /*! \ingroup NTools \fn operator<<(ostream&,const Poly&) 125 \brief Print a(x) on stream \b s */ 103 126 inline ostream& operator << (ostream& s, const Poly& a) 104 127 { a.Print(s); return s; } 105 128 106 129 ////////////////////////////////////////////////////////////////////////// 130 /*! \ingroup NTools \fn operator<<(POutPersist&,Poly&) 131 \brief For persistance management */ 107 132 inline POutPersist& operator << (POutPersist& os, Poly & obj) 108 133 { ObjFileIO<Poly> fio(&obj); fio.Write(os); return(os); } 134 /*! \ingroup NTools \fn operator<<(PInPersist&,,Poly&) 135 \brief For persistance management */ 109 136 inline PInPersist& operator >> (PInPersist& is, Poly & obj) 110 137 { ObjFileIO<Poly> fio(&obj); fio.Read(is); return(is); } … … 116 143 117 144 ////////////////////////////////////////////////////////////////////////// 145 //! Class of 2 dimensions polynomials P(x,y) 118 146 class Poly2 : public TVector<r_8> { 119 147 friend class ObjFileIO<Poly2>; … … 124 152 Poly2(Poly2 const& a); 125 153 154 //! Return polynomial partial degre for X 126 155 inline int DegX() const {UpdateDegIfDirty(); return degX;} 156 //! Return polynomial partial degre for Y 127 157 inline int DegY() const {UpdateDegIfDirty(); return degY;} 158 //! Return polynomial maximum partial degre for X 128 159 inline int MaxDegX() const {return maxDegX;} 160 //! Return polynomial maximum partial degre for Y 129 161 inline int MaxDegY() const {return maxDegY;} 162 //! Return polynomial total degre for X 130 163 inline int Deg() const {UpdateDegIfDirty(); return deg;} 131 164 // les degres partiels en x et y, et totaux. 132 165 133 166 // Pour compatibilite PEIDA - Reza 03/2000 167 //! Return coefficient of degre \b i 134 168 inline double Element(int i) const { return Elem(i,0,0,0,0); } 169 //! Return coefficient of degre \b i 135 170 inline double & Element(int i) { return Elem(i,0,0,0,0); } 136 171 … … 138 173 // retourne la valeur en (x,y) 139 174 175 //! Return index of coefficient of X^dx * Y^dy in the vector 140 176 inline int IndCoef(int dx, int dy) const { 141 177 if (dx>maxDegX || dy>maxDegY) THROW(rangeCheckErr); … … 146 182 // d'un fit... 147 183 184 //! Return coefficient of X^dx * Y^dy 148 185 inline double Coef(int dx, int dy) const { 149 186 return (dx>maxDegX || dy>maxDegY) ? 0 : Element(IndCoef(dx,dy)); 150 187 } 188 //! Return coefficient of X^dx * Y^dy 151 189 inline double& Coef(int dx, int dy) { 152 190 if (dx>maxDegX || dy>maxDegY) THROW(rangeCheckErr); … … 199 237 }; 200 238 239 /*! \ingroup NTools \fn operator*(Poly2 const&,Poly2 const&) 240 \brief Perform P(x,y) = a(x,y) * b(x,y) */ 201 241 inline Poly2 operator* (Poly2 const& a, Poly2 const& b) 202 242 { return a.Mult(b); } 203 243 244 /*! \ingroup NTools \fn operator+(Poly2 const&,Poly2 const&) 245 \brief Perform P(x,y) = a(x,y) + b(x,y) */ 204 246 inline Poly2 operator+ (Poly2 const& a, Poly2 const& b) 205 247 { Poly2 c(a); c += b; return c; } 206 248 249 /*! \ingroup NTools \fn operator-(Poly2 const&,Poly2 const&) 250 \brief Perform P(x,y) = a(x,y) - b(x,y) */ 207 251 inline Poly2 operator- (Poly2 const& a, Poly2 const& b) 208 252 { Poly2 c(a); c -= b; return c; } 209 253 254 /*! \ingroup NTools \fn operator-(double,Poly2 const&) 255 \brief Perform P(x,y) = a * b(x,y) */ 210 256 inline Poly2 operator * (double a, Poly2 const& b) 211 257 { Poly2 c(b); c *= a; return c; } 212 258 259 /*! \ingroup NTools \fn operator<<(ostream&,const Poly2&) 260 \brief Print a(x,y) on stream \b s */ 213 261 inline ostream& operator << (ostream& s, const Poly2& a) 214 262 { a.Print(s); return s; } 215 263 216 264 ////////////////////////////////////////////////////////////////////////// 265 /*! \ingroup NTools \fn operator<<(POutPersist&,Poly2&) 266 \brief For persistance management */ 217 267 inline POutPersist& operator << (POutPersist& os, Poly2 & obj) 218 268 { ObjFileIO<Poly2> fio(&obj); fio.Write(os); return(os); } 269 /*! \ingroup NTools \fn operator<<(POutPersist&,Poly2&) 270 \brief For persistance management */ 219 271 inline PInPersist& operator >> (PInPersist& is, Poly2 & obj) 220 272 { ObjFileIO<Poly2> fio(&obj); fio.Read(is); return(is); }
Note:
See TracChangeset
for help on using the changeset viewer.