MOAB: Mesh Oriented datABase
(version 5.4.1)
|
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) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file LineDomainTest.cpp 00028 * \brief UnitTests for LineDomain class 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "UnitUtil.hpp" 00033 #include "MeshDomain1D.hpp" 00034 00035 namespace MBMesquite 00036 { 00037 00038 class LineDomainTest : public CppUnit::TestFixture 00039 { 00040 CPPUNIT_TEST_SUITE( LineDomainTest ); 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( LineDomainTest, "LineDomainTest" ); 00053 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LineDomainTest, "Unit" ); 00054 00055 void LineDomainTest::test_snap_to() 00056 { 00057 const Vector3D base1( 1, 1, 1 ); 00058 const Vector3D dir1( -1, -2, -3 ); 00059 LineDomain dom1( base1, dir1 ); 00060 00061 Vector3D point( 0, 0, 0 ), result( point ); 00062 dom1.snap_to( 0, result ); 00063 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, ( ( result - base1 ) * dir1 ).length(), 00064 1e-6 ); // on the line 00065 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, ( ( point - result ) % dir1 ), 1e-6 ); // moved perp to line 00066 00067 point = Vector3D( 10, 11, 12 ); 00068 result = point; 00069 dom1.snap_to( 0, result ); 00070 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, ( ( result - base1 ) * dir1 ).length(), 00071 1e-6 ); // on the line 00072 CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, ( ( point - result ) % dir1 ), 1e-6 ); // moved perp to line 00073 } 00074 00075 void LineDomainTest::test_arc_length() 00076 { 00077 MsqPrintError err( std::cerr ); 00078 00079 const Vector3D base1( 1, 1, 1 ); 00080 const Vector3D dir1( -1, -2, -3 ); 00081 LineDomain dom1( base1, dir1 ); 00082 00083 double l1 = 1.0, l2 = M_PI; 00084 Vector3D p1 = base1 + l1 / dir1.length() * dir1; 00085 Vector3D p2 = base1 + l2 / dir1.length() * dir1; 00086 double len = dom1.arc_length( p1.to_array(), p2.to_array(), err ); 00087 ASSERT_NO_ERROR( err ); 00088 CPPUNIT_ASSERT_DOUBLES_EQUAL( l2 - l1, len, 1e-6 ); 00089 len = dom1.arc_length( p2.to_array(), p1.to_array(), err ); 00090 ASSERT_NO_ERROR( err ); 00091 CPPUNIT_ASSERT_DOUBLES_EQUAL( l1 - l2, len, 1e-6 ); 00092 } 00093 00094 void LineDomainTest::test_position_from_length() 00095 { 00096 MsqPrintError err( std::cerr ); 00097 00098 const Vector3D base1( 1, 1, 1 ); 00099 const Vector3D dir1( -1, -2, -3 ); 00100 LineDomain dom1( base1, dir1 ); 00101 const Vector3D unit = dir1 / dir1.length(); 00102 double l1 = 1.5; 00103 Vector3D result; 00104 dom1.position_from_length( base1.to_array(), l1, result.to_array(), err ); 00105 ASSERT_NO_ERROR( err ); 00106 CPPUNIT_ASSERT_VECTORS_EQUAL( base1 + l1 * unit, result, 1e-6 ); 00107 00108 double l2 = 3.333; 00109 Vector3D result2; 00110 dom1.position_from_length( result.to_array(), l2, result2.to_array(), err ); 00111 ASSERT_NO_ERROR( err ); 00112 CPPUNIT_ASSERT_VECTORS_EQUAL( result + l2 * unit, result2, 1e-6 ); 00113 } 00114 00115 } // namespace MBMesquite