source: molecuilder/src/unittests/tesselation_boundarytriangleunittest.cpp@ 32842d8

Last change on this file since 32842d8 was e7ea64, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Changed implementation of Vector to forward operations to contained objects

  • Property mode set to 100644
File size: 7.3 KB
RevLine 
[a34fab]1/*
2 * tesselation_boundarytriangleunittest.cpp
3 *
4 * Created on: Jan 13, 2010
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <cstring>
15
16#include "defs.hpp"
17#include "tesselation.hpp"
18#include "tesselation_boundarytriangleunittest.hpp"
19
[44becc]20#ifdef HAVE_TESTRUNNER
21#include "UnitTestMain.hpp"
22#endif /*HAVE_TESTRUNNER*/
23
[a34fab]24#define SPHERERADIUS 2.
25
26/********************************************** Test classes **************************************/
27
28// Registers the fixture into the 'registry'
29CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest );
30
31
32void TesselationBoundaryTriangleTest::setUp()
33{
34 setVerbosity(5);
35
36 // create nodes
[ececad]37 tesselpoints[0] = new TesselPoint;
38 tesselpoints[0]->node = new Vector(0., 0., 0.);
39 tesselpoints[0]->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
40 strcpy(tesselpoints[0]->Name, "1");
41 tesselpoints[0]->nr = 1;
42 points[0] = new BoundaryPointSet(tesselpoints[0]);
43 tesselpoints[1] = new TesselPoint;
44 tesselpoints[1]->node = new Vector(0., 1., 0.);
45 tesselpoints[1]->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
46 strcpy(tesselpoints[1]->Name, "2");
47 tesselpoints[1]->nr = 2;
48 points[1] = new BoundaryPointSet(tesselpoints[1]);
49 tesselpoints[2] = new TesselPoint;
50 tesselpoints[2] ->node = new Vector(1., 0., 0.);
51 tesselpoints[2] ->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
52 strcpy(tesselpoints[2] ->Name, "3");
53 tesselpoints[2] ->nr = 3;
54 points[2] = new BoundaryPointSet(tesselpoints[2] );
[a34fab]55
56 // create line
57 lines[0] = new BoundaryLineSet(points[0], points[1], 0);
58 lines[1] = new BoundaryLineSet(points[1], points[2], 1);
59 lines[2] = new BoundaryLineSet(points[0], points[2], 2);
60
61 // create triangle
62 triangle = new BoundaryTriangleSet(lines, 0);
63 triangle->GetNormalVector(Vector(0.,0.,1.));
64};
65
66
67void TesselationBoundaryTriangleTest::tearDown()
68{
69 delete(triangle);
[ececad]70 for (int i=0;i<3;++i) {
71 // TesselPoint does not delete its vector as it only got a reference
72 delete tesselpoints[i]->node;
73 delete tesselpoints[i];
74 }
[a34fab]75 MemoryUsageObserver::purgeInstance();
76 logger::purgeInstance();
77 errorLogger::purgeInstance();
78};
79
80/** UnitTest for Tesselation::IsInnerPoint()
81 */
82void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest()
83{
84 Vector TestIntersection;
85 Vector Point;
86
87 // simple test on y line
[e7ea64]88 Point = Vector(-1.,0.5,0.);
[a34fab]89 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]90 Point = Vector(0.,0.5,0.);
[a34fab]91 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[e7ea64]92 Point = Vector(-4.,0.5,0.);
[a34fab]93 CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]94 Point = Vector(0.,0.5,0.);
[a34fab]95 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
96
97 // simple test on x line
[e7ea64]98 Point = Vector(0.5,-1.,0.);
[a34fab]99 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]100 Point = Vector(0.5,0.,0.);
[a34fab]101 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[e7ea64]102 Point = Vector(0.5,-6.,0.);
[a34fab]103 CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]104 Point = Vector(0.5,0.,0.);
[a34fab]105 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
106
107 // simple test on slanted line
[e7ea64]108 Point = Vector(1.,1.,0.);
[a34fab]109 CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]110 Point = Vector(0.5,0.5,0.);
[a34fab]111 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[e7ea64]112 Point = Vector(5.,5.,0.);
[a34fab]113 CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]114 Point = Vector(0.5,0.5,0.);
[a34fab]115 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
116
117 // simple test on first node
[e7ea64]118 Point = Vector(-1.,-1.,0.);
[a34fab]119 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]120 Point = Vector(0.,0.,0.);
[a34fab]121 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
122
123 // simple test on second node
[e7ea64]124 Point = Vector(0.,2.,0.);
[a34fab]125 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]126 Point = Vector(0.,1.,0.);
[a34fab]127 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
128
129 // simple test on third node
[e7ea64]130 Point = Vector(2.,0.,0.);
[a34fab]131 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]132 Point = Vector(1.,0.,0.);
[a34fab]133 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
134};
135
136/** UnitTest for Tesselation::IsInnerPoint()
137 */
138void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest()
139{
140 Vector TestIntersection;
141 Vector Point;
142
143 // straight down/up
[e7ea64]144 Point = Vector(1./3.,1./3.,+5.);
[a34fab]145 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]146 Point = Vector(1./3.,1./3.,0.);
[a34fab]147 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[e7ea64]148 Point = Vector(1./3.,1./3.,-5.);
[a34fab]149 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]150 Point = Vector(1./3.,1./3.,0.);
[a34fab]151 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
152
153 // simple test on y line
[e7ea64]154 Point = Vector(-1.,0.5,+2.);
[a34fab]155 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]156 Point = Vector(0.,0.5,0.);
[a34fab]157 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[e7ea64]158 Point = Vector(-1.,0.5,-3.);
[a34fab]159 CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]160 Point = Vector(0.,0.5,0.);
[a34fab]161 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
162
163 // simple test on x line
[e7ea64]164 Point = Vector(0.5,-1.,+1.);
[a34fab]165 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]166 Point = Vector(0.5,0.,0.);
[a34fab]167 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[e7ea64]168 Point = Vector(0.5,-1.,-2.);
[a34fab]169 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]170 Point = Vector(0.5,0.,0.);
[a34fab]171 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
172
173 // simple test on slanted line
[e7ea64]174 Point = Vector(1.,1.,+3.);
[a34fab]175 CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]176 Point = Vector(0.5,0.5,0.);
[a34fab]177 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[e7ea64]178 Point = Vector(1.,1.,-4.);
[a34fab]179 CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]180 Point = Vector(0.5,0.5,0.);
[a34fab]181 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
182
183 // simple test on first node
[e7ea64]184 Point = Vector(-1.,-1.,5.);
[a34fab]185 CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]186 Point = Vector(0.,0.,0.);
[a34fab]187 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
188
189 // simple test on second node
[e7ea64]190 Point = Vector(0.,2.,5.);
[a34fab]191 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]192 Point = Vector(0.,1.,0.);
[a34fab]193 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
194
195 // simple test on third node
[e7ea64]196 Point = Vector(2.,0.,5.);
[a34fab]197 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
[e7ea64]198 Point = Vector(1.,0.,0.);
[a34fab]199 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
200};
Note: See TracBrowser for help on using the repository browser.