00001
00034 #include <tut/tut.h>
00035 #include "linden_common.h"
00036 #include "lltut.h"
00037 #include "llquaternion.h"
00038 #include "linden_common.h"
00039 #include "llquantize.h"
00040 #include "v3dmath.h"
00041 #include "m3math.h"
00042 #include "v4math.h"
00043 #include "llsd.h"
00044 #include "v3math.h"
00045
00046
00047 namespace tut
00048 {
00049 struct v3math_data
00050 {
00051 };
00052 typedef test_group<v3math_data> v3math_test;
00053 typedef v3math_test::object v3math_object;
00054 tut::v3math_test v3math_testcase("v3math");
00055
00056 template<> template<>
00057 void v3math_object::test<1>()
00058 {
00059 LLVector3 vec3;
00060 ensure("1:LLVector3:Fail to initialize ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
00061 F32 x = 2.32f, y = 1.212f, z = -.12f;
00062 LLVector3 vec3a(x,y,z);
00063 ensure("2:LLVector3:Fail to initialize ", ((2.32f == vec3a.mV[VX]) && (1.212f == vec3a.mV[VY]) && (-.12f == vec3a.mV[VZ])));
00064 const F32 vec[3] = {1.2f ,3.2f, -4.2f};
00065 LLVector3 vec3b(vec);
00066 ensure("3:LLVector3:Fail to initialize ", ((1.2f == vec3b.mV[VX]) && (3.2f == vec3b.mV[VY]) && (-4.2f == vec3b.mV[VZ])));
00067 }
00068
00069 template<> template<>
00070 void v3math_object::test<2>()
00071 {
00072 F32 x = 2.32f, y = 1.212f, z = -.12f;
00073 LLVector3 vec3(x,y,z);
00074 LLVector3d vector3d(vec3);
00075 LLVector3 vec3a(vector3d);
00076 ensure("1:LLVector3:Fail to initialize ", vec3 == vec3a);
00077 LLVector4 vector4(vec3);
00078 LLVector3 vec3b(vector4);
00079 ensure("2:LLVector3:Fail to initialize ", vec3 == vec3b);
00080 }
00081
00082 template<> template<>
00083 void v3math_object::test<3>()
00084 {
00085 S32 a = 231;
00086 LLSD llsd(a);
00087 LLVector3 vec3(llsd);
00088 LLSD sd = vec3.getValue();
00089 LLVector3 vec3a(sd);
00090 ensure("1:LLVector3:Fail to initialize ", (vec3 == vec3a));
00091 }
00092
00093 template<> template<>
00094 void v3math_object::test<4>()
00095 {
00096 S32 a = 231;
00097 LLSD llsd(a);
00098 LLVector3 vec3(llsd),vec3a;
00099 vec3a = vec3;
00100 ensure("1:Operator= Fail to initialize " ,(vec3 == vec3a));
00101 }
00102
00103 template<> template<>
00104 void v3math_object::test<5>()
00105 {
00106 F32 x = 2.32f, y = 1.212f, z = -.12f;
00107 LLVector3 vec3(x,y,z);
00108 ensure("1:isFinite= Fail to initialize ", (TRUE == vec3.isFinite()));
00109 vec3.clearVec();
00110 ensure("2:clearVec:Fail to set values ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
00111 vec3.setVec(x,y,z);
00112 ensure("3:setVec:Fail to set values ", ((2.32f == vec3.mV[VX]) && (1.212f == vec3.mV[VY]) && (-.12f == vec3.mV[VZ])));
00113 vec3.zeroVec();
00114 ensure("4:zeroVec:Fail to set values ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
00115 }
00116
00117 template<> template<>
00118 void v3math_object::test<6>()
00119 {
00120 F32 x = 2.32f, y = 1.212f, z = -.12f;
00121 LLVector3 vec3(x,y,z),vec3a;
00122 vec3.abs();
00123 ensure("1:abs:Fail ", ((x == vec3.mV[VX]) && (y == vec3.mV[VY]) && (-z == vec3.mV[VZ])));
00124 vec3a.setVec(vec3);
00125 ensure("2:setVec:Fail to initialize ", (vec3a == vec3));
00126 const F32 vec[3] = {1.2f ,3.2f, -4.2f};
00127 vec3.clearVec();
00128 vec3.setVec(vec);
00129 ensure("3:setVec:Fail to initialize ", ((1.2f == vec3.mV[VX]) && (3.2f == vec3.mV[VY]) && (-4.2f == vec3.mV[VZ])));
00130 vec3a.clearVec();
00131 LLVector3d vector3d(vec3);
00132 vec3a.setVec(vector3d);
00133 ensure("4:setVec:Fail to initialize ", (vec3 == vec3a));
00134 LLVector4 vector4(vec3);
00135 vec3a.clearVec();
00136 vec3a.setVec(vector4);
00137 ensure("5:setVec:Fail to initialize ", (vec3 == vec3a));
00138 }
00139
00140 template<> template<>
00141 void v3math_object::test<7>()
00142 {
00143 F32 x = 2.32f, y = 3.212f, z = -.12f;
00144 F32 min = 0.0001f, max = 3.0f;
00145 LLVector3 vec3(x,y,z);
00146 ensure("1:clamp:Fail ", TRUE == vec3.clamp(min, max) && x == vec3.mV[VX] && max == vec3.mV[VY] && min == vec3.mV[VZ]);
00147 x = 1.f, y = 2.2f, z = 2.8f;
00148 vec3.setVec(x,y,z);
00149 ensure("2:clamp:Fail ", FALSE == vec3.clamp(min, max));
00150 }
00151
00152 template<> template<>
00153 void v3math_object::test<8>()
00154 {
00155 F32 x = 2.32f, y = 1.212f, z = -.12f;
00156 LLVector3 vec3(x,y,z);
00157 ensure("1:magVecSquared:Fail ", is_approx_equal(vec3.magVecSquared(), (x*x + y*y + z*z)));
00158 ensure("2:magVec:Fail ", is_approx_equal(vec3.magVec(), fsqrtf(x*x + y*y + z*z)));
00159 }
00160
00161 template<> template<>
00162 void v3math_object::test<9>()
00163 {
00164 F32 x =-2.0f, y = -3.0f, z = 1.23f ;
00165 LLVector3 vec3(x,y,z);
00166 ensure("1:abs():Fail ", (TRUE == vec3.abs()));
00167 ensure("2:isNull():Fail", (FALSE == vec3.isNull()));
00168 x =.00000001f, y = .000001001f, z = .000001001f;
00169 vec3.setVec(x,y,z);
00170 ensure("3:isNull(): Fail ", (TRUE == vec3.isNull()));
00171 }
00172
00173 template<> template<>
00174 void v3math_object::test<10>()
00175 {
00176 F32 x =-2.0f, y = -3.0f, z = 1.f ;
00177 LLVector3 vec3(x,y,z),vec3a;
00178 ensure("1:isExactlyZero():Fail ", (TRUE == vec3a.isExactlyZero()));
00179 vec3a = vec3a.scaleVec(vec3);
00180 ensure("2:scaleVec: Fail ", vec3a.mV[VX] == 0.f && vec3a.mV[VY] == 0.f && vec3a.mV[VZ] == 0.f);
00181 vec3a.setVec(x,y,z);
00182 vec3a = vec3a.scaleVec(vec3);
00183 ensure("3:scaleVec: Fail ", ((4 == vec3a.mV[VX]) && (9 == vec3a.mV[VY]) &&(1 == vec3a.mV[VZ])));
00184 ensure("4:isExactlyZero():Fail ", (FALSE == vec3.isExactlyZero()));
00185 }
00186
00187 template<> template<>
00188 void v3math_object::test<11>()
00189 {
00190 F32 x =20.0f, y = 30.0f, z = 15.f ;
00191 F32 angle = 100.f;
00192 LLVector3 vec3(x,y,z),vec3a(1.f,2.f,3.f);
00193 vec3a = vec3a.rotVec(angle, vec3);
00194 LLVector3 vec3b(1.f,2.f,3.f);
00195 vec3b = vec3b.rotVec(angle, vec3);
00196 ensure_equals("rotVec():Fail" ,vec3b,vec3a);
00197 }
00198
00199 template<> template<>
00200 void v3math_object::test<12>()
00201 {
00202 F32 x =-2.0f, y = -3.0f, z = 1.f ;
00203 LLVector3 vec3(x,y,z);
00204 ensure("1:operator [] failed",( x == vec3[0]));
00205 ensure("2:operator [] failed",( y == vec3[1]));
00206 ensure("3:operator [] failed",( z == vec3[2]));
00207
00208 vec3.clearVec();
00209 x = 23.f, y = -.2361f, z = 3.25;
00210 vec3.setVec(x,y,z);
00211 F32 &ref1 = vec3[0];
00212 ensure("4:operator [] failed",( ref1 == vec3[0]));
00213 F32 &ref2 = vec3[1];
00214 ensure("5:operator [] failed",( ref2 == vec3[1]));
00215 F32 &ref3 = vec3[2];
00216 ensure("6:operator [] failed",( ref3 == vec3[2]));
00217 }
00218
00219 template<> template<>
00220 void v3math_object::test<13>()
00221 {
00222 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
00223 F32 val1, val2, val3;
00224 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
00225 vec3b = vec3 + vec3a ;
00226 val1 = x1+x2;
00227 val2 = y1+y2;
00228 val3 = z1+z2;
00229 ensure("1:operator+ failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
00230
00231 vec3.clearVec();
00232 vec3a.clearVec();
00233 vec3b.clearVec();
00234 x1 = -.235f, y1 = -24.32f,z1 = 2.13f, x2 = -2.3f, y2 = 1.f, z2 = 34.21f;
00235 vec3.setVec(x1,y1,z1);
00236 vec3a.setVec(x2,y2,z2);
00237 vec3b = vec3 + vec3a;
00238 val1 = x1+x2;
00239 val2 = y1+y2;
00240 val3 = z1+z2;
00241 ensure("2:operator+ failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
00242 }
00243
00244 template<> template<>
00245 void v3math_object::test<14>()
00246 {
00247 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
00248 F32 val1, val2, val3;
00249 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
00250 vec3b = vec3 - vec3a ;
00251 val1 = x1-x2;
00252 val2 = y1-y2;
00253 val3 = z1-z2;
00254 ensure("1:operator- failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
00255
00256 vec3.clearVec();
00257 vec3a.clearVec();
00258 vec3b.clearVec();
00259 x1 = -.235f, y1 = -24.32f,z1 = 2.13f, x2 = -2.3f, y2 = 1.f, z2 = 34.21f;
00260 vec3.setVec(x1,y1,z1);
00261 vec3a.setVec(x2,y2,z2);
00262 vec3b = vec3 - vec3a;
00263 val1 = x1-x2;
00264 val2 = y1-y2;
00265 val3 = z1-z2;
00266 ensure("2:operator- failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
00267 }
00268
00269 template<> template<>
00270 void v3math_object::test<15>()
00271 {
00272 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
00273 F32 val1, val2, val3;
00274 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
00275 val1 = vec3 * vec3a;
00276 val2 = x1*x2 + y1*y2 + z1*z2;
00277 ensure_equals("1:operator* failed",val1,val2);
00278
00279 vec3a.clearVec();
00280 F32 mulVal = 4.332f;
00281 vec3a = vec3 * mulVal;
00282 val1 = x1*mulVal;
00283 val2 = y1*mulVal;
00284 val3 = z1*mulVal;
00285 ensure("2:operator* failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
00286 vec3a.clearVec();
00287 vec3a = mulVal * vec3;
00288 ensure("3:operator* failed ", (val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
00289 }
00290
00291 template<> template<>
00292 void v3math_object::test<16>()
00293 {
00294 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
00295 F32 val1, val2, val3;
00296 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
00297 vec3b = vec3 % vec3a ;
00298 val1 = y1*z2 - y2*z1;
00299 val2 = z1*x2 -z2*x1;
00300 val3 = x1*y2-x2*y1;
00301 ensure("1:operator% failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
00302
00303 vec3.clearVec();
00304 vec3a.clearVec();
00305 vec3b.clearVec();
00306 x1 =112.f, y1 = 22.3f,z1 = 1.2f, x2 = -2.3f, y2 = 341.11f, z2 = 1234.234f;
00307 vec3.setVec(x1,y1,z1);
00308 vec3a.setVec(x2,y2,z2);
00309 vec3b = vec3 % vec3a ;
00310 val1 = y1*z2 - y2*z1;
00311 val2 = z1*x2 -z2*x1;
00312 val3 = x1*y2-x2*y1;
00313 ensure("2:operator% failed ", (val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ]));
00314 }
00315
00316 template<> template<>
00317 void v3math_object::test<17>()
00318 {
00319 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, div = 3.2f;
00320 F32 t = 1.f / div, val1, val2, val3;
00321 LLVector3 vec3(x1,y1,z1), vec3a;
00322 vec3a = vec3 / div;
00323 val1 = x1 * t;
00324 val2 = y1 * t;
00325 val3 = z1 *t;
00326 ensure("1:operator/ failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));
00327
00328 vec3a.clearVec();
00329 x1 = -.235f, y1 = -24.32f, z1 = .342f, div = -2.2f;
00330 t = 1.f / div;
00331 vec3.setVec(x1,y1,z1);
00332 vec3a = vec3 / div;
00333 val1 = x1 * t;
00334 val2 = y1 * t;
00335 val3 = z1 *t;
00336 ensure("2:operator/ failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));
00337 }
00338
00339 template<> template<>
00340 void v3math_object::test<18>()
00341 {
00342 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
00343 LLVector3 vec3(x1,y1,z1), vec3a(x1,y1,z1);
00344 ensure("1:operator== failed",(vec3 == vec3a));
00345
00346 vec3a.clearVec();
00347 x1 = -.235f, y1 = -24.32f, z1 = .342f;
00348 vec3.clearVec();
00349 vec3a.clearVec();
00350 vec3.setVec(x1,y1,z1);
00351 vec3a.setVec(x1,y1,z1);
00352 ensure("2:operator== failed ", (vec3 == vec3a));
00353 }
00354
00355 template<> template<>
00356 void v3math_object::test<19>()
00357 {
00358 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.234f,z2 = 11.2f;;
00359 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
00360 ensure("1:operator!= failed",(vec3a != vec3));
00361
00362 vec3.clearVec();
00363 vec3.clearVec();
00364 vec3a.setVec(vec3);
00365 ensure("2:operator!= failed", ( FALSE == (vec3a != vec3)));
00366 }
00367
00368 template<> template<>
00369 void v3math_object::test<20>()
00370 {
00371 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.2f,z2 = 11.2f;;
00372 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
00373 vec3a += vec3;
00374 F32 val1, val2, val3;
00375 val1 = x1+x2;
00376 val2 = y1+y2;
00377 val3 = z1+z2;
00378 ensure("1:operator+= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
00379 }
00380
00381 template<> template<>
00382 void v3math_object::test<21>()
00383 {
00384 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.2f,z2 = 11.2f;;
00385 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
00386 vec3a -= vec3;
00387 F32 val1, val2, val3;
00388 val1 = x2-x1;
00389 val2 = y2-y1;
00390 val3 = z2-z1;
00391 ensure("1:operator-= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
00392 }
00393
00394 template<> template<>
00395 void v3math_object::test<22>()
00396 {
00397 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
00398 F32 val1,val2,val3;
00399 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
00400 vec3a *= vec3;
00401 val1 = x1*x2;
00402 val2 = y1*y2;
00403 val3 = z1*z2;
00404 ensure("1:operator*= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
00405
00406 F32 mulVal = 4.332f;
00407 vec3 *=mulVal;
00408 val1 = x1*mulVal;
00409 val2 = y1*mulVal;
00410 val3 = z1*mulVal;
00411 ensure("2:operator*= failed ", is_approx_equal(val1, vec3.mV[VX]) && is_approx_equal(val2, vec3.mV[VY]) && is_approx_equal(val3, vec3.mV[VZ]));
00412 }
00413
00414 template<> template<>
00415 void v3math_object::test<23>()
00416 {
00417 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
00418 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2),vec3b;
00419 vec3b = vec3a % vec3;
00420 vec3a %= vec3;
00421 ensure_equals("1:operator%= failed",vec3a,vec3b);
00422 }
00423
00424 template<> template<>
00425 void v3math_object::test<24>()
00426 {
00427 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, div = 3.2f;
00428 F32 t = 1.f / div, val1, val2, val3;
00429 LLVector3 vec3a(x1,y1,z1);
00430 vec3a /= div;
00431 val1 = x1 * t;
00432 val2 = y1 * t;
00433 val3 = z1 *t;
00434 ensure("1:operator/= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));
00435 }
00436
00437 template<> template<>
00438 void v3math_object::test<25>()
00439 {
00440 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
00441 LLVector3 vec3(x1,y1,z1), vec3a;
00442 vec3a = -vec3;
00443 ensure("1:operator- failed",(-vec3a == vec3));
00444 }
00445
00446 template<> template<>
00447 void v3math_object::test<26>()
00448 {
00449 F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
00450 std::ostringstream stream1, stream2;
00451 LLVector3 vec3(x1,y1,z1), vec3a;
00452 stream1 << vec3;
00453 vec3a.setVec(x1,y1,z1);
00454 stream2 << vec3a;
00455 ensure("1:operator << failed",(stream1.str() == stream2.str()));
00456 }
00457
00458 template<> template<>
00459 void v3math_object::test<27>()
00460 {
00461 F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.11f, z2 = 1234.234f;
00462 LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
00463 ensure("1:operator< failed", (TRUE == vec3 < vec3a));
00464 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 2.f, z2 = 1234.234f;
00465 vec3.setVec(x1,y1,z1);
00466 vec3a.setVec(x2,y2,z2);
00467 ensure("2:operator< failed ", (TRUE == vec3 < vec3a));
00468 x1 =2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f,
00469 vec3.setVec(x1,y1,z1);
00470 vec3a.setVec(x2,y2,z2);
00471 ensure("3:operator< failed ", (FALSE == vec3 < vec3a));
00472 }
00473
00474 template<> template<>
00475 void v3math_object::test<28>()
00476 {
00477 F32 x1 =1.23f, y1 = 2.f,z1 = 4.f;
00478 char buf[] = "1.23 2. 4";
00479 LLVector3 vec3, vec3a(x1,y1,z1);
00480 LLVector3::parseVector3(buf, &vec3);
00481 ensure_equals("1:parseVector3 failed", vec3, vec3a);
00482 }
00483
00484 template<> template<>
00485 void v3math_object::test<29>()
00486 {
00487 F32 x1 =1.f, y1 = 2.f,z1 = 4.f;
00488 LLVector3 vec3(x1,y1,z1),vec3a,vec3b;
00489 vec3a.setVec(1,1,1);
00490 vec3a.scaleVec(vec3);
00491 ensure_equals("1:scaleVec failed", vec3, vec3a);
00492 vec3a.clearVec();
00493 vec3a.setVec(x1,y1,z1);
00494 vec3a.scaleVec(vec3);
00495 ensure("2:scaleVec failed", ((1.f ==vec3a.mV[VX])&& (4.f ==vec3a.mV[VY]) && (16.f ==vec3a.mV[VZ])));
00496 }
00497
00498 template<> template<>
00499 void v3math_object::test<30>()
00500 {
00501 F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.11f, z2 = 1234.234f;
00502 F32 val = 2.3f,val1,val2,val3;
00503 val1 = x1 + (x2 - x1)* val;
00504 val2 = y1 + (y2 - y1)* val;
00505 val3 = z1 + (z2 - z1)* val;
00506 LLVector3 vec3(x1,y1,z1),vec3a(x2,y2,z2);
00507 LLVector3 vec3b = lerp(vec3,vec3a,val);
00508 ensure("1:lerp failed", ((val1 ==vec3b.mV[VX])&& (val2 ==vec3b.mV[VY]) && (val3 ==vec3b.mV[VZ])));
00509 }
00510
00511 template<> template<>
00512 void v3math_object::test<31>()
00513 {
00514 F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.f, z2 = 1.f;
00515 F32 val1,val2;
00516 LLVector3 vec3(x1,y1,z1),vec3a(x2,y2,z2);
00517 val1 = dist_vec(vec3,vec3a);
00518 val2 = fsqrtf((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2));
00519 ensure_equals("1:dist_vec: Fail ",val2, val1);
00520 val1 = dist_vec_squared(vec3,vec3a);
00521 val2 =((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2));
00522 ensure_equals("2:dist_vec_squared: Fail ",val2, val1);
00523 val1 = dist_vec_squared2D(vec3, vec3a);
00524 val2 =(x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2);
00525 ensure_equals("3:dist_vec_squared2D: Fail ",val2, val1);
00526 }
00527
00528 template<> template<>
00529 void v3math_object::test<32>()
00530 {
00531 F32 x =12.3524f, y = -342.f,z = 4.126341f;
00532 LLVector3 vec3(x,y,z);
00533 F32 mag = vec3.normVec();
00534 mag = 1.f/ mag;
00535 F32 val1 = x* mag, val2 = y* mag, val3 = z* mag;
00536 ensure("1:normVec: Fail ", is_approx_equal(val1, vec3.mV[VX]) && is_approx_equal(val2, vec3.mV[VY]) && is_approx_equal(val3, vec3.mV[VZ]));
00537 x = 0.000000001f, y = 0.f, z = 0.f;
00538 vec3.clearVec();
00539 vec3.setVec(x,y,z);
00540 mag = vec3.normVec();
00541 val1 = x* mag, val2 = y* mag, val3 = z* mag;
00542 ensure("2:normVec: Fail ", (mag == 0.) && (0. == vec3.mV[VX]) && (0. == vec3.mV[VY])&& (0. == vec3.mV[VZ]));
00543 }
00544
00545 template<> template<>
00546 void v3math_object::test<33>()
00547 {
00548 F32 x = -202.23412f, y = 123.2312f, z = -89.f;
00549 LLVector3 vec(x,y,z);
00550 vec.snap(2);
00551 ensure("1:snap: Fail ", is_approx_equal(-202.23f, vec.mV[VX]) && is_approx_equal(123.23f, vec.mV[VY]) && is_approx_equal(-89.f, vec.mV[VZ]));
00552 }
00553
00554 template<> template<>
00555 void v3math_object::test<34>()
00556 {
00557 F32 x = 10.f, y = 20.f, z = -15.f;
00558 F32 x1, y1, z1;
00559 F32 lowerxy = 0.f, upperxy = 1.0f, lowerz = -1.0f, upperz = 1.f;
00560 LLVector3 vec3(x,y,z);
00561 vec3.quantize16(lowerxy,upperxy,lowerz,upperz);
00562 x1 = U16_to_F32(F32_to_U16(x, lowerxy, upperxy), lowerxy, upperxy);
00563 y1 = U16_to_F32(F32_to_U16(y, lowerxy, upperxy), lowerxy, upperxy);
00564 z1 = U16_to_F32(F32_to_U16(z, lowerz, upperz), lowerz, upperz);
00565 ensure("1:quantize16: Fail ", is_approx_equal(x1, vec3.mV[VX]) && is_approx_equal(y1, vec3.mV[VY]) && is_approx_equal(z1, vec3.mV[VZ]));
00566 LLVector3 vec3a(x,y,z);
00567 vec3a.quantize8(lowerxy,upperxy,lowerz,upperz);
00568 x1 = U8_to_F32(F32_to_U8(x, lowerxy, upperxy), lowerxy, upperxy);
00569 y1 = U8_to_F32(F32_to_U8(y, lowerxy, upperxy), lowerxy, upperxy);
00570 z1 = U8_to_F32(F32_to_U8(z, lowerz, upperz), lowerz, upperz);
00571 ensure("2:quantize8: Fail ", is_approx_equal(x1, vec3a.mV[VX]) && is_approx_equal(y1, vec3a.mV[VY]) && is_approx_equal(z1, vec3a.mV[VZ]));
00572 }
00573 }