shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/point_glue.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 * MODULE     : point_glue.hpp
00003 * DESCRIPTION: Glue for points
00004 * COPYRIGHT  : (C) 2007 Bernard Mourrain
00005 *******************************************************************************
00006 * This software falls under the GNU general public license and comes WITHOUT
00007 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00008 * If you don't have this file, write to the Free Software Foundation, Inc.,
00009 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00010 ******************************************************************************/
00011 #ifndef __mmx_shape_point_glue_hpp
00012 #define __mmx_shape_point_glue_hpp
00013 #include <basix/glue.hpp>
00014 #include <shape/axel_glue.hpp>
00015 #include <shape/point.hpp>
00016 
00017 #define TMPL   template<class C>
00018 #define Point  shape::point<C>
00019 #define Scalar C
00020 #define Vector vector<Scalar>
00021 
00022 
00023 namespace mmx {
00024   namespace shape {
00025 
00026     TMPL inline bool operator ==(const Point& v1, const Point& v2) {return true;}
00027     TMPL inline bool operator !=(const Point& v1, const Point& v2) {return !(v1==v2);}
00028     TMPL inline bool exact_eq(const Point& v1, const Point& v2) {return v1==v2;}
00029     TMPL inline bool exact_neq(const Point& v1, const Point& v2) {return v1!=v2;}
00030     
00031     TMPL inline unsigned hash (const Point& v) 
00032     {
00033       register unsigned i, h= 214365, n=1;
00034       for (i=0; i<n; i++) h= (h<<1) ^ (h<<5) ^ (h>>27) ;//^ hash(v[i]);
00035       return h;
00036     }
00037     TMPL inline unsigned exact_hash (const Point& m) {return hash(m);}
00038     TMPL inline unsigned soft_hash (const Point& m) {return hash(m);}
00039 
00040     TMPL inline syntactic flatten (const Point& p) {
00041       vector<syntactic> v;
00042       v<<mmx::flatten(p[0]);
00043       v<<mmx::flatten(p[1]);
00044       v<<mmx::flatten(p[2]);
00045       
00046       return mmx::flatten(v);
00047     }
00048   }
00049   //-------------------------------------------------------------------- 
00050 
00051   TMPL Point shape_point_tuple(const vector<C>& v) {
00052     Point p;
00053     for(unsigned i=0;i<N(v) && i<3; i++)
00054       p[i]=v[i];
00055     return p;
00056   }
00057 
00058   TMPL vector<C> operator-(const Point& p1, const Point& p2){
00059     Vector res((C)0,3);
00060     for(unsigned i=0;i<3; i++) res[i]=p1[i]-p2[i];
00061     return res;
00062   }
00063 
00064   TMPL Point  operator+(const Point& p, const vector<C>& v) {
00065     Point res;
00066     for(unsigned i=0;i<3; i++) res[i]=p[i]+v[i];
00067     return res;
00068   }
00069 #undef TMPL
00070 #undef Point
00071 //====================================================================
00072 } // namespace mmx
00073 #endif // __mmx_point_glue_hpp