MOAB: Mesh Oriented datABase  (version 5.3.0)
CircleDomainTest.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2010 Sandia National Laboratories.  Developed at the
00005     University of Wisconsin--Madison under SNL contract number
00006     624796.  The U.S. Government and the University of Wisconsin
00007     retain certain rights to this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     (2010) kraftche@cae.wisc.edu
00024 
00025   ***************************************************************** */
00026 
00027 /** \file CircleDomainTest.cpp
00028  *  \brief UnitTests for CircleDomain class
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "UnitUtil.hpp"
00033 #include "MeshDomain1D.hpp"
00034 
00035 namespace MBMesquite
00036 {
00037 
00038 class CircleDomainTest : public CppUnit::TestFixture
00039 {
00040     CPPUNIT_TEST_SUITE( CircleDomainTest );
00041     CPPUNIT_TEST( test_snap_to );
00042     CPPUNIT_TEST( test_arc_length );
00043     CPPUNIT_TEST( test_position_from_length );
00044     CPPUNIT_TEST_SUITE_END();
00045 
00046   public:
00047     void test_snap_to();
00048     void test_arc_length();
00049     void test_position_from_length();
00050 };
00051 
00052 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CircleDomainTest, "CircleDomainTest" );
00053 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CircleDomainTest, "Unit" );
00054 
00055 void CircleDomainTest::test_snap_to()
00056 {
00057     Vector3D origin( 0, 0, 0 );
00058     Vector3D z( 0, 0, 1 );
00059     double rad1 = 4.0 / 3.0;
00060     CircleDomain dom1( origin, z, rad1 );
00061     Vector3D pt( 1, 0, 0 );
00062     dom1.snap_to( 0, pt );
00063     CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( rad1, 0, 0 ), pt, 1e-6 );
00064     Vector3D a = Vector3D( 1, 2, 3 );
00065     pt         = a;
00066     dom1.snap_to( 0, pt );
00067     a = Vector3D( 1, 2, 0 );
00068     a *= rad1 / a.length();
00069     CPPUNIT_ASSERT_VECTORS_EQUAL( a, pt, 1e-6 );
00070 
00071     Vector3D some_pt( 5, -1, 6 );
00072     Vector3D some_dir( -5, -4, 1 );
00073     double rad2 = 1.0;
00074     CircleDomain dom2( some_pt, some_dir, rad2 );
00075 
00076     a  = Vector3D( 0, 0, 0 );
00077     pt = a;
00078     dom2.snap_to( 0, pt );
00079     CPPUNIT_ASSERT_DOUBLES_EQUAL( rad2, ( pt - some_pt ).length(), 1e-6 );   // rad from center
00080     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, ( pt - some_pt ) % some_dir, 1e-6 );  // in plane
00081     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, ( ( pt - some_pt ) * ( a - some_pt ) ) % some_dir,
00082                                   1e-6 );  // correct direction from center
00083 
00084     a  = Vector3D( 0, -1, -2 );
00085     pt = a;
00086     dom2.snap_to( 0, pt );
00087     CPPUNIT_ASSERT_DOUBLES_EQUAL( rad2, ( pt - some_pt ).length(), 1e-6 );   // rad from center
00088     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, ( pt - some_pt ) % some_dir, 1e-6 );  // in plane
00089     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, ( ( pt - some_pt ) * ( a - some_pt ) ) % some_dir,
00090                                   1e-6 );  // correct direction from center
00091 }
00092 
00093 void CircleDomainTest::test_arc_length()
00094 {
00095     MsqPrintError err( std::cerr );
00096 
00097     Vector3D origin( 0, 0, 0 );
00098     Vector3D z( 0, 0, 1 );
00099     double rad1 = 4.0 / 3.0;
00100     CircleDomain dom1( origin, z, rad1 );
00101 
00102     Vector3D xp = Vector3D( 1, 0, 0 );
00103     Vector3D xn = Vector3D( -1, 0, 0 );
00104     Vector3D yp = Vector3D( 0, 1, 0 );
00105 
00106     double len = dom1.arc_length( xp.to_array(), yp.to_array(), err );
00107     ASSERT_NO_ERROR( err );
00108     CPPUNIT_ASSERT_DOUBLES_EQUAL( rad1 * M_PI * 0.5, len, 1e-6 );
00109 
00110     len = dom1.arc_length( xp.to_array(), xn.to_array(), err );
00111     ASSERT_NO_ERROR( err );
00112     CPPUNIT_ASSERT_DOUBLES_EQUAL( rad1 * M_PI, len, 1e-6 );
00113 
00114     len = dom1.arc_length( yp.to_array(), xp.to_array(), err );
00115     ASSERT_NO_ERROR( err );
00116     CPPUNIT_ASSERT_DOUBLES_EQUAL( -rad1 * M_PI * 0.5, len, 1e-6 );
00117 
00118     len = dom1.arc_length( ( xp + z ).to_array(), yp.to_array(), err );
00119     ASSERT_NO_ERROR( err );
00120     CPPUNIT_ASSERT_DOUBLES_EQUAL( rad1 * M_PI * 0.5, len, 1e-6 );
00121 
00122     len = dom1.arc_length( xp.to_array(), ( yp + z ).to_array(), err );
00123     ASSERT_NO_ERROR( err );
00124     CPPUNIT_ASSERT_DOUBLES_EQUAL( rad1 * M_PI * 0.5, len, 1e-6 );
00125 
00126     Vector3D center( -1, -2, -1 );
00127     Vector3D normal( -2, -1, -2 );
00128     double rad = 1.5;
00129     CircleDomain dom2( center, normal, rad );
00130 
00131     Vector3D v( 1, 0, 0 );
00132     v = v * normal;
00133     v *= rad / v.length();
00134     v += center;
00135     len = dom2.arc_length( v.to_array(), v.to_array(), err );
00136     ASSERT_NO_ERROR( err );
00137     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, len, 1e-6 );
00138 }
00139 
00140 void CircleDomainTest::test_position_from_length()
00141 {
00142     MsqPrintError err( std::cerr );
00143 
00144     Vector3D origin( 0, 0, 0 );
00145     Vector3D z( 0, 0, 1 );
00146     double rad1 = 4.0 / 3.0;
00147     CircleDomain dom1( origin, z, rad1 );
00148 
00149     Vector3D xp = Vector3D( 1, 0, 0 );
00150     Vector3D xn = Vector3D( -1, 0, 0 );
00151     Vector3D yp = Vector3D( 0, 1, 0 );
00152 
00153     const double qc = 0.5 * rad1 * M_PI;
00154 
00155     Vector3D result;
00156     dom1.position_from_length( xp.to_array(), qc, result.to_array(), err );
00157     ASSERT_NO_ERROR( err );
00158     CPPUNIT_ASSERT_VECTORS_EQUAL( yp * rad1, result, 1e-6 );
00159 
00160     dom1.position_from_length( xp.to_array(), 2 * qc, result.to_array(), err );
00161     ASSERT_NO_ERROR( err );
00162     CPPUNIT_ASSERT_VECTORS_EQUAL( xn * rad1, result, 1e-6 );
00163 
00164     dom1.position_from_length( yp.to_array(), -qc, result.to_array(), err );
00165     ASSERT_NO_ERROR( err );
00166     CPPUNIT_ASSERT_VECTORS_EQUAL( xp * rad1, result, 1e-6 );
00167 
00168     dom1.position_from_length( ( xp + z ).to_array(), qc, result.to_array(), err );
00169     ASSERT_NO_ERROR( err );
00170     CPPUNIT_ASSERT_VECTORS_EQUAL( yp * rad1, result, 1e-6 );
00171 
00172     Vector3D center( -1, -2, -1 );
00173     Vector3D normal( -2, -1, -2 );
00174     double rad2 = 1.5;
00175     CircleDomain dom2( center, normal, rad2 );
00176 
00177     Vector3D v( 1, 0, 0 );
00178     v = v * normal;
00179     v *= rad2 / v.length();
00180     v += center;
00181     dom2.position_from_length( v.to_array(), 0.0, result.to_array(), err );
00182     ASSERT_NO_ERROR( err );
00183     CPPUNIT_ASSERT_VECTORS_EQUAL( v, result, 1e-6 );
00184 }
00185 
00186 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines