Ignore:
Timestamp:
May 21, 2008, 9:24:54 AM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
33c05d
Parents:
e9c14d
Message:

new header file for the vector class, new operators +=,*=,*,+

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/vector.cpp

    re9c14d r725869  
    182182};
    183183
     184/** Sums vector \a to this lhs component-wise.
     185 * \param a base vector
     186 * \param b vector components to add
     187 * \return lhs + a
     188 */
     189vector& operator+=(vector& a, const vector& b)
     190{
     191  a.AddVector(&b);
     192  return a;
     193};
     194/** factor each component of \a a times a double \a m.
     195 * \param a base vector
     196 * \param m factor
     197 * \return lhs.x[i] * m
     198 */
     199vector& operator*=(vector& a, const double m)
     200{
     201  a.Scale(m);
     202  return a;
     203};
     204
     205/** Sums two vectors \a  and \b component-wise.
     206 * \param a first vector
     207 * \param b second vector
     208 * \return a + b
     209 */
     210vector& operator+(const vector& a, const vector& b)
     211{
     212  vector *x = new vector;
     213  x->CopyVector(&a);
     214  x->AddVector(&b);
     215  return *x;
     216};
     217
     218/** Factors given vector \a a times \a m.
     219 * \param a vector
     220 * \param m factor
     221 * \return a + b
     222 */
     223vector& operator*(const vector& a, const double m)
     224{
     225  vector *x = new vector;
     226  x->CopyVector(&a);
     227  x->Scale(m);
     228  return *x;
     229};
     230
    184231/** Prints a 3dim vector.
    185232 * prints no end of line.
     
    213260{
    214261  for (int i=0;i<NDIM;i++)
    215     this->x[i] *= (*factor)[i];
     262    x[i] *= (*factor)[i];
    216263};
    217264
     
    219266{
    220267  for (int i=0;i<NDIM;i++)
    221     this->x[i] *= *factor;
     268    x[i] *= *factor;
    222269};
    223270
     
    225272{
    226273  for (int i=0;i<NDIM;i++)
    227     this->x[i] *= factor;
     274    x[i] *= factor;
    228275};
    229276
Note: See TracChangeset for help on using the changeset viewer.