1 // Some tests for vgl_ray_3d
2 // J.L. Mundy Sept. 17, 2010
3 
4 #include <iostream>
5 #ifdef _MSC_VER
6 #  include "vcl_msvc_warnings.h"
7 #endif
8 #include "testlib/testlib_test.h"
9 #include "vgl/vgl_ray_3d.h"
10 #include "vgl/vgl_closest_point.h"
11 
12 
13 static void
test_constructor()14 test_constructor()
15 {
16   vgl_vector_3d<double> t(0, 0, 2);
17   vgl_point_3d<double> p(1, 2, 3);
18   vgl_ray_3d<double> ray(p, t);
19   vgl_point_3d<double> origin = ray.origin();
20   vgl_vector_3d<double> dir = ray.direction();
21   TEST_NEAR("Constructor from point and dir - compare origin", origin.x() + origin.y(), 3.0, 1e-5);
22   TEST_NEAR("Constructor from point and dir - compare dir", dir.z_, 1.0, 1e-5);
23   vgl_point_3d<double> p1(1, 2, 4);
24   vgl_ray_3d<double> ray1(p, p1);
25   origin = ray1.origin();
26   dir = ray1.direction();
27   TEST_NEAR("Constructor from point-point - compare origin", origin.x() + origin.y(), 3.0, 1e-5);
28   TEST_NEAR("Constructor from point-point - compare dir", dir.z_, 1.0, 1e-5);
29 }
30 
31 static void
test_operations()32 test_operations()
33 {
34   vgl_vector_3d<double> t(0, 0, 1);
35   vgl_point_3d<double> p(1, 2, 3), pt(1, 2, 2), clpt;
36   vgl_ray_3d<double> ray(p, t);
37   clpt = vgl_closest_point(ray, pt);
38   bool con = ray.contains(clpt);
39   TEST("Contains ", con, false);
40 }
41 
42 void
test_ray_3d()43 test_ray_3d()
44 {
45   std::cout << "*****************************\n"
46             << " Testing vgl_ray_3d\n"
47             << "*****************************\n\n";
48 
49   test_constructor();
50   test_operations();
51 }
52 
53 
54 TESTMAIN(test_ray_3d);
55