1 // shape_test.h (generic shape interface test functions)
2 //
3 //  The WorldForge Project
4 //  Copyright (C) 2001  The WorldForge Project
5 //
6 //  This program is free software; you can redistribute it and/or modify
7 //  it under the terms of the GNU General Public License as published by
8 //  the Free Software Foundation; either version 2 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 //
20 //  For information about WorldForge and its authors, please contact
21 //  the Worldforge Web Site at http://www.worldforge.org.
22 
23 // Author: Ron Steinke
24 // Created: 2001-1-6
25 
26 #ifndef WFMATH_SHAPE_TEST_H
27 #define WFMATH_SHAPE_TEST_H
28 
29 #include "const.h"
30 #include "vector.h"
31 #include "rotmatrix.h"
32 #include "point.h"
33 #include "axisbox.h"
34 #include "ball.h"
35 #include "intersect.h"
36 #include "stream.h"
37 
38 namespace WFMath {
39 
40 template<int dim, template<int> class Shape>
test_shape_no_rotate(const Shape<dim> & s)41 void test_shape_no_rotate(const Shape<dim>& s)
42 {
43   Shape<dim> s2 = s;
44 
45   size_t corners = s2.numCorners();
46 
47   Point<dim> p = s2.getCenter();
48   Vector<dim> v;
49 
50   v.zero();
51   v[0] = 1;
52   s2.shift(v);
53 
54   for(size_t i = 0; i < corners; ++i) {
55     s2.moveCornerTo(p, i);
56     p = s2.getCorner(i);
57   }
58 
59   s2.moveCenterTo(p);
60 
61   assert(s2 == s);
62 
63   AxisBox<dim> box = s.boundingBox();
64   assert(Contains(box, s, false));
65   Ball<dim> ball1 = s.boundingSphere(), ball2 = s.boundingSphereSloppy();
66 //  cout << ball1 << std::endl << ball2 << std::endl;
67   assert(Contains(ball1, s, false));
68   assert(Contains(ball2, ball1, false));
69 }
70 
71 template<int dim, template<int> class Shape>
test_shape(const Shape<dim> & s)72 void test_shape(const Shape<dim>& s)
73 {
74   test_shape_no_rotate(s);
75 
76   Shape<dim> s2 = s;
77   RotMatrix<dim> m;
78   Point<dim> p;
79   size_t corners = s2.numCorners();
80 
81   if(dim >= 2)
82     m.rotation(0, 1, numeric_constants<CoordType>::pi() / 6);
83   else
84     m.identity();
85 
86   for(size_t i = 0; i < corners; ++i) {
87     s2.rotateCorner(m, i);
88     p = s2.getCorner(i);
89   }
90 
91   s2.rotatePoint(m, p);
92   s2.rotateCenter(m);
93 }
94 
95 } // namespace WFMath
96 
97 #endif // WFMATH_SHAPE_TEST_H
98