geomtest.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2004-2007 University of Southern California
00006 // Rob Peters <rjpeters at usc dot edu>
00007 //
00008 // created: Thu Oct 28 12:13:08 2004
00009 // commit: $Id: geomtest.cc 10065 2007-04-12 05:54:56Z rjpeters $
00010 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/pkgs/whitebox/geomtest.cc $
00011 //
00012 // --------------------------------------------------------------------
00013 //
00014 // This file is part of GroovX.
00015 //   [http://ilab.usc.edu/rjpeters/groovx/]
00016 //
00017 // GroovX is free software; you can redistribute it and/or modify it
00018 // under the terms of the GNU General Public License as published by
00019 // the Free Software Foundation; either version 2 of the License, or
00020 // (at your option) any later version.
00021 //
00022 // GroovX is distributed in the hope that it will be useful, but
00023 // WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025 // General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License
00028 // along with GroovX; if not, write to the Free Software Foundation,
00029 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00030 //
00032 
00033 #ifndef GROOVX_PKGS_WHITEBOX_GEOMTEST_CC_UTC20050626084022_DEFINED
00034 #define GROOVX_PKGS_WHITEBOX_GEOMTEST_CC_UTC20050626084022_DEFINED
00035 
00036 #include "pkgs/whitebox/geomtest.h"
00037 
00038 #include "geom/txform.h"
00039 
00040 #include "tcl/pkg.h"
00041 
00042 #include "rutz/unittest.h"
00043 
00044 #include "rutz/trace.h"
00045 #include "rutz/debug.h"
00046 GVX_DBG_REGISTER
00047 
00048 namespace
00049 {
00050   using geom::txform;
00051 
00052   double sum_square(const txform& t)
00053   {
00054     double result=0.0;
00055     for (int i = 0; i < 16; ++i)
00056       result += (t[i] * t[i]);
00057     return result;
00058   }
00059 
00060   txform operator-(const txform& t1, const txform& t2)
00061   {
00062     txform r = txform::no_init();
00063     for (int i = 0; i < 16; ++i)
00064       r[i] = t1[i] - t2[i];
00065     return r;
00066   }
00067 
00068   void testInvert()
00069   {
00070     const txform I = txform::identity();
00071 
00072     for (int i = 0; i < 1000; ++i)
00073       {
00074         const txform T = txform::random();
00075         const txform TI = T.inverted();
00076 
00077         const txform M1 = T.mtx_mul(TI); // compute T * inv(T)
00078         const txform M2 = TI.mtx_mul(T); // compute inv(T) * T
00079 
00080         dbg_dump(3, M1);
00081         dbg_dump(3, M2);
00082 
00083         TEST_REQUIRE_APPROX(sum_square(M1 - I), 0.0, 1e-20);
00084         TEST_REQUIRE_APPROX(sum_square(M2 - I), 0.0, 1e-20);
00085       }
00086   }
00087 }
00088 
00089 extern "C"
00090 int Geomtest_Init(Tcl_Interp* interp)
00091 {
00092 GVX_TRACE("Geomtest_Init");
00093 
00094   GVX_PKG_CREATE(pkg, interp, "Geomtest", "4.$Revision: 10065 $");
00095 
00096   DEF_TEST(pkg, testInvert);
00097 
00098   GVX_PKG_RETURN(pkg);
00099 }
00100 
00101 // Need these to avoid dyld errors on Mac OS X
00102 extern "C" int Geomtest_SafeInit(Tcl_Interp*) { return 1; }
00103 
00104 extern "C" int Geomtest_Unload(Tcl_Interp* interp, int /*flags*/)
00105 {
00106 GVX_TRACE("Geomtest_Unload");
00107   return tcl::pkg::destroy_on_unload(interp, "Geomtest");
00108 }
00109 
00110 extern "C" int Geomtest_SafeUnload(Tcl_Interp*, int /*flags*/) { return 1; }
00111 
00112 static const char __attribute__((used)) vcid_groovx_pkgs_whitebox_geomtest_cc_utc20050626084022[] = "$Id: geomtest.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00113 #endif // !GROOVX_PKGS_WHITEBOX_GEOMTEST_CC_UTC20050626084022_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:40 2008 by Doxygen version 1.5.5.