00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef WGRIDTRANSFORMORTHO_TEST_H
00026 #define WGRIDTRANSFORMORTHO_TEST_H
00027
00028 #include <cstdio>
00029 #include <sstream>
00030 #include <string>
00031 #include <vector>
00032
00033 #include <boost/shared_ptr.hpp>
00034
00035 #include <cxxtest/TestSuite.h>
00036
00037 #include "../../common/exceptions/WPreconditionNotMet.h"
00038
00039 #include "../WGridTransformOrtho.h"
00040
00041
00042
00043
00044 class WGridTransformTest : public CxxTest::TestSuite
00045 {
00046 public:
00047
00048
00049
00050
00051 void testInstantiation()
00052 {
00053 {
00054 TS_ASSERT_THROWS_NOTHING( WGridTransformOrtho v() );
00055 WGridTransformOrtho v;
00056 TS_ASSERT_EQUALS( v.getOffsetX(), 1.0 );
00057 TS_ASSERT_EQUALS( v.getOffsetY(), 1.0 );
00058 TS_ASSERT_EQUALS( v.getOffsetZ(), 1.0 );
00059 TS_ASSERT_EQUALS( v.getUnitDirectionX(), WVector3d( 1.0, 0.0, 0.0 ) );
00060 TS_ASSERT_EQUALS( v.getUnitDirectionY(), WVector3d( 0.0, 1.0, 0.0 ) );
00061 TS_ASSERT_EQUALS( v.getUnitDirectionZ(), WVector3d( 0.0, 0.0, 1.0 ) );
00062 TS_ASSERT_EQUALS( v.getDirectionX(), WVector3d( 1.0, 0.0, 0.0 ) );
00063 TS_ASSERT_EQUALS( v.getDirectionY(), WVector3d( 0.0, 1.0, 0.0 ) );
00064 TS_ASSERT_EQUALS( v.getDirectionZ(), WVector3d( 0.0, 0.0, 1.0 ) );
00065 TS_ASSERT_EQUALS( v.getOrigin(), WVector3d( 0.0, 0.0, 0.0 ) );
00066 }
00067 {
00068 TS_ASSERT_THROWS_NOTHING( WGridTransformOrtho v( 2.2, 3.3, -1.0 ) );
00069 TS_ASSERT_THROWS( WGridTransformOrtho v( 0.0, 0.0, 1.0 ), WPreconditionNotMet );
00070 TS_ASSERT_THROWS( WGridTransformOrtho v( 0.0, 2.0, 1.0 ), WPreconditionNotMet );
00071 TS_ASSERT_THROWS( WGridTransformOrtho v( 1.0, 1.0, 0.0 ), WPreconditionNotMet );
00072 }
00073 {
00074 WGridTransformOrtho v( 2.2, 3.3, -1.0 );
00075 TS_ASSERT_EQUALS( v.getOffsetX(), 2.2 );
00076 TS_ASSERT_EQUALS( v.getOffsetY(), 3.3 );
00077 TS_ASSERT_EQUALS( v.getOffsetZ(), 1.0 );
00078 TS_ASSERT_EQUALS( v.getUnitDirectionX(), WVector3d( 1.0, 0.0, 0.0 ) );
00079 TS_ASSERT_EQUALS( v.getUnitDirectionY(), WVector3d( 0.0, 1.0, 0.0 ) );
00080 TS_ASSERT_EQUALS( v.getUnitDirectionZ(), WVector3d( 0.0, 0.0, -1.0 ) );
00081 TS_ASSERT_EQUALS( v.getDirectionX(), WVector3d( 2.2, 0.0, 0.0 ) );
00082 TS_ASSERT_EQUALS( v.getDirectionY(), WVector3d( 0.0, 3.3, 0.0 ) );
00083 TS_ASSERT_EQUALS( v.getDirectionZ(), WVector3d( 0.0, 0.0, -1.0 ) );
00084 TS_ASSERT_EQUALS( v.getOrigin(), WVector3d( 0.0, 0.0, 0.0 ) );
00085 }
00086 {
00087 WMatrix< double > mat( 4, 4 );
00088 mat.makeIdentity();
00089 mat( 0, 0 ) = 2.2;
00090 mat( 1, 1 ) = 3.3;
00091 mat( 2, 2 ) = 0.0;
00092
00093 TS_ASSERT_THROWS( WGridTransformOrtho v( mat ), WPreconditionNotMet );
00094 }
00095 {
00096 WMatrix< double > mat( 4, 4 );
00097 mat.makeIdentity();
00098 mat( 0, 0 ) = 2.2;
00099 mat( 1, 0 ) = 0.1;
00100 mat( 1, 1 ) = 3.3;
00101 mat( 2, 2 ) = 1.0;
00102
00103 TS_ASSERT_THROWS( WGridTransformOrtho v( mat ), WPreconditionNotMet );
00104 }
00105 {
00106 WMatrix< double > mat( 4, 4 );
00107 mat.makeIdentity();
00108 mat( 0, 0 ) = 2.0;
00109 mat( 1, 0 ) = 2.0;
00110 mat( 1, 1 ) = 3.0;
00111 mat( 0, 1 ) = -3.0;
00112 mat( 2, 2 ) = 4.4;
00113 mat( 0, 3 ) = 1.0;
00114 mat( 1, 3 ) = 2.0;
00115 mat( 2, 3 ) = 0.5;
00116
00117 WGridTransformOrtho v( mat );
00118 TS_ASSERT_EQUALS( v.getOffsetX(), sqrt( 8.0 ) );
00119 TS_ASSERT_EQUALS( v.getOffsetY(), sqrt( 18.0 ) );
00120 TS_ASSERT_EQUALS( v.getOffsetZ(), 4.4 );
00121 TS_ASSERT_DELTA( length( v.getUnitDirectionX() - WVector3d( 0.5 * sqrt( 2.0 ), 0.5 * sqrt( 2.0 ), 0.0 ) ), 0.0, 1e-13 );
00122 TS_ASSERT_DELTA( length( v.getUnitDirectionY() - WVector3d( -0.5 * sqrt( 2.0 ), 0.5 * sqrt( 2.0 ), 0.0 ) ), 0.0, 1e-13 );
00123 TS_ASSERT_EQUALS( v.getUnitDirectionZ(), WVector3d( 0.0, 0.0, 1.0 ) );
00124 TS_ASSERT_EQUALS( v.getDirectionX(), WVector3d( 2.0, 2.0, 0.0 ) );
00125 TS_ASSERT_EQUALS( v.getDirectionY(), WVector3d( -3.0, 3.0, 0.0 ) );
00126 TS_ASSERT_EQUALS( v.getDirectionZ(), WVector3d( 0.0, 0.0, 4.4 ) );
00127 TS_ASSERT_EQUALS( v.getOrigin(), WVector3d( 1.0, 2.0, 0.5 ) );
00128 }
00129 }
00130
00131
00132
00133
00134
00135 void testCompareConstructors()
00136 {
00137 WMatrix< double > mat( 4, 4 );
00138 mat.makeIdentity();
00139 mat( 0, 0 ) = 2.2;
00140 mat( 1, 1 ) = 3.3;
00141 mat( 2, 2 ) = 4.4;
00142
00143 WGridTransformOrtho t1( mat );
00144 WGridTransformOrtho t2( 2.2, 3.3, 4.4 );
00145
00146 TS_ASSERT_EQUALS( t1.getOffsetX(), t2.getOffsetX() );
00147 TS_ASSERT_EQUALS( t1.getOffsetY(), t2.getOffsetY() );
00148 TS_ASSERT_EQUALS( t1.getOffsetZ(), t2.getOffsetZ() );
00149
00150 TS_ASSERT_EQUALS( t1.getDirectionX(), t2.getDirectionX() );
00151 TS_ASSERT_EQUALS( t1.getDirectionY(), t2.getDirectionY() );
00152 TS_ASSERT_EQUALS( t1.getDirectionZ(), t2.getDirectionZ() );
00153
00154 TS_ASSERT_EQUALS( t1.getOrigin(), t2.getOrigin() );
00155 }
00156
00157
00158
00159
00160 void testTransformationToWorldSpace()
00161 {
00162 {
00163
00164 WVector3d v( -7.64, 8.73, -0.0063 );
00165 WGridTransformOrtho t;
00166
00167 TS_ASSERT_EQUALS( v, t.positionToWorldSpace( v ) );
00168 TS_ASSERT_EQUALS( v, t.directionToWorldSpace( v ) );
00169 }
00170
00171 {
00172 WGridTransformOrtho t( 2.2, 3.3, 4.4 );
00173 WVector3d v( 1.0, 1.0, 1.0 );
00174
00175 TS_ASSERT_EQUALS( WVector3d( 2.2, 3.3, 4.4 ), t.positionToWorldSpace( v ) );
00176 TS_ASSERT_EQUALS( WVector3d( 2.2, 3.3, 4.4 ), t.directionToWorldSpace( v ) );
00177 }
00178
00179 {
00180 WMatrix< double > mat( 4, 4 );
00181 mat.makeIdentity();
00182 mat( 0, 0 ) = 2.2;
00183 mat( 1, 1 ) = 3.3;
00184 mat( 2, 2 ) = 4.4;
00185 mat( 0, 3 ) = 1.0;
00186 mat( 1, 3 ) = 2.0;
00187 mat( 2, 3 ) = 0.5;
00188
00189 WGridTransformOrtho t( mat );
00190 WVector3d v( 1.0, 1.0, 1.0 );
00191
00192 TS_ASSERT_EQUALS( WVector3d( 3.2, 5.3, 4.9 ), t.positionToWorldSpace( v ) );
00193 TS_ASSERT_EQUALS( WVector3d( 2.2, 3.3, 4.4 ), t.directionToWorldSpace( v ) );
00194 }
00195 {
00196 WMatrix< double > mat( 4, 4 );
00197 mat.makeIdentity();
00198 mat( 0, 0 ) = 2.0;
00199 mat( 1, 0 ) = 2.0;
00200 mat( 1, 1 ) = 3.0;
00201 mat( 0, 1 ) = -3.0;
00202 mat( 2, 2 ) = 4.4;
00203 mat( 0, 3 ) = 1.0;
00204 mat( 1, 3 ) = 2.0;
00205 mat( 2, 3 ) = 0.5;
00206
00207 WGridTransformOrtho t( mat );
00208 WVector3d v( 1.0, 1.0, 1.0 );
00209
00210 WVector3d w = t.positionToWorldSpace( v );
00211 TS_ASSERT_DELTA( 0.0, w[ 0 ], 0.0001 );
00212 TS_ASSERT_DELTA( 7.0, w[ 1 ], 0.0001 );
00213 TS_ASSERT_DELTA( 4.9, w[ 2 ], 0.0001 );
00214 TS_ASSERT_EQUALS( WVector3d( -1.0, 5.0, 4.4 ), t.directionToWorldSpace( v ) );
00215 }
00216 }
00217
00218
00219
00220
00221 void testTransformationToGridSpace()
00222 {
00223 {
00224
00225 WVector3d v( -7.64, 8.73, -0.0063 );
00226 WGridTransformOrtho t;
00227
00228 TS_ASSERT_EQUALS( v, t.positionToGridSpace( v ) );
00229 TS_ASSERT_EQUALS( v, t.directionToGridSpace( v ) );
00230 }
00231
00232 {
00233 WGridTransformOrtho t( 2.2, 3.3, 4.4 );
00234 WVector3d v( 2.2, 3.3, 4.4 );
00235
00236 TS_ASSERT_EQUALS( WVector3d( 1.0, 1.0, 1.0 ), t.positionToGridSpace( v ) );
00237 TS_ASSERT_EQUALS( WVector3d( 1.0, 1.0, 1.0 ), t.directionToGridSpace( v ) );
00238 }
00239
00240 {
00241 WMatrix< double > mat( 4, 4 );
00242 mat.makeIdentity();
00243 mat( 0, 0 ) = 2.2;
00244 mat( 1, 1 ) = 3.3;
00245 mat( 2, 2 ) = 4.4;
00246 mat( 0, 3 ) = 1.0;
00247 mat( 1, 3 ) = 2.0;
00248 mat( 2, 3 ) = 0.5;
00249
00250 WGridTransformOrtho t( mat );
00251
00252 TS_ASSERT_EQUALS( WVector3d( 1.0, 1.0, 1.0 ), t.positionToGridSpace( WVector3d( 3.2, 5.3, 4.9 ) ) );
00253 TS_ASSERT_EQUALS( WVector3d( 1.0, 1.0, 1.0 ), t.directionToGridSpace( WVector3d( 2.2, 3.3, 4.4 ) ) );
00254 }
00255 {
00256 WMatrix< double > mat( 4, 4 );
00257 mat.makeIdentity();
00258 mat( 0, 0 ) = 2.0;
00259 mat( 1, 0 ) = 2.0;
00260 mat( 1, 1 ) = 3.0;
00261 mat( 0, 1 ) = -3.0;
00262 mat( 2, 2 ) = 4.4;
00263 mat( 0, 3 ) = 1.0;
00264 mat( 1, 3 ) = 2.0;
00265 mat( 2, 3 ) = 0.5;
00266
00267 WGridTransformOrtho t( mat );
00268
00269 TS_ASSERT_DELTA( length( WVector3d( 1.0, 1.0, 1.0 )
00270 - t.positionToGridSpace( WVector3d( 0.0, 7.0, 4.9 ) ) ), 0.0, 1e-13 );
00271 TS_ASSERT_DELTA( length( WVector3d( 1.0, 1.0, 1.0 )
00272 - t.directionToGridSpace( WVector3d( -1.0, 5.0, 4.4 ) ) ), 0.0, 1e-13 );
00273 }
00274 }
00275 };
00276
00277 #endif // WGRIDTRANSFORMORTHO_TEST_H