00001
00002
00003
00004 #ifndef GENERAL_COORDS_TEMPLATES_NOSPECIAL_H
00005 #define GENERAL_COORDS_TEMPLATES_NOSPECIAL_H
00006
00007 #include "is-specialized.h"
00008 #include "geometric-point-traits.h"
00009
00010 typedef double component;
00011
00012 template<unsigned N>
00013 class coordN_ns {
00014 public:
00015 typedef unsigned index;
00016 typedef coordN_ns self;
00017
00018
00019 coordN_ns() {}
00020 coordN_ns(const component& x) { for(index i=0; i<N; i++) X[i] = x;}
00021 coordN_ns(const component Y[]) { for(index i=0; i<N; i++) X[i] = Y[i];}
00022 coordN_ns(const self& rhs) { for(index i=0; i<N; i++) X[i] = rhs.X[i];}
00023 self& operator=(const self& rhs)
00024 {
00025
00026 for(index i=0; i<N; i++)
00027 X[i] = rhs.X[i];
00028 return *this;
00029 }
00030
00031 ~coordN_ns() {}
00032 const component& operator[](index i) const { return X[i];}
00033 component& operator[](index i) { return X[i];}
00034 self& operator+=(const self& rhs) { for(index i=0; i<N; i++) X[i] += rhs.X[i]; return *this; }
00035 self& operator-=(const self& rhs) { for(index i=0; i<N; i++) X[i] -= rhs.X[i]; return *this; }
00036 self& operator*=(const component& rhs) { for(index i=0; i<N; i++) X[i] *= rhs; return *this; }
00037 self& operator/=(const component& rhs) { for(index i=0; i<N; i++) X[i] /= rhs; return *this; }
00038
00039 static self origin() { return self(component(0));}
00040 static index dim() { return N;}
00041 private:
00042 component X[N];
00043 };
00044
00045
00046 template<unsigned K, unsigned L>
00047 inline coordN_ns<K+L> operator,(const coordN_ns<K>& PK, const coordN_ns<L>& PL)
00048 {
00049 coordN_ns<K+L> result;
00050 for(unsigned k = 1; k <= K; k++)
00051 result[k] = PK[k];
00052 for(unsigned l = 1; l <= L; l++)
00053 result[l+K] = PL[l];
00054 return result;
00055 }
00056
00057
00058 template<unsigned N>
00059 inline coordN_ns<N> operator+(const coordN_ns<N>& lhs, const coordN_ns<N>& rhs)
00060 { coordN_ns<N> tmp(lhs); return (tmp+= rhs);}
00061
00062 template<unsigned N>
00063 inline coordN_ns<N> operator-(const coordN_ns<N>& lhs, const coordN_ns<N>& rhs)
00064 { coordN_ns<N> tmp(lhs); tmp-= rhs; return tmp;}
00065
00066 template<unsigned N>
00067 inline coordN_ns<N> operator*(const coordN_ns<N>& lhs, const component& rhs)
00068 { coordN_ns<N> tmp(lhs); tmp *= rhs; return tmp; }
00069
00070 template<unsigned N>
00071 inline coordN_ns<N> operator*( const component& lhs, const coordN_ns<N>& rhs)
00072 { return rhs*lhs;}
00073
00074 template<unsigned N>
00075 inline coordN_ns<N> operator/(const coordN_ns<N>& lhs, const component& rhs)
00076 { coordN_ns<N> tmp(lhs); tmp /= rhs; return tmp; }
00077
00078
00079
00080 template<unsigned N>
00081 ostream& operator<<(ostream& out, const coordN_ns<N>& P)
00082 {
00083 for(unsigned i = 0; i<= N-1; i++)
00084 out << P[i] << ' ';
00085 return out;
00086 }
00087
00088 template<unsigned N>
00089 istream& operator>>(istream& in, coordN_ns<N>& P)
00090 {
00091 for(unsigned i = 0; i<= N-1; i++)
00092 in >> P[i];
00093 return in;
00094 }
00095
00096
00097 template<unsigned N>
00098 struct point_traits_for_coordN_ns : public point_traits_default {
00099 typedef coordN_ns<N> point_t;
00100 static int LowerIndex(const point_t&) { return 0;}
00101 static int UpperIndex(const point_t&) { return N-1;}
00102 static int Dimension(const point_t&) { return N;}
00103
00104 static int Dimension() { return N;}
00105 static fixed_size_tag point_size_tag() { return fixed_size_tag();}
00106
00107 static point_t origin() { return point_t(0.0);}
00108
00109 typedef double component_type;
00110
00111
00112 };
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 struct point_traits<coordN_ns<2> > : public point_traits_for_coordN_ns<2> {};
00123 struct point_traits<coordN_ns<3> > : public point_traits_for_coordN_ns<3> {};
00124
00125 #endif