// // $Id: CylindricalSurface_t.cpp,v 1.8 2000/05/12 20:29:34 hobbs Exp $ // // File: CylindricalSurface_t.cpp // Purpose: Component test for CylindricalSurface.cpp // Created: 02-Sep-1999 hobbs // // $Revision: 1.8 $ // // // Include files #include #include #include #include #include #include using namespace std; using namespace dgs; class testPlane: public Plane { public: testPlane(const double dx, const double dy): Plane(dx,dy) {} const list get_children() { return no_kids; } private: list no_kids; }; class testCylindricalSurface: public CylindricalSurface { public: testCylindricalSurface(): CylindricalSurface() {} testCylindricalSurface(const double r, const double zhalf): CylindricalSurface(r,zhalf) {} testCylindricalSurface(const double r, const double zhalf, list kids): CylindricalSurface(r,zhalf), _kids(kids) {} const list get_children() { return _kids; } private: list _kids; }; //---------------------------------------------------------------------------- int main() { int errcode = 0; // Test default constructor testCylindricalSurface t1; if( (t1.get_radius()==0.0) && (t1.get_zhalf()==0.0) && (t1.get_children().size()==0) ) cout << "Passed default constructor tests" << endl; else { cout << "Error with default constructor" << endl; errcode += 1; } // Test the real constructor testCylindricalSurface t2(1.0,15.0); if( (t2.get_radius()==1.0) && (t2.get_zhalf()==15.0) && (t2.get_children().size()==0) ) cout << "Passed user constructor tests" << endl; else { cout << "Error with user constructor: Radius=" << t2.get_radius() << ", ZHalf=" << t2.get_zhalf() << ", Child count = " << t2.get_children().size() << endl; errcode += 2; } // Add some children GeometryXform xnull; testPlane k1(1.0,2.0),k2(3.0,4.0); // These must be kept 'til the end... list kids; kids.push_back(&k1); kids.push_back(&k2); double r0=1.0; testCylindricalSurface t3(r0,15.0,kids); list geKids = t3.get_children(); if( geKids.size() != 2 ) { cout << "Error in children list length" << endl; errcode += 4; } else { list::iterator i=geKids.begin(); bool pass=true; while( i != geKids.end() ) { if( (*i)->get_position() != xnull ) { pass =false; cout << "Error in unpositioned childs default position" << endl; } ++i; } if( !pass ) errcode += 4; } // Position the children double tphi=1.2345; list::iterator i=geKids.begin(); bool pass=true; while( i != geKids.end() ) { if( i==geKids.begin() ) { t3.position_child_at(CylindricalCoordinate(r0,0.0,0.0),**i); if( (*i)->get_position() != GeometryXform(r0,0.0,0.0,halfpi,halfpi,0.0) ) { pass = false; cout << "Error positioning first child" << endl; } } else { t3.set_tangent_Xform(Rotation(0.,0.,0.)); t3.position_child_at(CylindricalCoordinate(r0,tphi,0.0),**i); if( (*i)->get_position() != // GeometryXform(r0*cos(tphi),r0*sin(tphi),0.0,PI/2.0+tphi,PI/2.0,0.0) ) GeometryXform(r0*cos(tphi),r0*sin(tphi),0.0,tphi,0.0,0.0) ) { pass = false; cout << "Error positioning second child" << endl; } } ++i; } if( !pass ) errcode += 8; // Test resize t3.resize(0.1,-0.1); i=geKids.begin(); pass=true; while( i != geKids.end() ) { if( i==geKids.begin() ) { if( (*i)->get_position() != GeometryXform(r0+0.1,0.0,0.0,halfpi,halfpi,0.0) ) { pass = false; cout << "Resize Error, position of first child" << endl; cout << " Expect: " << GeometryXform(r0+0.1,0.0,0.0,0.0,0.0,0.0) << endl; cout << " Got : " << (*i)->get_position() << endl; } } else { if( (*i)->get_position() != // GeometryXform((r0+0.1)*cos(tphi),(r0+0.1)*sin(tphi),0.0,PI/2.0+tphi,PI/2.0,0.0) ) GeometryXform((r0+0.1)*cos(tphi),(r0+0.1)*sin(tphi),0.0,tphi,0.0,0.0) ) { pass = false; cout << "Resize Error, position of second child" << endl; } } ++i; } if( !pass ) errcode += 16; return errcode; }