PageRenderTime 119ms CodeModel.GetById 13ms app.highlight 97ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llmath/tests/v3math_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 585 lines | 507 code | 51 blank | 27 comment | 175 complexity | 2b1aba8cbeb3e3aa6deffe88139a33cc MD5 | raw file
  1/**
  2 * @file v3math_test.cpp
  3 * @author Adroit
  4 * @date 2007-02
  5 * @brief v3math test cases.
  6 *
  7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28 
 29#include "linden_common.h"
 30#include "../test/lltut.h"
 31#include "llsd.h"
 32
 33#include "../v3dmath.h"
 34#include "../m3math.h"
 35#include "../v4math.h"
 36#include "../v3math.h"
 37#include "../llquaternion.h"
 38#include "../llquantize.h"
 39
 40
 41namespace tut
 42{
 43	struct v3math_data
 44	{
 45	};
 46	typedef test_group<v3math_data> v3math_test;
 47	typedef v3math_test::object v3math_object;
 48	tut::v3math_test v3math_testcase("v3math_h");
 49
 50	template<> template<>
 51	void v3math_object::test<1>()
 52	{
 53		LLVector3 vec3;
 54		ensure("1:LLVector3:Fail to initialize ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
 55		F32 x = 2.32f, y = 1.212f, z = -.12f;
 56		LLVector3 vec3a(x,y,z);
 57		ensure("2:LLVector3:Fail to initialize ", ((2.32f == vec3a.mV[VX]) && (1.212f == vec3a.mV[VY]) && (-.12f == vec3a.mV[VZ])));
 58		const F32 vec[3] = {1.2f ,3.2f, -4.2f};
 59		LLVector3 vec3b(vec);
 60		ensure("3:LLVector3:Fail to initialize ", ((1.2f == vec3b.mV[VX]) && (3.2f == vec3b.mV[VY]) && (-4.2f == vec3b.mV[VZ])));
 61	}
 62
 63	template<> template<>
 64	void v3math_object::test<2>()
 65	{
 66		F32 x = 2.32f, y = 1.212f, z = -.12f;
 67		LLVector3 vec3(x,y,z);
 68		LLVector3d vector3d(vec3);
 69		LLVector3 vec3a(vector3d);
 70		ensure("1:LLVector3:Fail to initialize ", vec3 == vec3a);
 71		LLVector4 vector4(vec3);
 72		LLVector3 vec3b(vector4);
 73		ensure("2:LLVector3:Fail to initialize ", vec3 == vec3b);
 74	}
 75
 76	template<> template<>
 77	void v3math_object::test<3>()
 78	{
 79		S32 a = 231;
 80		LLSD llsd(a);
 81		LLVector3 vec3(llsd);
 82		LLSD sd = vec3.getValue();
 83		LLVector3 vec3a(sd);
 84		ensure("1:LLVector3:Fail to initialize ", (vec3 == vec3a));
 85	}
 86
 87	template<> template<>
 88	void v3math_object::test<4>()
 89	{
 90		S32 a = 231;
 91		LLSD llsd(a);
 92		LLVector3 vec3(llsd),vec3a;
 93		vec3a = vec3;
 94		ensure("1:Operator= Fail to initialize " ,(vec3 == vec3a));
 95	}
 96	
 97	template<> template<>
 98	void v3math_object::test<5>()
 99	{
100		F32 x = 2.32f, y = 1.212f, z = -.12f;
101		LLVector3 vec3(x,y,z);
102		ensure("1:isFinite= Fail to initialize ", (TRUE == vec3.isFinite()));//need more test cases:
103		vec3.clearVec();
104		ensure("2:clearVec:Fail to set values ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
105		vec3.setVec(x,y,z);
106		ensure("3:setVec:Fail to set values ", ((2.32f == vec3.mV[VX]) && (1.212f == vec3.mV[VY]) && (-.12f == vec3.mV[VZ])));
107		vec3.zeroVec();
108		ensure("4:zeroVec:Fail to set values ", ((0.f == vec3.mV[VX]) && (0.f == vec3.mV[VY]) && (0.f == vec3.mV[VZ])));
109	}
110	
111	template<> template<>
112	void v3math_object::test<6>()
113	{
114		F32 x = 2.32f, y = 1.212f, z = -.12f;
115		LLVector3 vec3(x,y,z),vec3a;
116		vec3.abs();
117		ensure("1:abs:Fail ", ((x == vec3.mV[VX]) && (y == vec3.mV[VY]) && (-z == vec3.mV[VZ])));
118		vec3a.setVec(vec3);
119		ensure("2:setVec:Fail to initialize ", (vec3a == vec3));	
120		const F32 vec[3] = {1.2f ,3.2f, -4.2f};
121		vec3.clearVec();
122		vec3.setVec(vec);
123		ensure("3:setVec:Fail to initialize ", ((1.2f == vec3.mV[VX]) && (3.2f == vec3.mV[VY]) && (-4.2f == vec3.mV[VZ])));
124		vec3a.clearVec();
125		LLVector3d vector3d(vec3);
126		vec3a.setVec(vector3d);
127		ensure("4:setVec:Fail to initialize ", (vec3 == vec3a));
128		LLVector4 vector4(vec3);
129		vec3a.clearVec();
130		vec3a.setVec(vector4);
131		ensure("5:setVec:Fail to initialize ", (vec3 == vec3a));
132	}
133
134	template<> template<>
135	void v3math_object::test<7>()
136	{
137		F32 x = 2.32f, y = 3.212f, z = -.12f;
138		F32 min = 0.0001f, max = 3.0f;
139		LLVector3 vec3(x,y,z);		
140		ensure("1:clamp:Fail  ", TRUE == vec3.clamp(min, max) && x == vec3.mV[VX] && max == vec3.mV[VY] && min == vec3.mV[VZ]);
141		x = 1.f, y = 2.2f, z = 2.8f;
142		vec3.setVec(x,y,z);
143		ensure("2:clamp:Fail  ", FALSE == vec3.clamp(min, max));
144	}
145
146	template<> template<>
147	void v3math_object::test<8>()
148	{
149		F32 x = 2.32f, y = 1.212f, z = -.12f;
150		LLVector3 vec3(x,y,z);		
151		ensure("1:magVecSquared:Fail ", is_approx_equal(vec3.magVecSquared(), (x*x + y*y + z*z)));
152		ensure("2:magVec:Fail ", is_approx_equal(vec3.magVec(), (F32) sqrt(x*x + y*y + z*z)));
153	}
154
155	template<> template<>
156	void v3math_object::test<9>()
157	{
158		F32 x =-2.0f, y = -3.0f, z = 1.23f ;
159		LLVector3 vec3(x,y,z);
160		ensure("1:abs():Fail ", (TRUE == vec3.abs()));	
161		ensure("2:isNull():Fail", (FALSE == vec3.isNull()));	//Returns TRUE if vector has a _very_small_ length
162		x =.00000001f, y = .000001001f, z = .000001001f;
163		vec3.setVec(x,y,z);
164		ensure("3:isNull(): Fail ", (TRUE == vec3.isNull()));	
165	}
166
167	template<> template<>
168	void v3math_object::test<10>()
169	{
170		F32 x =-2.0f, y = -3.0f, z = 1.f ;
171		LLVector3 vec3(x,y,z),vec3a;
172		ensure("1:isExactlyZero():Fail ", (TRUE == vec3a.isExactlyZero()));
173		vec3a = vec3a.scaleVec(vec3);
174		ensure("2:scaleVec: Fail ", vec3a.mV[VX] == 0.f && vec3a.mV[VY] == 0.f && vec3a.mV[VZ] == 0.f);
175		vec3a.setVec(x,y,z);
176		vec3a = vec3a.scaleVec(vec3);
177		ensure("3:scaleVec: Fail ", ((4 == vec3a.mV[VX]) && (9 == vec3a.mV[VY]) &&(1 == vec3a.mV[VZ])));
178		ensure("4:isExactlyZero():Fail ", (FALSE == vec3.isExactlyZero()));
179	}
180
181	template<> template<>
182	void v3math_object::test<11>()
183	{
184		F32 x =20.0f, y = 30.0f, z = 15.f ;
185		F32 angle = 100.f;
186		LLVector3 vec3(x,y,z),vec3a(1.f,2.f,3.f);
187		vec3a = vec3a.rotVec(angle, vec3);
188		LLVector3 vec3b(1.f,2.f,3.f);
189		vec3b = vec3b.rotVec(angle, vec3);
190		ensure_equals("rotVec():Fail" ,vec3b,vec3a);
191	}
192
193	template<> template<>
194	void v3math_object::test<12>()
195	{
196		F32 x =-2.0f, y = -3.0f, z = 1.f ;
197		LLVector3 vec3(x,y,z);
198		ensure("1:operator [] failed",( x ==  vec3[0]));	
199		ensure("2:operator [] failed",( y ==  vec3[1]));
200		ensure("3:operator [] failed",( z ==  vec3[2]));
201
202		vec3.clearVec();
203		x = 23.f, y = -.2361f, z = 3.25;
204		vec3.setVec(x,y,z);
205		F32 &ref1 = vec3[0];
206		ensure("4:operator [] failed",( ref1 ==  vec3[0]));
207		F32 &ref2 = vec3[1];
208		ensure("5:operator [] failed",( ref2 ==  vec3[1]));
209		F32 &ref3 = vec3[2];
210		ensure("6:operator [] failed",( ref3 ==  vec3[2]));
211	}
212
213	template<> template<>
214	void v3math_object::test<13>()
215	{
216		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
217		F32 val1, val2, val3;
218		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
219		vec3b = vec3 + vec3a ;
220		val1 = x1+x2;
221		val2 = y1+y2;
222		val3 = z1+z2;
223		ensure("1:operator+ failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); 
224
225		vec3.clearVec();
226		vec3a.clearVec();
227		vec3b.clearVec();
228		x1 = -.235f, y1 = -24.32f,z1 = 2.13f,  x2 = -2.3f, y2 = 1.f, z2 = 34.21f;
229		vec3.setVec(x1,y1,z1);
230		vec3a.setVec(x2,y2,z2);
231		vec3b = vec3 + vec3a;
232		val1 = x1+x2;
233		val2 = y1+y2;
234		val3 = z1+z2;
235		ensure("2:operator+ failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); 
236	}
237
238	template<> template<>
239	void v3math_object::test<14>()
240	{
241		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
242		F32 val1, val2, val3;
243		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
244		vec3b = vec3 - vec3a ;
245		val1 = x1-x2;
246		val2 = y1-y2;
247		val3 = z1-z2;
248		ensure("1:operator- failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); 
249
250		vec3.clearVec();
251		vec3a.clearVec();
252		vec3b.clearVec();
253		x1 = -.235f, y1 = -24.32f,z1 = 2.13f,  x2 = -2.3f, y2 = 1.f, z2 = 34.21f;
254		vec3.setVec(x1,y1,z1);
255		vec3a.setVec(x2,y2,z2);
256		vec3b = vec3 - vec3a;
257		val1 = x1-x2;
258		val2 = y1-y2;
259		val3 = z1-z2;
260		ensure("2:operator- failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); 
261	}
262
263	template<> template<>
264	void v3math_object::test<15>()
265	{
266		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
267		F32 val1, val2, val3;
268		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
269		val1 = vec3 * vec3a;
270		val2 = x1*x2 + y1*y2 + z1*z2;
271		ensure_equals("1:operator* failed",val1,val2);
272
273		vec3a.clearVec();
274		F32 mulVal = 4.332f;
275		vec3a = vec3 * mulVal;
276		val1 = x1*mulVal;
277		val2 = y1*mulVal;
278		val3 = z1*mulVal;
279		ensure("2:operator* failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
280		vec3a.clearVec();
281		vec3a = mulVal * vec3;
282		ensure("3:operator* failed ", (val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
283	}
284
285	template<> template<>
286	void v3math_object::test<16>()
287	{
288		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
289		F32 val1, val2, val3;
290		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2), vec3b;
291		vec3b = vec3 % vec3a ;
292		val1 = y1*z2 - y2*z1;
293		val2 = z1*x2 -z2*x1;
294		val3 = x1*y2-x2*y1;
295		ensure("1:operator% failed",(val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); 
296
297		vec3.clearVec();
298		vec3a.clearVec();
299		vec3b.clearVec();
300		x1 =112.f, y1 = 22.3f,z1 = 1.2f, x2 = -2.3f, y2 = 341.11f, z2 = 1234.234f;
301		vec3.setVec(x1,y1,z1);
302		vec3a.setVec(x2,y2,z2);
303		vec3b = vec3 % vec3a ;
304		val1 = y1*z2 - y2*z1;
305		val2 = z1*x2 -z2*x1;
306		val3 = x1*y2-x2*y1;
307		ensure("2:operator% failed ", (val1 == vec3b.mV[VX]) && (val2 == vec3b.mV[VY]) && (val3 == vec3b.mV[VZ])); 
308	}
309
310	template<> template<>
311	void v3math_object::test<17>()
312	{
313		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, div = 3.2f;
314		F32 t = 1.f / div, val1, val2, val3;
315		LLVector3 vec3(x1,y1,z1), vec3a;
316		vec3a = vec3 / div;
317		val1 = x1 * t;
318		val2 = y1 * t;
319		val3 = z1 *t;
320		ensure("1:operator/ failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));		
321
322		vec3a.clearVec();
323		x1 = -.235f, y1 = -24.32f, z1 = .342f, div = -2.2f;
324		t = 1.f / div;
325		vec3.setVec(x1,y1,z1);
326		vec3a = vec3 / div;
327		val1 = x1 * t;
328		val2 = y1 * t;
329		val3 = z1 *t;
330		ensure("2:operator/ failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));		
331	}
332
333	template<> template<>
334	void v3math_object::test<18>()
335	{
336		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
337		LLVector3 vec3(x1,y1,z1), vec3a(x1,y1,z1);
338		ensure("1:operator== failed",(vec3 == vec3a));		
339
340		vec3a.clearVec();
341		x1 = -.235f, y1 = -24.32f, z1 = .342f;
342		vec3.clearVec();
343		vec3a.clearVec();
344		vec3.setVec(x1,y1,z1);
345		vec3a.setVec(x1,y1,z1);
346		ensure("2:operator== failed ", (vec3 == vec3a));		
347	}
348
349	template<> template<>
350	void v3math_object::test<19>()
351	{
352		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.234f,z2 = 11.2f;;
353		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
354		ensure("1:operator!= failed",(vec3a != vec3));
355
356		vec3.clearVec();
357		vec3.clearVec();
358		vec3a.setVec(vec3);
359		ensure("2:operator!= failed", ( FALSE == (vec3a != vec3)));
360	}
361
362	template<> template<>
363	void v3math_object::test<20>()
364	{
365		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.2f,z2 = 11.2f;;
366		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
367		vec3a += vec3;
368		F32 val1, val2, val3;
369		val1 = x1+x2;
370		val2 = y1+y2;
371		val3 = z1+z2;
372		ensure("1:operator+= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
373	}
374	
375	template<> template<>
376	void v3math_object::test<21>()
377	{
378		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 =112.f, y2 = 2.2f,z2 = 11.2f;;
379		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
380		vec3a -= vec3;
381		F32 val1, val2, val3;
382		val1 = x2-x1;
383		val2 = y2-y1;
384		val3 = z2-z1;
385		ensure("1:operator-= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
386	}
387
388	template<> template<>
389	void v3math_object::test<22>()
390	{
391		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
392		F32 val1,val2,val3;
393		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
394		vec3a *= vec3;
395		val1 = x1*x2;
396		val2 = y1*y2;
397		val3 = z1*z2;
398		ensure("1:operator*= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY])&& (val3 == vec3a.mV[VZ]));
399
400		F32 mulVal = 4.332f;
401		vec3 *=mulVal;
402		val1 = x1*mulVal;
403		val2 = y1*mulVal;
404		val3 = z1*mulVal;
405		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]));
406	}
407
408	template<> template<>
409	void v3math_object::test<23>()
410	{
411		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, x2 = -2.3f, y2 = 1.11f, z2 = 1234.234f;
412		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2),vec3b;
413		vec3b = vec3a % vec3;
414		vec3a %= vec3;
415		ensure_equals("1:operator%= failed",vec3a,vec3b); 
416	}
417
418	template<> template<>
419	void v3math_object::test<24>()
420	{
421		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f, div = 3.2f;
422		F32 t = 1.f / div, val1, val2, val3;
423		LLVector3 vec3a(x1,y1,z1);
424		vec3a /= div;
425		val1 = x1 * t;
426		val2 = y1 * t;
427		val3 = z1 *t;
428		ensure("1:operator/= failed",(val1 == vec3a.mV[VX]) && (val2 == vec3a.mV[VY]) && (val3 == vec3a.mV[VZ]));		
429	}
430
431	template<> template<>
432	void v3math_object::test<25>()
433	{
434		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
435		LLVector3 vec3(x1,y1,z1), vec3a;
436		vec3a = -vec3;
437		ensure("1:operator- failed",(-vec3a == vec3));	
438	}
439
440	template<> template<>
441	void v3math_object::test<26>()
442	{
443		F32 x1 =1.f, y1 = 2.f,z1 = 1.2f;
444		std::ostringstream stream1, stream2;
445		LLVector3 vec3(x1,y1,z1), vec3a;
446		stream1 << vec3;
447		vec3a.setVec(x1,y1,z1);
448		stream2 << vec3a;
449		ensure("1:operator << failed",(stream1.str() == stream2.str()));	
450	}
451
452	template<> template<>
453	void v3math_object::test<27>()
454	{
455		F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.11f, z2 = 1234.234f;
456		LLVector3 vec3(x1,y1,z1), vec3a(x2,y2,z2);
457		ensure("1:operator< failed", (TRUE == (vec3 < vec3a)));
458		x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 2.f, z2 = 1234.234f;
459		vec3.setVec(x1,y1,z1);
460		vec3a.setVec(x2,y2,z2);
461		ensure("2:operator< failed ", (TRUE == (vec3 < vec3a)));
462		x1 =2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f,
463		vec3.setVec(x1,y1,z1);
464		vec3a.setVec(x2,y2,z2);
465		ensure("3:operator< failed ", (FALSE == (vec3 < vec3a)));
466	}
467
468	template<> template<>
469	void v3math_object::test<28>()
470	{
471		F32 x1 =1.23f, y1 = 2.f,z1 = 4.f;
472		std::string buf("1.23 2. 4");
473		LLVector3 vec3, vec3a(x1,y1,z1);
474		LLVector3::parseVector3(buf, &vec3);
475		ensure_equals("1:parseVector3 failed", vec3, vec3a);	
476	}
477
478	template<> template<>
479	void v3math_object::test<29>()
480	{
481		F32 x1 =1.f, y1 = 2.f,z1 = 4.f;
482		LLVector3 vec3(x1,y1,z1),vec3a,vec3b;
483		vec3a.setVec(1,1,1);
484		vec3a.scaleVec(vec3);
485		ensure_equals("1:scaleVec failed", vec3, vec3a);	
486		vec3a.clearVec();
487		vec3a.setVec(x1,y1,z1);
488		vec3a.scaleVec(vec3);
489		ensure("2:scaleVec failed", ((1.f ==vec3a.mV[VX])&& (4.f ==vec3a.mV[VY]) && (16.f ==vec3a.mV[VZ])));		
490	}
491	
492	template<> template<>
493	void v3math_object::test<30>()
494	{
495		F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.11f, z2 = 1234.234f;
496		F32 val = 2.3f,val1,val2,val3;
497		val1 = x1 + (x2 - x1)* val;
498		val2 = y1 + (y2 - y1)* val;
499		val3 = z1 + (z2 - z1)* val;
500		LLVector3 vec3(x1,y1,z1),vec3a(x2,y2,z2);
501		LLVector3 vec3b = lerp(vec3,vec3a,val);
502		ensure("1:lerp failed", ((val1 ==vec3b.mV[VX])&& (val2 ==vec3b.mV[VY]) && (val3 ==vec3b.mV[VZ])));		
503	}
504
505	template<> template<>
506	void v3math_object::test<31>()
507	{
508		F32 x1 =-2.3f, y1 = 2.f,z1 = 1.2f, x2 = 1.3f, y2 = 1.f, z2 = 1.f;
509		F32 val1,val2;
510		LLVector3 vec3(x1,y1,z1),vec3a(x2,y2,z2);
511		val1 = dist_vec(vec3,vec3a);
512		val2 = (F32) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2));
513		ensure_equals("1:dist_vec: Fail ",val2, val1);
514		val1 = dist_vec_squared(vec3,vec3a);
515		val2 =((x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2) + (z1 - z2)* (z1 -z2));
516		ensure_equals("2:dist_vec_squared: Fail ",val2, val1);
517		val1 = dist_vec_squared2D(vec3, vec3a);
518		val2 =(x1 - x2)*(x1 - x2) + (y1 - y2)* (y1 - y2);
519		ensure_equals("3:dist_vec_squared2D: Fail ",val2, val1);
520	}
521
522	template<> template<>
523	void v3math_object::test<32>()
524	{
525		F32 x =12.3524f, y = -342.f,z = 4.126341f;
526		LLVector3 vec3(x,y,z);
527		F32 mag = vec3.normVec();
528		mag = 1.f/ mag;
529		F32 val1 = x* mag, val2 = y* mag, val3 = z* mag;
530		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]));
531		x = 0.000000001f, y = 0.f, z = 0.f;
532		vec3.clearVec();
533		vec3.setVec(x,y,z);
534		mag = vec3.normVec();
535		val1 = x* mag, val2 = y* mag, val3 = z* mag;
536		ensure("2:normVec: Fail ", (mag == 0.) && (0. == vec3.mV[VX]) && (0. == vec3.mV[VY])&& (0. == vec3.mV[VZ]));
537	}
538
539	template<> template<>
540	void v3math_object::test<33>()
541	{
542		F32 x = -202.23412f, y = 123.2312f, z = -89.f;
543		LLVector3 vec(x,y,z);
544		vec.snap(2);
545		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]));
546	}
547		
548	template<> template<>
549	void v3math_object::test<34>()
550	{
551		F32 x = 10.f, y = 20.f, z = -15.f;
552		F32 x1, y1, z1;
553		F32 lowerxy = 0.f, upperxy = 1.0f, lowerz = -1.0f, upperz = 1.f;
554		LLVector3 vec3(x,y,z);
555		vec3.quantize16(lowerxy,upperxy,lowerz,upperz);
556		x1 = U16_to_F32(F32_to_U16(x, lowerxy, upperxy), lowerxy, upperxy);
557		y1 = U16_to_F32(F32_to_U16(y, lowerxy, upperxy), lowerxy, upperxy);
558		z1 = U16_to_F32(F32_to_U16(z, lowerz,  upperz),  lowerz,  upperz);
559		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]));
560		LLVector3 vec3a(x,y,z);
561		vec3a.quantize8(lowerxy,upperxy,lowerz,upperz);
562		x1 = U8_to_F32(F32_to_U8(x, lowerxy, upperxy), lowerxy, upperxy);
563		y1 = U8_to_F32(F32_to_U8(y, lowerxy, upperxy), lowerxy, upperxy);
564		z1 = U8_to_F32(F32_to_U8(z, lowerz, upperz), lowerz, upperz);
565		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]));
566	}
567
568	template<> template<>
569	void v3math_object::test<35>()
570	{
571		LLSD sd = LLSD::emptyArray();
572		sd[0] = 1.f;
573
574		LLVector3 parsed_1(sd);
575		ensure("1:LLSD parse: Fail ", is_approx_equal(parsed_1.mV[VX], 1.f) && is_approx_equal(parsed_1.mV[VY], 0.f) && is_approx_equal(parsed_1.mV[VZ], 0.f));
576
577		sd[1] = 2.f;
578		LLVector3 parsed_2(sd);
579		ensure("2:LLSD parse: Fail ", is_approx_equal(parsed_2.mV[VX], 1.f) && is_approx_equal(parsed_2.mV[VY], 2.f) && is_approx_equal(parsed_2.mV[VZ], 0.f));
580
581		sd[2] = 3.f;
582		LLVector3 parsed_3(sd);
583		ensure("3:LLSD parse: Fail ", is_approx_equal(parsed_3.mV[VX], 1.f) && is_approx_equal(parsed_3.mV[VY], 2.f) && is_approx_equal(parsed_3.mV[VZ], 3.f));
584	}
585}