00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include "collide_util.h"
00008 #include "charm.h"
00009
00010
00011
00012 static void testMapping(CollideGrid3d &map,int axis,
00013 double origin,double size)
00014 {
00015 int m1=map.world2grid(axis,rSeg1d(-1.0e20,origin-0.6*size)).getMax();
00016 int m2=map.world2grid(axis,rSeg1d(-1.0e20,origin-0.4*size)).getMax();
00017 int m3=map.world2grid(axis,rSeg1d(-1.0e20,origin-0.1*size)).getMax();
00018 int e1=map.world2grid(axis,rSeg1d(-1.0e20,origin+0.1*size)).getMax();
00019 int e2=map.world2grid(axis,rSeg1d(-1.0e20,origin+0.4*size)).getMax();
00020 int e3=map.world2grid(axis,rSeg1d(-1.0e20,origin+0.6*size)).getMax();
00021 int e4=map.world2grid(axis,rSeg1d(-1.0e20,origin+0.9*size)).getMax();
00022 int p1=map.world2grid(axis,rSeg1d(-1.0e20,origin+1.1*size)).getMax();
00023 int p2=map.world2grid(axis,rSeg1d(-1.0e20,origin+1.4*size)).getMax();
00024 int p3=map.world2grid(axis,rSeg1d(-1.0e20,origin+1.6*size)).getMax();
00025 int p4=map.world2grid(axis,rSeg1d(-1.0e20,origin+1.9*size)).getMax();
00026 if (m1!=m2 || m1!=m3)
00027 CkAbort("CollideGrid3d::Grid initialization error (m)!\n");
00028 if (e1!=e2 || e1!=e3 || e1!=e4)
00029 CkAbort("CollideGrid3d::Grid initialization error (e)!\n");
00030 if (p1!=p2 || p1!=p3 || p1!=p4)
00031 CkAbort("CollideGrid3d::Grid initialization error (p)!\n");
00032 }
00033
00034 void CollideGrid3d::init(const vector3d &Norigin,
00035 const vector3d &desiredSize)
00036 {
00037 origin=Norigin;
00038 for (int i=0;i<3;i++) {
00039 #if COLLIDE_USE_FLOAT_HACK
00040
00041
00042 double s=(1<<20);
00043 while (s>(1.25*desiredSize[i])) s*=0.5;
00044 ((double*)sizes)[i]=s;
00045 hakShift[i]=(1.5*(1<<23)-0.5)*s-((double*)origin)[i];
00046 float o=(float)(hakShift[i]);
00047 hakStart[i]=*(int *)&o;
00048 #else
00049 sizes[i]=desiredSize[i];
00050 #endif
00051 ((double *)scales)[i]=1.0/((double *)sizes)[i];
00052 testMapping(*this,i,((double *)origin)[i],((double *)sizes)[i]);
00053 }
00054
00055 }
00056
00057 void CollideGrid3d::pup(PUP::er &p) {
00058 p|origin; p|scales; p|sizes;
00059 #if COLLIDE_USE_FLOAT_HACK
00060 p(hakShift,3);
00061 p(hakStart,3);
00062 #endif
00063 }
00064
00065 void CollideGrid3d::print(const CollideLoc3d &g) {
00066 #if !COLLIDE_USE_FLOAT_HACK
00067 const static int hakStart[3]={0,0,0};
00068 #endif
00069 printf("%d,%d,%d",g.x-hakStart[0],g.y-hakStart[1],g.z-hakStart[2]);
00070 }
00071