Go to Overview over all GrAL packages.
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Geometry/coords_2_special.h

Go to the documentation of this file.
00001 #ifndef NMWR_GB_COORDS_2_SPECIALIZATION_H
00002 #define NMWR_GB_COORDS_2_SPECIALIZATION_H
00003 
00004 
00005 // $LICENSE
00006 
00007 
00008 //----------------------------------------------------------------
00009 // 
00010 // to be included by coord.h
00011 // specialization of coordN<N> for N = 2
00012 //
00013 //----------------------------------------------------------------
00014 
00015 template<unsigned N> class coordN;
00016 
00017 class coordN<2> {
00018 public:
00019   typedef unsigned index;
00020   typedef coordN<2> self;
00021   typedef double   component;
00022 
00023   coordN() {}
00024   coordN(const component& x) { X[0] = X[1] = x;}
00025   coordN(const component x1, const component x2) { X[0] = x1; X[1] = x2;}
00026   coordN(const self& rhs)    { X[0] = rhs.X[0]; X[1] = rhs.X[1];}
00027   self& operator=(const self& rhs)
00028   { 
00029     //if(this != & rhs){
00030     X[0] = rhs.X[0]; X[1] = rhs.X[1];
00031     //}   
00032     return *this;
00033   }
00034 
00035   ~coordN() {}
00036   
00037   component  operator[](index i) const { _c(i); return X[--i];}
00038   component& operator[](index i)       { _c(i); return X[--i];}
00039   component  operator()(index i) const { _c(i); return X[--i];}
00040   component& operator()(index i)       { _c(i); return X[--i];}
00041 
00042   void _c(index i) const { REQUIRE ( (1 <= i && i <= 2), "i = " << i << '\n',1);}
00043 
00044  
00045   self& operator+=(const self& rhs) { X[0] += rhs.X[0];X[1] += rhs.X[1]; return *this; }
00046   self& operator-=(const self& rhs) { X[0] -= rhs.X[0];X[1] -= rhs.X[1]; return *this; }
00047   self& operator*=(const component& rhs) { X[0] *= rhs;X[1] *= rhs; return *this; }
00048   self& operator/=(const component& rhs) { X[0] /= rhs;X[1] /= rhs; return *this; }
00049   
00050   friend inline self operator+(const self& ls, const self& rs)
00051   {  return self(ls.X[0]+rs.X[0], ls.X[1]+rs.X[1]);}
00052   friend inline self operator-(const self& ls, const self& rs)
00053   {  return self(ls.X[0]-rs.X[0], ls.X[1]-rs.X[1]);}
00054 
00055   static self origin() { return self(component(0));}
00056   static self Origin() { return self(component(0));}
00057   static index dim()   { return 2;}
00058 private:
00059   component X[2];
00060 };
00061 
00062 
00063 template<class T> struct is_specialized;
00064 
00065 template<>
00066 struct is_specialized<coordN<2> > {
00067   static bool specialized() { return true;}
00068   static const char* name() { return "coordN<2>";}
00069 };
00070 
00071 #endif

Copyright (c) Guntram Berti 1997-2002. See the GrAL Homepage for up-to-date information.

Generated at Tue Feb 26 15:57:26 2002 for Geometry by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000