// SurfPolygon_t.cpp // Test SurfPolygon. #include "SurfPolygon.h" #include #include #include "trfutil/TRFMath.h" #include "trfbase/ETrack.h" #include "trfbase/CrossStat.h" #include "trfutil/trfstream.h" #include #include "objstream/StdObjStream.hpp" #include "objstream/ObjData.hpp" #ifndef DEFECT_NO_STDLIB_NAMESPACES using std::cout; using std::cerr; using std::endl; using std::string; using std::sin; using std::cos; using std::ostringstream; using std::istringstream; #endif using namespace trf; using namespace trf::polygon; //********************************************************************** int main( ) { string ok_prefix = "SurfPolygon test (I): "; string error_prefix = "SurfPolygon test (E): "; cout << ok_prefix << "------ Testing component SurfPolygon. ------" << endl; // Make sure assert is enabled. bool assert_flag = false; assert ( ( assert_flag = true, assert_flag ) ); if ( ! assert_flag ) { cerr << "Assert is disabled" << endl; return 1; } //******************************************************************** cout << trf_format; cout << ok_prefix << "Test constructor and get routines." << endl; PairList plist; SurfPolygon bzp( 10.0,plist ); cout << bzp << endl; assert( bzp.get_z() == 10.0 ); //******************************************************************** cout << ok_prefix << "Test type." << endl; assert( bzp.get_type() != 0 ); assert( bzp.get_type() == SurfPolygon::get_static_type() ); //******************************************************************** cout << ok_prefix << "Check cloning." << endl; SurfacePtr psrft ( bzp.new_surface()); SurfacePtr psrf_pure ( bzp.new_pure_surface()); assert( psrft->get_type() == SurfPolygon::get_static_type() ); assert( psrf_pure->get_type() == SurfZPlane::get_static_type() ); SurfPolygonPtr psrf ( (SurfPolygon*)bzp.new_surface()); //******************************************************************** assert( psrf->bound_equal(*psrf) ); cout << ok_prefix << "Equality tests varying parameters." << endl; PairList plist0; plist0.push_back(PairPtr(new Pair(11.,12.))); plist0.push_back(PairPtr(new Pair(12.,13.))); psrf= SurfPolygonPtr( new SurfPolygon(10.,plist0)); PairList plist1; plist1.push_back(PairPtr(new Pair(11.,12.))); plist1.push_back(PairPtr(new Pair(12.,13.))); SurfPolygonPtr psrf1 ( new SurfPolygon( 10.0, plist1)); PairList plist2; plist2.push_back(PairPtr(new Pair(11.,12.))); plist2.push_back(PairPtr(new Pair(12.,13.))); SurfPolygonPtr psrf2 ( new SurfPolygon( 11.0, plist2)); PairList plist3; plist3.push_back(PairPtr(new Pair(11.,12.))); plist3.push_back(PairPtr(new Pair(12.,13.))); plist3.push_back(PairPtr(new Pair(14.,15.))); SurfPolygonPtr psrf3 ( new SurfPolygon( 10.0, plist3 )); PairList plist4; plist4.push_back(PairPtr(new Pair(12.,13.))); plist4.push_back(PairPtr(new Pair(14.,15.))); SurfPolygonPtr psrf4 ( new SurfPolygon( 10.0, plist4)); PairList plist5; plist5.push_back(PairPtr(new Pair(12.,13.))); plist5.push_back(PairPtr(new Pair(11.,12.))); SurfPolygonPtr psrf5 ( new SurfPolygon( 10.0, plist5 )); PairList plist6; plist6.push_back(PairPtr(new Pair(12.,13.))); plist6.push_back(PairPtr(new Pair(11.,12.))); SurfPolygonPtr psrf6 ( new SurfPolygon( 10.0, plist6)); assert( psrf->bound_equal(*psrf1) ); assert( ! psrf->bound_equal(*psrf2) ); assert( ! psrf->bound_equal(*psrf3) ); assert( ! psrf->bound_equal(*psrf4) ); assert( psrf->bound_equal(*psrf5) ); assert( psrf->bound_equal(*psrf6) ); PairList plist7; plist7.push_back(PairPtr(new Pair(5,1))); plist7.push_back(PairPtr(new Pair(1,3))); plist7.push_back(PairPtr(new Pair(7,5))); psrf=SurfPolygonPtr( new SurfPolygon(10.,plist7)); PairList plist8; plist8.push_back(PairPtr(new Pair(7,5))); plist8.push_back(PairPtr(new Pair(1,3))); plist8.push_back(PairPtr(new Pair(5,1))); psrf1=SurfPolygonPtr( new SurfPolygon(10.,plist8)); PairList plist9; plist9.push_back(PairPtr(new Pair(7,5))); plist9.push_back(PairPtr(new Pair(5,1))); plist9.push_back(PairPtr(new Pair(1,3))); psrf2=SurfPolygonPtr( new SurfPolygon(10.,plist9)); assert( psrf->bound_equal(*psrf) ); assert( psrf->bound_equal(*psrf1) ); assert( psrf->bound_equal(*psrf2) ); cout<< *psrf<<'\n'; //******************************************************************** cout << ok_prefix << "Test purity." << endl; assert( ! bzp.is_pure() ); assert( psrf_pure->is_pure() ); //******************************************************************** cout << ok_prefix << "Test crossing status." << endl; cout << bzp << endl; TrackVector tvec; TrackError terr; terr(SurfZPlane::IX,SurfZPlane::IX) = 0.1; terr(SurfZPlane::IY,SurfZPlane::IY) = 0.1; PairList plist10; plist10.push_back(PairPtr(new Pair(5,1))); plist10.push_back(PairPtr(new Pair(1,3))); plist10.push_back(PairPtr(new Pair(7,5))); plist10.push_back(PairPtr(new Pair(8,2))); psrf=SurfPolygonPtr( new SurfPolygon(10.,plist10)); tvec(SurfZPlane::IY) = 2.0; tvec(SurfZPlane::IX) = 5.0; ETrack trk1(psrf,tvec,terr); CrossStat xs = psrf->status(trk1); assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); terr(SurfZPlane::IX,SurfZPlane::IX) = 0.0001; terr(SurfZPlane::IY,SurfZPlane::IY) = 0.0001; PairList plist11; plist11.push_back(PairPtr(new Pair(2,1))); plist11.push_back(PairPtr(new Pair(1,5))); plist11.push_back(PairPtr(new Pair(11,5))); plist11.push_back(PairPtr(new Pair(10,1))); psrf=SurfPolygonPtr( new SurfPolygon(10.,plist11)); tvec(SurfZPlane::IX) = 6.0; tvec(SurfZPlane::IY) = 3.0; ETrack trk2(psrf,tvec,terr); xs = psrf->status(trk2); assert( xs.in_bounds() ); assert( !xs.out_of_bounds() ); terr(SurfZPlane::IX,SurfZPlane::IX) = 1000.; terr(SurfZPlane::IY,SurfZPlane::IY) = 1000.; PairList plist12; plist12.push_back(PairPtr(new Pair(10,10))); plist12.push_back(PairPtr(new Pair(-10,10))); plist12.push_back(PairPtr(new Pair(-10,-10))); plist12.push_back(PairPtr(new Pair(10,-10))); psrf=SurfPolygonPtr( new SurfPolygon(10.,plist12)); tvec(SurfZPlane::IX) = 6.0; tvec(SurfZPlane::IY) = 3.0; ETrack trk3(psrf,tvec,terr); xs = psrf->status(trk3); assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); terr(SurfZPlane::IX,SurfZPlane::IX) = 1.; terr(SurfZPlane::IY,SurfZPlane::IY) = 1.; PairList plist13; plist13.push_back(PairPtr(new Pair(10,10))); plist13.push_back(PairPtr(new Pair(-10,10))); plist13.push_back(PairPtr(new Pair(-10,-10))); plist13.push_back(PairPtr(new Pair(10,-10))); psrf=SurfPolygonPtr( new SurfPolygon(10.,plist13)); tvec(SurfZPlane::IX) = 13.0; tvec(SurfZPlane::IY) = 3.0; ETrack trk7(psrf,tvec,terr); xs = psrf->status(trk7); assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); terr(SurfZPlane::IX,SurfZPlane::IX) = 100.; terr(SurfZPlane::IY,SurfZPlane::IY) = 1.; PairList plist14; plist14.push_back(PairPtr(new Pair(10,10))); plist14.push_back(PairPtr(new Pair(-10,10))); plist14.push_back(PairPtr(new Pair(-10,-10))); plist14.push_back(PairPtr(new Pair(10,-10))); psrf=SurfPolygonPtr( new SurfPolygon(10.,plist14)); tvec(SurfZPlane::IX) = 0.0; tvec(SurfZPlane::IY) = 0.0; ETrack trk8(psrf,tvec,terr); xs = psrf->status(trk8); assert( xs.in_bounds() ); assert( xs.out_of_bounds() ); terr(SurfZPlane::IX,SurfZPlane::IX) = 1.; terr(SurfZPlane::IY,SurfZPlane::IY) = 1.; PairList plist15; plist15.push_back(PairPtr(new Pair(10,10))); plist15.push_back(PairPtr(new Pair(-10,10))); plist15.push_back(PairPtr(new Pair(-10,-10))); plist15.push_back(PairPtr(new Pair(10,-10))); psrf=SurfPolygonPtr( new SurfPolygon(10.,plist15)); tvec(SurfZPlane::IX) = 16.0; tvec(SurfZPlane::IY) = 5.0; ETrack trk4(psrf,tvec,terr); xs = psrf->status(trk4); assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); xs = psrf->status(VTrack(psrf,tvec)); assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); tvec(SurfZPlane::IX) = 5.0; tvec(SurfZPlane::IY) = 5.0; xs = psrf->status(VTrack(psrf,tvec)); assert( xs.in_bounds() ); assert( !xs.out_of_bounds() ); terr(SurfZPlane::IX,SurfZPlane::IX) = 1.e-8; terr(SurfZPlane::IY,SurfZPlane::IY) = 1.e-8; tvec(SurfZPlane::IX) = 16.0; tvec(SurfZPlane::IY) = 5.0; xs = psrf->status(ETrack(psrf,tvec,terr)); assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); terr(SurfZPlane::IX,SurfZPlane::IX) = 1.e-14; terr(SurfZPlane::IY,SurfZPlane::IY) = 1.e-14; tvec(SurfZPlane::IX) = 16.0; tvec(SurfZPlane::IY) = 5.0; xs = psrf->status(ETrack(psrf,tvec,terr)); assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); //******************************************************************** //and now main test; terr(SurfZPlane::IX,SurfZPlane::IX) = 0.0001; terr(SurfZPlane::IY,SurfZPlane::IY) = 0.0001; tvec(SurfZPlane::IX) = 9.9; tvec(SurfZPlane::IY) = 0.0; ETrack trk5(psrf,tvec,terr); PairList plist16; for(int i=0;i<12;i++) { double phi= TWOPI*i/12; plist16.push_back(PairPtr(new Pair(10.*cos(phi),10.*sin(phi)))); } psrf=SurfPolygonPtr( new SurfPolygon(10.,plist16)); xs = psrf->status(trk5); assert( xs.in_bounds() ); assert( !xs.out_of_bounds() ); PairList plist17; for(int i=11;i>=0;i--) { double phi= TWOPI*i/12; plist17.push_back(PairPtr(new Pair(10.*cos(phi),10.*sin(phi)))); } psrf=SurfPolygonPtr( new SurfPolygon(10.,plist17)); terr(SurfZPlane::IX,SurfZPlane::IX) = 0.0001; terr(SurfZPlane::IY,SurfZPlane::IY) = 0.0001; tvec(SurfZPlane::IX) = 0.0; tvec(SurfZPlane::IY) = 10.1; ETrack trk6(psrf,tvec,terr); xs = psrf->status(trk6); assert( !xs.in_bounds() ); assert( xs.out_of_bounds() ); //******************************************************************** ObjTable::register_type(); cout << ok_prefix << "Write object data." << endl; PairList pairs; #define NUMPAIRS 3 double px[NUMPAIRS]={2.3,4.5,5.6}; double py[NUMPAIRS]={3.1,6.2,8.9}; for(int i=0;iget_type() == SurfPolygon::get_static_type() ); assert( pobj->get_z() == 24.6 ); cout<< *pobj << endl; } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }