summaryrefslogtreecommitdiff
path: root/indra/llmath/tests/mathmisc_test.cpp
blob: cecb8b2edb0e8a477742bc78022afbe625b53f89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
/** 
 * @file math.cpp
 * @author Phoenix
 * @date 2005-09-26
 * @brief Tests for the llmath library.
 *
 * $LicenseInfo:firstyear=2005&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2010, Linden Research, Inc.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation;
 * version 2.1 of the License only.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 * 
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */

#include "linden_common.h"
#include "../test/lltut.h"

#include "llcrc.h"
#include "llrand.h"
#include "lluuid.h"

#include "../llline.h"
#include "../llmath.h"
#include "../llsphere.h"
#include "../v3math.h"

namespace tut
{
	struct math_data
	{
	};
	typedef test_group<math_data> math_test;
	typedef math_test::object math_object;
	tut::math_test tm("BasicLindenMath");

	template<> template<>
	void math_object::test<1>()
	{
		S32 val = 89543;
		val = llabs(val);
		ensure("integer absolute value 1", (89543 == val));
		val = -500;
		val = llabs(val);
		ensure("integer absolute value 2", (500 == val));
	}

	template<> template<>
	void math_object::test<2>()
	{
		F32 val = -2583.4f;
		val = llabs(val);
		ensure("float absolute value 1", (2583.4f == val));
		val = 430903.f;
		val = llabs(val);
		ensure("float absolute value 2", (430903.f == val));
	}

	template<> template<>
	void math_object::test<3>()
	{
		F64 val = 387439393.987329839;
		val = llabs(val);
		ensure("double absolute value 1", (387439393.987329839 == val));
		val = -8937843.9394878;
		val = llabs(val);
		ensure("double absolute value 2", (8937843.9394878 == val));
	}

	template<> template<>
	void math_object::test<4>()
	{
		F32 val = 430903.9f;
		S32 val1 = lltrunc(val);
		ensure("float truncate value 1", (430903 == val1));
		val = -2303.9f;
		val1 = lltrunc(val);
		ensure("float truncate value 2", (-2303  == val1));
	}

	template<> template<>
	void math_object::test<5>()
	{
		F64 val = 387439393.987329839 ;
		S32 val1 = lltrunc(val);
		ensure("float truncate value 1", (387439393 == val1));
		val = -387439393.987329839;
		val1 = lltrunc(val);
		ensure("float truncate value 2", (-387439393  == val1));
	}

	template<> template<>
	void math_object::test<6>()
	{
		F32 val = 430903.2f;
		S32 val1 = llfloor(val);
		ensure("float llfloor value 1", (430903 == val1));
		val = -430903.9f;
		val1 = llfloor(val);
		ensure("float llfloor value 2", (-430904 == val1));
	}

	template<> template<>
	void math_object::test<7>()
	{
		F32 val = 430903.2f;
		S32 val1 = llceil(val);
		ensure("float llceil value 1", (430904 == val1));
		val = -430903.9f;
		val1 = llceil(val);
		ensure("float llceil value 2", (-430903 == val1));
	}

	template<> template<>
	void math_object::test<8>()
	{
		F32 val = 430903.2f;
		S32 val1 = ll_round(val);
		ensure("float ll_round value 1", (430903 == val1));
		val = -430903.9f;
		val1 = ll_round(val);
		ensure("float ll_round value 2", (-430904 == val1));
	}

	template<> template<>
	void math_object::test<9>()
	{
		F32 val = 430905.2654f, nearest = 100.f;
		val = ll_round(val, nearest);
		ensure("float ll_round value 1", (430900 == val));
		val = -430905.2654f, nearest = 10.f;
		val = ll_round(val, nearest);
		ensure("float ll_round value 1", (-430910 == val));
	}

	template<> template<>
	void math_object::test<10>()
	{
		F64 val = 430905.2654, nearest = 100.0;
		val = ll_round(val, nearest);
		ensure("double ll_round value 1", (430900 == val));
		val = -430905.2654, nearest = 10.0;
		val = ll_round(val, nearest);
		ensure("double ll_round value 1", (-430910.00000 == val));
	}

	template<> template<>
	void math_object::test<11>()
	{
		const F32	F_PI		= 3.1415926535897932384626433832795f;
		F32 angle = 3506.f;
		angle =  llsimple_angle(angle);
		ensure("llsimple_angle  value 1", (angle <=F_PI && angle >= -F_PI));
		angle = -431.f;
		angle =  llsimple_angle(angle);
		ensure("llsimple_angle  value 1", (angle <=F_PI && angle >= -F_PI));
	}
}

namespace tut
{
	struct uuid_data
	{
		LLUUID id;
	};
	typedef test_group<uuid_data> uuid_test;
	typedef uuid_test::object uuid_object;
	tut::uuid_test tu("LLUUID");

	template<> template<>
	void uuid_object::test<1>()
	{
		ensure("uuid null", id.isNull());
		id.generate();
		ensure("generate not null", id.notNull());
		id.setNull();
		ensure("set null", id.isNull());
	}

	template<> template<>
	void uuid_object::test<2>()
	{
		id.generate();
		LLUUID a(id);
		ensure_equals("copy equal", id, a);
		a.generate();
		ensure_not_equals("generate not equal", id, a);
		a = id;
		ensure_equals("assignment equal", id, a);
	}

	template<> template<>
	void uuid_object::test<3>()
	{
		id.generate();
		LLUUID copy(id);
		LLUUID mask;
		mask.generate();
		copy ^= mask;
		ensure_not_equals("mask not equal", id, copy);
		copy ^= mask;
		ensure_equals("mask back", id, copy);
	}

	template<> template<>
	void uuid_object::test<4>()
	{
		id.generate();
		std::string id_str = id.asString();
		LLUUID copy(id_str.c_str());
		ensure_equals("string serialization", id, copy);
	}
	
}

namespace tut
{
	struct crc_data
	{
	};
	typedef test_group<crc_data> crc_test;
	typedef crc_test::object crc_object;
	tut::crc_test tc("LLCrc");

	template<> template<>
	void crc_object::test<1>()
	{
		/* Test buffer update and individual char update */
		const char TEST_BUFFER[] = "hello &#$)$&Nd0";
		LLCRC c1, c2;
		c1.update((U8*)TEST_BUFFER, sizeof(TEST_BUFFER) - 1);
		char* rh = (char*)TEST_BUFFER;
		while(*rh != '\0')
		{
			c2.update(*rh);
			++rh;
		}
		ensure_equals("crc update 1", c1.getCRC(), c2.getCRC());
	}

	template<> template<>
	void crc_object::test<2>()
	{
		/* Test mixing of buffer and individual char update */
		const char TEST_BUFFER1[] = "Split Buffer one $^%$%#@$";
		const char TEST_BUFFER2[] = "Split Buffer two )(8723#5dsds";
		LLCRC c1, c2;
		c1.update((U8*)TEST_BUFFER1, sizeof(TEST_BUFFER1) - 1);
		char* rh = (char*)TEST_BUFFER2;
		while(*rh != '\0')
		{
			c1.update(*rh);
			++rh;
		}

		rh = (char*)TEST_BUFFER1;
		while(*rh != '\0')
		{
			c2.update(*rh);
			++rh;
		}
		c2.update((U8*)TEST_BUFFER2, sizeof(TEST_BUFFER2) - 1);

		ensure_equals("crc update 2", c1.getCRC(), c2.getCRC());
	}
}

namespace tut
{
	struct sphere_data
	{
	};
	typedef test_group<sphere_data> sphere_test;
	typedef sphere_test::object sphere_object;
	tut::sphere_test tsphere("LLSphere");

	template<> template<>
	void sphere_object::test<1>()
	{
		// test LLSphere::contains() and ::overlaps()
		S32 number_of_tests = 10;
		for (S32 test = 0; test < number_of_tests; ++test)
		{
			LLVector3 first_center(1.f, 1.f, 1.f);
			F32 first_radius = 3.f;
			LLSphere first_sphere( first_center, first_radius );
	
			F32 half_millimeter = 0.0005f;
			LLVector3 direction( ll_frand(2.f) - 1.f, ll_frand(2.f) - 1.f, ll_frand(2.f) - 1.f);
			direction.normalize();
	
			F32 distance = ll_frand(first_radius - 2.f * half_millimeter);
			LLVector3 second_center = first_center + distance * direction;
			F32 second_radius = first_radius - distance - half_millimeter;
			LLSphere second_sphere( second_center, second_radius );
			ensure("first sphere should contain the second", first_sphere.contains(second_sphere));
			ensure("first sphere should overlap the second", first_sphere.overlaps(second_sphere));
	
			distance = first_radius + ll_frand(first_radius);
			second_center = first_center + distance * direction;
			second_radius = distance - first_radius + half_millimeter;
			second_sphere.set( second_center, second_radius );
			ensure("first sphere should NOT contain the second", !first_sphere.contains(second_sphere));
			ensure("first sphere should overlap the second", first_sphere.overlaps(second_sphere));
	
			distance = first_radius + ll_frand(first_radius) + half_millimeter;
			second_center = first_center + distance * direction;
			second_radius = distance - first_radius - half_millimeter;
			second_sphere.set( second_center, second_radius );
			ensure("first sphere should NOT contain the second", !first_sphere.contains(second_sphere));
			ensure("first sphere should NOT overlap the second", !first_sphere.overlaps(second_sphere));
		}
	}

	template<> template<>
	void sphere_object::test<2>()
	{
		skip("See SNOW-620.  Neither the test nor the code being tested seem good.  Also sim-only.");

		// test LLSphere::getBoundingSphere()
		S32 number_of_tests = 100;
		S32 number_of_spheres = 10;
		F32 sphere_center_range = 32.f;
		F32 sphere_radius_range = 5.f;

		for (S32 test = 0; test < number_of_tests; ++test)
		{
			// gegnerate a bunch of random sphere
			std::vector< LLSphere > sphere_list;
			for (S32 sphere_count=0; sphere_count < number_of_spheres; ++sphere_count)
			{
				LLVector3 direction( ll_frand(2.f) - 1.f, ll_frand(2.f) - 1.f, ll_frand(2.f) - 1.f);
				direction.normalize();
				F32 distance = ll_frand(sphere_center_range);
				LLVector3 center = distance * direction;
				F32 radius = ll_frand(sphere_radius_range);
				LLSphere sphere( center, radius );
				sphere_list.push_back(sphere);
			}

			// compute the bounding sphere
			LLSphere bounding_sphere = LLSphere::getBoundingSphere(sphere_list);

			// make sure all spheres are inside the bounding sphere
			{
				std::vector< LLSphere >::const_iterator sphere_itr;
				for (sphere_itr = sphere_list.begin(); sphere_itr != sphere_list.end(); ++sphere_itr)
				{
					ensure("sphere should be contained by the bounding sphere", bounding_sphere.contains(*sphere_itr));
				}
			}

			// TODO -- improve LLSphere::getBoundingSphere() to the point where
			// we can reduce the 'expansion' in the two tests below to about 
			// 2 mm or less

			F32 expansion = 0.005f;
			// move all spheres out a little bit 
			// and count how many are NOT contained
			{
				std::vector< LLVector3 > uncontained_directions;
				std::vector< LLSphere >::iterator sphere_itr;
				for (sphere_itr = sphere_list.begin(); sphere_itr != sphere_list.end(); ++sphere_itr)
				{
					LLVector3 direction = sphere_itr->getCenter() - bounding_sphere.getCenter();
					direction.normalize();
	
					sphere_itr->setCenter( sphere_itr->getCenter() + expansion * direction );
					if (! bounding_sphere.contains( *sphere_itr ) )
					{
						uncontained_directions.push_back(direction);
					}
				}
				ensure("when moving spheres out there should be at least two uncontained spheres", 
						uncontained_directions.size() > 1);

				/* TODO -- when the bounding sphere algorithm is improved we can open up this test
				 * at the moment it occasionally fails when the sphere collection is tight and small
				 * (2 meters or less)
				if (2 == uncontained_directions.size() )
				{
					// if there were only two uncontained spheres then
					// the two directions should be nearly opposite
					F32 dir_dot = uncontained_directions[0] * uncontained_directions[1];
					ensure("two uncontained spheres should lie opposite the bounding center", dir_dot < -0.95f);
				}
				*/
			}

			// compute the new bounding sphere
			bounding_sphere = LLSphere::getBoundingSphere(sphere_list);

			// increase the size of all spheres a little bit
			// and count how many are NOT contained
			{
				std::vector< LLVector3 > uncontained_directions;
				std::vector< LLSphere >::iterator sphere_itr;
				for (sphere_itr = sphere_list.begin(); sphere_itr != sphere_list.end(); ++sphere_itr)
				{
					LLVector3 direction = sphere_itr->getCenter() - bounding_sphere.getCenter();
					direction.normalize();
	
					sphere_itr->setRadius( sphere_itr->getRadius() + expansion );
					if (! bounding_sphere.contains( *sphere_itr ) )
					{
						uncontained_directions.push_back(direction);
					}
				}
				ensure("when boosting sphere radii there should be at least two uncontained spheres", 
						uncontained_directions.size() > 1);

				/* TODO -- when the bounding sphere algorithm is improved we can open up this test
				 * at the moment it occasionally fails when the sphere collection is tight and small
				 * (2 meters or less)
				if (2 == uncontained_directions.size() )
				{
					// if there were only two uncontained spheres then
					// the two directions should be nearly opposite
					F32 dir_dot = uncontained_directions[0] * uncontained_directions[1];
					ensure("two uncontained spheres should lie opposite the bounding center", dir_dot < -0.95f);
				}
				*/
			}
		}
	}
}

namespace tut
{
	F32 SMALL_RADIUS = 1.0f;
	F32 MEDIUM_RADIUS = 5.0f;
	F32 LARGE_RADIUS = 10.0f;

	struct line_data
	{
	};
	typedef test_group<line_data> line_test;
	typedef line_test::object line_object;
	tut::line_test tline("LLLine");

	template<> template<>
	void line_object::test<1>()
	{
		// this is a test for LLLine::intersects(point) which returns TRUE 
		// if the line passes within some tolerance of point

		// these tests will have some floating point error, 
		// so we need to specify how much error is ok
		F32 allowable_relative_error = 0.00001f;
		S32 number_of_tests = 100;
		for (S32 test = 0; test < number_of_tests; ++test)
		{
			// generate some random point to be on the line
			LLVector3 point_on_line( ll_frand(2.f) - 1.f, 
			   						 ll_frand(2.f) - 1.f, 
			   						 ll_frand(2.f) - 1.f);
			point_on_line.normalize();
			point_on_line *= ll_frand(LARGE_RADIUS);

			// generate some random point to "intersect"
			LLVector3 random_direction ( ll_frand(2.f) - 1.f, 
			   							 ll_frand(2.f) - 1.f, 
			   							 ll_frand(2.f) - 1.f);
			random_direction.normalize();

			LLVector3 random_offset( ll_frand(2.f) - 1.f, 
			   						 ll_frand(2.f) - 1.f, 
			   						 ll_frand(2.f) - 1.f);
			random_offset.normalize();
			random_offset *= ll_frand(SMALL_RADIUS);

			LLVector3 point = point_on_line + MEDIUM_RADIUS * random_direction
				+ random_offset;
	
			// compute the axis of approach (a unit vector between the points)
			LLVector3 axis_of_approach = point - point_on_line;
			axis_of_approach.normalize();
	
			// compute the direction of the the first line (perp to axis_of_approach)
			LLVector3 first_dir( ll_frand(2.f) - 1.f, 
			   					 ll_frand(2.f) - 1.f, 
			   					 ll_frand(2.f) - 1.f);
			first_dir.normalize();
			F32 dot = first_dir * axis_of_approach;		
			first_dir -= dot * axis_of_approach;	// subtract component parallel to axis
			first_dir.normalize();
	
			// construct the line
			LLVector3 another_point_on_line = point_on_line + ll_frand(LARGE_RADIUS) * first_dir;
			LLLine line(another_point_on_line, point_on_line);
	
			// test that the intersection point is within MEDIUM_RADIUS + SMALL_RADIUS
			F32 test_radius = MEDIUM_RADIUS + SMALL_RADIUS;
			test_radius += (LARGE_RADIUS * allowable_relative_error);
			ensure("line should pass near intersection point", line.intersects(point, test_radius));

			test_radius = allowable_relative_error * (point - point_on_line).length();
			ensure("line should intersect point used to define it", line.intersects(point_on_line, test_radius));
		}
	}

	template<> template<>
	void line_object::test<2>()
	{
          /*
            These tests fail intermittently on all platforms - see DEV-16600
            Commenting this out until dev has time to investigate.
            
		// this is a test for LLLine::nearestApproach(LLLIne) method
		// which computes the point on a line nearest another line

		// these tests will have some floating point error, 
		// so we need to specify how much error is ok
		// TODO -- make nearestApproach() algorithm more accurate so
		// we can tighten the allowable_error.  Most tests are tighter
		// than one milimeter, however when doing randomized testing
		// you can walk into inaccurate cases.
		F32 allowable_relative_error = 0.001f;
		S32 number_of_tests = 100;
		for (S32 test = 0; test < number_of_tests; ++test)
		{
			// generate two points to be our known nearest approaches
			LLVector3 some_point( ll_frand(2.f) - 1.f, 
			   					  ll_frand(2.f) - 1.f, 
			   					  ll_frand(2.f) - 1.f);
			some_point.normalize();
			some_point *= ll_frand(LARGE_RADIUS);

			LLVector3 another_point( ll_frand(2.f) - 1.f, 
			   						 ll_frand(2.f) - 1.f, 
			   						 ll_frand(2.f) - 1.f);
			another_point.normalize();
			another_point *= ll_frand(LARGE_RADIUS);

			// compute the axis of approach (a unit vector between the points)
			LLVector3 axis_of_approach = another_point - some_point;
			axis_of_approach.normalize();
	
			// compute the direction of the the first line (perp to axis_of_approach)
			LLVector3 first_dir( ll_frand(2.f) - 1.f, 
			   					 ll_frand(2.f) - 1.f, 
			   					 ll_frand(2.f) - 1.f);
			F32 dot = first_dir * axis_of_approach;		
			first_dir -= dot * axis_of_approach;		// subtract component parallel to axis
			first_dir.normalize();						// normalize
	
			// compute the direction of the the second line
			LLVector3 second_dir( ll_frand(2.f) - 1.f, 
			   					  ll_frand(2.f) - 1.f, 
			   					  ll_frand(2.f) - 1.f);
			dot = second_dir * axis_of_approach;		
			second_dir -= dot * axis_of_approach;
			second_dir.normalize();

			// make sure the lines aren't too parallel, 
			dot = fabsf(first_dir * second_dir);
			if (dot > 0.99f)
			{
				// skip this test, we're not interested in testing 
				// the intractible cases
				continue;
			}
	
			// construct the lines
			LLVector3 first_point = some_point + ll_frand(LARGE_RADIUS) * first_dir;
			LLLine first_line(first_point, some_point);
	
			LLVector3 second_point = another_point + ll_frand(LARGE_RADIUS) * second_dir;
			LLLine second_line(second_point, another_point);
	
			// compute the points of nearest approach
			LLVector3 some_computed_point = first_line.nearestApproach(second_line);
			LLVector3 another_computed_point = second_line.nearestApproach(first_line);
	
			// compute the error
			F32 first_error = (some_point - some_computed_point).length();
			F32 scale = llmax((some_point - another_point).length(), some_point.length());
			scale = llmax(scale, another_point.length());
			scale = llmax(scale, 1.f);
			F32 first_relative_error = first_error / scale;

			F32 second_error = (another_point - another_computed_point).length();
			F32 second_relative_error = second_error / scale;

			//if (first_relative_error > allowable_relative_error)
			//{
			//	std::cout << "first_error = " << first_error 
			//		<< "  first_relative_error = " << first_relative_error 
			//		<< "  scale = " << scale 
			//		<< "  dir_dot = " << (first_dir * second_dir)
			//		<< std::endl;
			//}
			//if (second_relative_error > allowable_relative_error)
			//{
			//	std::cout << "second_error = " << second_error 
			//		<< "  second_relative_error = " << second_relative_error 
			//		<< "  scale = " << scale 
			//		<< "  dist = " << (some_point - another_point).length()
			//		<< "  dir_dot = " << (first_dir * second_dir)
			//		<< std::endl;
			//}

			// test that the errors are small

			ensure("first line should accurately compute its closest approach", 
					first_relative_error <= allowable_relative_error);
			ensure("second line should accurately compute its closest approach", 
					second_relative_error <= allowable_relative_error);
		}
          */
	}

	F32 ALMOST_PARALLEL = 0.99f;
	template<> template<>
	void line_object::test<3>()
	{
		// this is a test for LLLine::getIntersectionBetweenTwoPlanes() method

		// first some known tests
		LLLine xy_plane(LLVector3(0.f, 0.f, 2.f), LLVector3(0.f, 0.f, 3.f));
		LLLine yz_plane(LLVector3(2.f, 0.f, 0.f), LLVector3(3.f, 0.f, 0.f));
		LLLine zx_plane(LLVector3(0.f, 2.f, 0.f), LLVector3(0.f, 3.f, 0.f));

		LLLine x_line;
		LLLine y_line;
		LLLine z_line;

		bool x_success = LLLine::getIntersectionBetweenTwoPlanes(x_line, xy_plane, zx_plane);
		bool y_success = LLLine::getIntersectionBetweenTwoPlanes(y_line, yz_plane, xy_plane);
		bool z_success = LLLine::getIntersectionBetweenTwoPlanes(z_line, zx_plane, yz_plane);

		ensure("xy and zx planes should intersect", x_success);
		ensure("yz and xy planes should intersect", y_success);
		ensure("zx and yz planes should intersect", z_success);

		LLVector3 direction = x_line.getDirection();
		ensure("x_line should be parallel to x_axis", fabs(direction.mV[VX]) == 1.f
													  && 0.f == direction.mV[VY]
													  && 0.f == direction.mV[VZ] );
		direction = y_line.getDirection();
		ensure("y_line should be parallel to y_axis", 0.f == direction.mV[VX]
													  && fabs(direction.mV[VY]) == 1.f
													  && 0.f == direction.mV[VZ] );
		direction = z_line.getDirection();
		ensure("z_line should be parallel to z_axis", 0.f == direction.mV[VX]
													  && 0.f == direction.mV[VY]
													  && fabs(direction.mV[VZ]) == 1.f );

		// next some random tests
		F32 allowable_relative_error = 0.0001f;
		S32 number_of_tests = 20;
		for (S32 test = 0; test < number_of_tests; ++test)
		{
			// generate the known line
			LLVector3 some_point( ll_frand(2.f) - 1.f, 
								  ll_frand(2.f) - 1.f, 
								  ll_frand(2.f) - 1.f);
			some_point.normalize();
			some_point *= ll_frand(LARGE_RADIUS);
			LLVector3 another_point( ll_frand(2.f) - 1.f, 
									 ll_frand(2.f) - 1.f, 
									 ll_frand(2.f) - 1.f);
			another_point.normalize();
			another_point *= ll_frand(LARGE_RADIUS);
			LLLine known_intersection(some_point, another_point);

			// compute a plane that intersect the line
			LLVector3 point_on_plane( ll_frand(2.f) - 1.f, 
									  ll_frand(2.f) - 1.f, 
									  ll_frand(2.f) - 1.f);
			point_on_plane.normalize();
			point_on_plane *= ll_frand(LARGE_RADIUS);
			LLVector3 plane_normal = (point_on_plane - some_point) % known_intersection.getDirection();
			plane_normal.normalize();
			LLLine first_plane(point_on_plane, point_on_plane + plane_normal);

			// compute a different plane that intersect the line
			LLVector3 point_on_different_plane( ll_frand(2.f) - 1.f, 
												ll_frand(2.f) - 1.f, 
												ll_frand(2.f) - 1.f);
			point_on_different_plane.normalize();
			point_on_different_plane *= ll_frand(LARGE_RADIUS);
			LLVector3 different_plane_normal = (point_on_different_plane - another_point) % known_intersection.getDirection();
			different_plane_normal.normalize();
			LLLine second_plane(point_on_different_plane, point_on_different_plane + different_plane_normal);

			if (fabs(plane_normal * different_plane_normal) > ALMOST_PARALLEL)
			{
				// the two planes are approximately parallel, so we won't test this case
				continue;
			}

			LLLine measured_intersection;
			bool success = LLLine::getIntersectionBetweenTwoPlanes(
					measured_intersection,
					first_plane,
					second_plane);

			try
			{
				ensure("plane intersection should succeed", success);

				F32 dot = fabs(known_intersection.getDirection() * measured_intersection.getDirection());
				ensure("measured intersection should be parallel to known intersection",
					   dot > ALMOST_PARALLEL);

				ensure("measured intersection should pass near known point",
					   measured_intersection.intersects(some_point, LARGE_RADIUS * allowable_relative_error));
			}
			catch (const failure&)
			{
				// If any of these assertions fail, since the values involved
				// are randomly generated, unless we report them, we have no
				// hope of diagnosing the problem.
				LL_INFOS()  << "some_point =               " << some_point << '\n'
							<< "another_point =            " << another_point << '\n'
							<< "known_intersection =       " << known_intersection << '\n'
							<< "point_on_plane =           " << point_on_plane << '\n'
							<< "plane_normal =             " << plane_normal << '\n'
							<< "first_plane =              " << first_plane << '\n'
							<< "point_on_different_plane = " << point_on_different_plane << '\n'
							<< "different_plane_normal =   " << different_plane_normal << '\n'
							<< "second_plane =             " << second_plane << '\n'
							<< "measured_intersection =    " << measured_intersection << LL_ENDL;
				throw;
			}
		}
	}
}