Main Page   Namespace List   Class Hierarchy   Compound List   File List   Header Files   Sources   Namespace Members   Compound Members   File Members  

vector2.h

This is the verbatim text of the vector2.h include file.
//$Header: /home/ben/Mapper/include/RCS/vector2.h,v 6.2 2002/06/09 22:43:13 ben Exp $
#ifndef VECTOR2_H
#define VECTOR2_H
// Copyright Benedict Adamson 2002.
// This file is part of Mapper.

// Mapper is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

// Mapper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mapper; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#include <cmath>



struct vector2
{
   public: //constructors and destructors
      
      inline vector2(void);

      inline vector2(
         const double ix,
         const double iy
         );

      inline vector2(
         const vector2 &v
         );

   public: //attributes
      
      inline double &operator[](
         const unsigned i
         );
      inline double operator[](
         const unsigned i
         ) const;

      inline unsigned size(void) const;

      double x;
      double y;
};

inline bool operator== (
   const vector2 &a,
   const vector2 &b
   );

inline vector2 operator- (
   const vector2 &a,
   const vector2 &b
   );

inline vector2 operator- (
   const vector2 &a
   );

inline double operator* (
   const vector2 &a,
   const vector2 &b
   );

inline vector2 operator* (
   const double k,
   const vector2 &x
   );

inline vector2 operator* (
   const vector2 &x,
   const double k
   )
{
   return k*x;
}

inline vector2 operator/ (
   const vector2 &x,
   const double k
   );

inline vector2 operator+ (
   const vector2 &x,
   const vector2 &y
   );

inline vector2 &operator +=(
   vector2 &x,
   const vector2 &y
   );

inline vector2 &operator -=(
   vector2 &x,
   const vector2 &y
   );

inline vector2 &operator *=(
   vector2 &x,
   const double k
   );

inline double magnitude(
   const vector2 &v
   );



inline vector2::vector2(void)
{
   //Do nothing
}

inline vector2::vector2(
   const double ix,
   const double iy
   )
   :
   x( ix ),
   y( iy )
{
   //Do nothing
}

inline vector2::vector2(
   const vector2 &v
   )
   :
   x( v.x ),
   y( v.y )
{
}

inline double &vector2::operator[](
   const unsigned i
   )
{
   if( i == 0 )
      return this->x;
   else
      return this->y;
   ;
}

inline double vector2::operator[](
   const unsigned i
   ) const
{
   if( i == 0 )
      return this->x;
   else
      return this->y;
   ;
}

inline unsigned vector2::size(void) const
{
   return 2U;
}

inline bool operator== (
   const vector2 &a,
   const vector2 &b
   )
{
   return a.x == b.x && a.y == b.y;
}   

inline vector2 operator- (
   const vector2 &a,
   const vector2 &b
   )
{
   return vector2(
      a.x - b.x,
      a.y - b.y
      );
}

inline vector2 operator- (
   const vector2 &a
   )
{
   return vector2( -a.x, -a.y );
}

inline double operator* (
   const vector2 &a,
   const vector2 &b
   )
{
   return a.x*b.x + a.y*b.y;
}

inline vector2 operator* (
   const double k,
   const vector2 &v
   )
{
   return vector2(
      v.x * k,
      v.y * k
      );
}

inline vector2 operator+ (
   const vector2 &a,
   const vector2 &b
   )
{
   return vector2(
      a.x + b.x,
      a.y + b.y
      );
}

inline vector2 &operator +=(
   vector2 &a,
   const vector2 &b
   )
{
   a.x += b.x;
   a.y += b.y;
   return a;
}

inline vector2 &operator -=(
   vector2 &a,
   const vector2 &b
   )
{
   a.x -= b.x;
   a.y -= b.y;
   return a;
}

inline vector2 &operator *=(
   vector2 &a,
   const double k
   )
{
   a.x *= k;
   a.y *= k;
   return a;
}

inline vector2 operator/ (
   const vector2 &v,
   const double k
   )
{
   return vector2(
      v.x/k, v.y/k
      );
}

inline double magnitude(
   const vector2 &v
   )
{
   return hypot( v.x, v.y );
}

#endif

Generated at Sun Jul 14 20:38:21 2002 for Mapper by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999