vectwotest.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2002-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Mon May 12 17:57:12 2003
00010 // commit: $Id: vectwotest.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/pkgs/whitebox/vectwotest.cc $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_PKGS_WHITEBOX_VECTWOTEST_CC_UTC20050626084022_DEFINED
00035 #define GROOVX_PKGS_WHITEBOX_VECTWOTEST_CC_UTC20050626084022_DEFINED
00036 
00037 #include "pkgs/whitebox/vectwotest.h"
00038 
00039 #include "geom/vec2.h"
00040 
00041 #include "tcl/pkg.h"
00042 
00043 #include "rutz/unittest.h"
00044 
00045 #include "rutz/debug.h"
00046 GVX_DBG_REGISTER
00047 #include "rutz/trace.h"
00048 
00049 namespace
00050 {
00051   using namespace geom;
00052 
00053   void testAbs()
00054   {
00055     vec2i v(-1, 3);
00056     TEST_REQUIRE(v.abs() == vec2i(1, 3));
00057   }
00058 
00059   void testLength()
00060   {
00061     vec2d v(3.0, 4.0);
00062     TEST_REQUIRE(v.length() == 5.0);
00063   }
00064 
00065   void testSetLength()
00066   {
00067     vec2d v(0.6, 0.8);
00068     v.set_length(5.0);
00069     TEST_REQUIRE_APPROX(v.length(), 5.0, 1e-40);
00070     TEST_REQUIRE(v == vec2d(3.0, 4.0));
00071   }
00072 
00073   void testSetPolarRad()
00074   {
00075     vec2d v;
00076     v.set_polar_rad(2.0, M_PI / 4.0);
00077     TEST_REQUIRE_APPROX(v.x(), 1.41421, 1e-5);
00078     TEST_REQUIRE_APPROX(v.y(), 1.41421, 1e-5);
00079   }
00080 
00081   void testThetaDeg()
00082   {
00083     TEST_REQUIRE_APPROX(vec2d( 1.0,  0.0).theta_deg(), 0.0,       1e-20);
00084     TEST_REQUIRE_APPROX(vec2d( 1.0,  0.5).theta_deg(), 26.5651,   1e-4);
00085     TEST_REQUIRE_APPROX(vec2d( 1.0,  1.0).theta_deg(), 45.0,      1e-20);
00086     TEST_REQUIRE_APPROX(vec2d( 0.5,  1.0).theta_deg(), 63.4349,   1e-4);
00087     TEST_REQUIRE_APPROX(vec2d( 0.0,  1.0).theta_deg(), 90.0,      1e-20);
00088     TEST_REQUIRE_APPROX(vec2d(-0.5,  1.0).theta_deg(), 116.5651,  1e-4);
00089     TEST_REQUIRE_APPROX(vec2d(-1.0,  1.0).theta_deg(), 135.0,     1e-20);
00090     TEST_REQUIRE_APPROX(vec2d(-1.0,  0.5).theta_deg(), 153.4349,  1e-4);
00091     TEST_REQUIRE_APPROX(vec2d(-1.0,  0.0).theta_deg(), 180.0,     1e-20);
00092     TEST_REQUIRE_APPROX(vec2d(-1.0, -0.5).theta_deg(), -153.4349, 1e-4);
00093     TEST_REQUIRE_APPROX(vec2d(-1.0, -1.0).theta_deg(), -135.0,    1e-20);
00094     TEST_REQUIRE_APPROX(vec2d(-0.5, -1.0).theta_deg(), -116.5651, 1e-4);
00095     TEST_REQUIRE_APPROX(vec2d(-0.0, -1.0).theta_deg(), -90.0,     1e-20);
00096     TEST_REQUIRE_APPROX(vec2d( 0.5, -1.0).theta_deg(), -63.4349,  1e-4);
00097     TEST_REQUIRE_APPROX(vec2d( 1.0, -1.0).theta_deg(), -45.0,     1e-20);
00098     TEST_REQUIRE_APPROX(vec2d( 1.0, -0.5).theta_deg(), -26.5651,  1e-4);
00099   }
00100 
00101   void testSetThetaDeg()
00102   {
00103     { vec2d v(1, 0); v.set_theta_deg(0.0);    TEST_REQUIRE_APPROX(v.x(),  1.000000, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  0.000000, 1e-4); }
00104     { vec2d v(1, 0); v.set_theta_deg(22.5);   TEST_REQUIRE_APPROX(v.x(),  0.923880, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  0.382683, 1e-4); }
00105     { vec2d v(1, 0); v.set_theta_deg(45.0);   TEST_REQUIRE_APPROX(v.x(),  0.707107, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  0.707107, 1e-4); }
00106     { vec2d v(1, 0); v.set_theta_deg(67.5);   TEST_REQUIRE_APPROX(v.x(),  0.382683, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  0.923880, 1e-4); }
00107     { vec2d v(1, 0); v.set_theta_deg(90.0);   TEST_REQUIRE_APPROX(v.x(),  0.000000, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  1.000000, 1e-4); }
00108     { vec2d v(1, 0); v.set_theta_deg(112.5);  TEST_REQUIRE_APPROX(v.x(), -0.382683, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  0.923880, 1e-4); }
00109     { vec2d v(1, 0); v.set_theta_deg(135.0);  TEST_REQUIRE_APPROX(v.x(), -0.707107, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  0.707107, 1e-4); }
00110     { vec2d v(1, 0); v.set_theta_deg(157.5);  TEST_REQUIRE_APPROX(v.x(), -0.923880, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  0.382683, 1e-4); }
00111     { vec2d v(1, 0); v.set_theta_deg(180.0);  TEST_REQUIRE_APPROX(v.x(), -1.000000, 1e-4);   TEST_REQUIRE_APPROX(v.y(),  0.000000, 1e-4); }
00112     { vec2d v(1, 0); v.set_theta_deg(202.5);  TEST_REQUIRE_APPROX(v.x(), -0.923880, 1e-4);   TEST_REQUIRE_APPROX(v.y(), -0.382683, 1e-4); }
00113     { vec2d v(1, 0); v.set_theta_deg(225.0);  TEST_REQUIRE_APPROX(v.x(), -0.707107, 1e-4);   TEST_REQUIRE_APPROX(v.y(), -0.707107, 1e-4); }
00114     { vec2d v(1, 0); v.set_theta_deg(247.5);  TEST_REQUIRE_APPROX(v.x(), -0.382683, 1e-4);   TEST_REQUIRE_APPROX(v.y(), -0.923880, 1e-4); }
00115     { vec2d v(1, 0); v.set_theta_deg(270.0);  TEST_REQUIRE_APPROX(v.x(),  0.000000, 1e-4);   TEST_REQUIRE_APPROX(v.y(), -1.000000, 1e-4); }
00116     { vec2d v(1, 0); v.set_theta_deg(292.5);  TEST_REQUIRE_APPROX(v.x(),  0.382683, 1e-4);   TEST_REQUIRE_APPROX(v.y(), -0.923880, 1e-4); }
00117     { vec2d v(1, 0); v.set_theta_deg(315.0);  TEST_REQUIRE_APPROX(v.x(),  0.707107, 1e-4);   TEST_REQUIRE_APPROX(v.y(), -0.707107, 1e-4); }
00118     { vec2d v(1, 0); v.set_theta_deg(337.5);  TEST_REQUIRE_APPROX(v.x(),  0.923880, 1e-4);   TEST_REQUIRE_APPROX(v.y(), -0.382683, 1e-4); }
00119   }
00120 }
00121 
00122 extern "C"
00123 int Vectwotest_Init(Tcl_Interp* interp)
00124 {
00125 GVX_TRACE("Vectwotest_Init");
00126 
00127   // Package can't be named "vec2test" because Tcl doesn't like numerals in
00128   // package names
00129   GVX_PKG_CREATE(pkg, interp, "Vectwotest", "4.$Revision: 10065 $");
00130 
00131   DEF_TEST(pkg, testAbs);
00132   DEF_TEST(pkg, testLength);
00133   DEF_TEST(pkg, testSetLength);
00134   DEF_TEST(pkg, testSetPolarRad);
00135   DEF_TEST(pkg, testThetaDeg);
00136   DEF_TEST(pkg, testSetThetaDeg);
00137 
00138   GVX_PKG_RETURN(pkg);
00139 }
00140 
00141 // Need these to avoid dyld errors on Mac OS X
00142 extern "C" int Vectwotest_SafeInit(Tcl_Interp*) { return 1; }
00143 
00144 extern "C" int Vectwotest_Unload(Tcl_Interp* interp, int /*flags*/)
00145 {
00146 GVX_TRACE("Vectwotest_Unload");
00147   return tcl::pkg::destroy_on_unload(interp, "Vectwotest");
00148 }
00149 
00150 extern "C" int Vectwotest_SafeUnload(Tcl_Interp*, int /*flags*/) { return 1; }
00151 
00152 static const char __attribute__((used)) vcid_groovx_pkgs_whitebox_vectwotest_cc_utc20050626084022[] = "$Id: vectwotest.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00153 #endif // !GROOVX_PKGS_WHITEBOX_VECTWOTEST_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.