1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * LineUnittest.cpp
|
---|
25 | *
|
---|
26 | * Created on: May 27, 2010
|
---|
27 | * Author: crueger
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 |
|
---|
36 | #include "Exceptions.hpp"
|
---|
37 | #include "Vector.hpp"
|
---|
38 |
|
---|
39 | #include <cppunit/CompilerOutputter.h>
|
---|
40 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
41 | #include <cppunit/ui/text/TestRunner.h>
|
---|
42 |
|
---|
43 | #include <iostream>
|
---|
44 | #include <cmath>
|
---|
45 |
|
---|
46 | #include "LineUnitTest.hpp"
|
---|
47 |
|
---|
48 | #include "RealSpaceMatrix.hpp"
|
---|
49 |
|
---|
50 | #ifdef HAVE_TESTRUNNER
|
---|
51 | #include "UnitTestMain.hpp"
|
---|
52 | #endif /*HAVE_TESTRUNNER*/
|
---|
53 |
|
---|
54 | CPPUNIT_TEST_SUITE_REGISTRATION( LineUnittest );
|
---|
55 |
|
---|
56 | void LineUnittest::setUp(){
|
---|
57 | // three lines along the axes
|
---|
58 | la1 = new Line(zeroVec,unitVec[0]);
|
---|
59 | la2 = new Line(zeroVec,unitVec[1]);
|
---|
60 | la3 = new Line(zeroVec,unitVec[2]);
|
---|
61 |
|
---|
62 | // the lines along the planes defined by two coordinate axes
|
---|
63 | lp1 = new Line(unitVec[0],unitVec[0]-unitVec[1]);
|
---|
64 | lp2 = new Line(unitVec[1],unitVec[1]-unitVec[2]);
|
---|
65 | lp3 = new Line(unitVec[2],unitVec[2]-unitVec[0]);
|
---|
66 | }
|
---|
67 | void LineUnittest::tearDown(){
|
---|
68 | delete la1;
|
---|
69 | delete la2;
|
---|
70 | delete la3;
|
---|
71 |
|
---|
72 | delete lp1;
|
---|
73 | delete lp2;
|
---|
74 | delete lp3;
|
---|
75 | }
|
---|
76 |
|
---|
77 | void LineUnittest::constructionErrorTest(){
|
---|
78 | // test some constructions
|
---|
79 |
|
---|
80 | // direction+origin should never fail
|
---|
81 | CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[0]));
|
---|
82 | CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[1]));
|
---|
83 | CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,unitVec[2]));
|
---|
84 |
|
---|
85 | // two points fails if both points are the same
|
---|
86 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[0],unitVec[1]));
|
---|
87 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[1],unitVec[2]));
|
---|
88 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[2],unitVec[0]));
|
---|
89 | // for zerovectors
|
---|
90 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[0],zeroVec));
|
---|
91 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[1],zeroVec));
|
---|
92 | CPPUNIT_ASSERT_NO_THROW(makeLineThrough(unitVec[2],zeroVec));
|
---|
93 | // now we pass two times the same point
|
---|
94 | CPPUNIT_ASSERT_THROW(makeLineThrough(zeroVec,zeroVec),LinearDependenceException);
|
---|
95 | CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[0],unitVec[0]),LinearDependenceException);
|
---|
96 | CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[1],unitVec[1]),LinearDependenceException);
|
---|
97 | CPPUNIT_ASSERT_THROW(makeLineThrough(unitVec[2],unitVec[2]),LinearDependenceException);
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|
101 | bool testDirection(const Vector &dir1,const Vector &dir2){
|
---|
102 | return (dir1==dir2) || (dir1==-1*dir2);
|
---|
103 | }
|
---|
104 |
|
---|
105 | void LineUnittest::constructionResultTest(){
|
---|
106 | // test all directions
|
---|
107 | CPPUNIT_ASSERT(testDirection(la1->getDirection(),unitVec[0]));
|
---|
108 | CPPUNIT_ASSERT(testDirection(la2->getDirection(),unitVec[1]));
|
---|
109 | CPPUNIT_ASSERT(testDirection(la3->getDirection(),unitVec[2]));
|
---|
110 |
|
---|
111 | // test origins
|
---|
112 | CPPUNIT_ASSERT_EQUAL(la1->getOrigin(),zeroVec);
|
---|
113 | CPPUNIT_ASSERT_EQUAL(la2->getOrigin(),zeroVec);
|
---|
114 | CPPUNIT_ASSERT_EQUAL(la2->getOrigin(),zeroVec);
|
---|
115 |
|
---|
116 | // test if desired points are on the lines
|
---|
117 | CPPUNIT_ASSERT(la1->isContained(zeroVec));
|
---|
118 | CPPUNIT_ASSERT(la2->isContained(zeroVec));
|
---|
119 | CPPUNIT_ASSERT(la3->isContained(zeroVec));
|
---|
120 |
|
---|
121 | CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
|
---|
122 | CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
|
---|
123 | CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
|
---|
124 |
|
---|
125 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
|
---|
126 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
|
---|
127 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
|
---|
128 |
|
---|
129 | CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
|
---|
130 | CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
|
---|
131 | CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
|
---|
132 | }
|
---|
133 |
|
---|
134 | void LineUnittest::isContainedTest(){
|
---|
135 | // Zerovector on the axes lines
|
---|
136 | CPPUNIT_ASSERT(la1->isContained(zeroVec));
|
---|
137 | CPPUNIT_ASSERT(la2->isContained(zeroVec));
|
---|
138 | CPPUNIT_ASSERT(la3->isContained(zeroVec));
|
---|
139 |
|
---|
140 | // multiples of the second support vector
|
---|
141 | CPPUNIT_ASSERT(la1->isContained(unitVec[0]));
|
---|
142 | CPPUNIT_ASSERT(la2->isContained(unitVec[1]));
|
---|
143 | CPPUNIT_ASSERT(la3->isContained(unitVec[2]));
|
---|
144 |
|
---|
145 | CPPUNIT_ASSERT(la1->isContained(2*unitVec[0]));
|
---|
146 | CPPUNIT_ASSERT(la2->isContained(2*unitVec[1]));
|
---|
147 | CPPUNIT_ASSERT(la3->isContained(2*unitVec[2]));
|
---|
148 |
|
---|
149 | CPPUNIT_ASSERT(la1->isContained(3*unitVec[0]));
|
---|
150 | CPPUNIT_ASSERT(la2->isContained(3*unitVec[1]));
|
---|
151 | CPPUNIT_ASSERT(la3->isContained(3*unitVec[2]));
|
---|
152 |
|
---|
153 | // negative multiples
|
---|
154 | CPPUNIT_ASSERT(la1->isContained(-1*unitVec[0]));
|
---|
155 | CPPUNIT_ASSERT(la2->isContained(-1*unitVec[1]));
|
---|
156 | CPPUNIT_ASSERT(la3->isContained(-1*unitVec[2]));
|
---|
157 |
|
---|
158 | CPPUNIT_ASSERT(la1->isContained(-2*unitVec[0]));
|
---|
159 | CPPUNIT_ASSERT(la2->isContained(-2*unitVec[1]));
|
---|
160 | CPPUNIT_ASSERT(la3->isContained(-2*unitVec[2]));
|
---|
161 |
|
---|
162 | // points that should not be on the lines
|
---|
163 | CPPUNIT_ASSERT(!la1->isContained(unitVec[1]));
|
---|
164 | CPPUNIT_ASSERT(!la2->isContained(unitVec[2]));
|
---|
165 | CPPUNIT_ASSERT(!la3->isContained(unitVec[0]));
|
---|
166 |
|
---|
167 | CPPUNIT_ASSERT(!la1->isContained(2*unitVec[1]));
|
---|
168 | CPPUNIT_ASSERT(!la2->isContained(2*unitVec[2]));
|
---|
169 | CPPUNIT_ASSERT(!la3->isContained(2*unitVec[0]));
|
---|
170 |
|
---|
171 | CPPUNIT_ASSERT(!la1->isContained(-1*unitVec[1]));
|
---|
172 | CPPUNIT_ASSERT(!la2->isContained(-1*unitVec[2]));
|
---|
173 | CPPUNIT_ASSERT(!la3->isContained(-1*unitVec[0]));
|
---|
174 |
|
---|
175 | // For the plane lines
|
---|
176 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]));
|
---|
177 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]));
|
---|
178 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]));
|
---|
179 |
|
---|
180 | CPPUNIT_ASSERT(lp1->isContained(unitVec[1]));
|
---|
181 | CPPUNIT_ASSERT(lp2->isContained(unitVec[2]));
|
---|
182 | CPPUNIT_ASSERT(lp3->isContained(unitVec[0]));
|
---|
183 |
|
---|
184 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]+2*(unitVec[0]-unitVec[1])));
|
---|
185 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]+2*(unitVec[1]-unitVec[2])));
|
---|
186 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]+2*(unitVec[2]-unitVec[0])));
|
---|
187 |
|
---|
188 | CPPUNIT_ASSERT(lp1->isContained(unitVec[0]-2*(unitVec[0]-unitVec[1])));
|
---|
189 | CPPUNIT_ASSERT(lp2->isContained(unitVec[1]-2*(unitVec[1]-unitVec[2])));
|
---|
190 | CPPUNIT_ASSERT(lp3->isContained(unitVec[2]-2*(unitVec[2]-unitVec[0])));
|
---|
191 | }
|
---|
192 |
|
---|
193 | void LineUnittest::intersectionTest(){
|
---|
194 | Vector fixture;
|
---|
195 |
|
---|
196 | // intersection of the axis lines
|
---|
197 | fixture = la1->getIntersection(*la2);
|
---|
198 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
199 | fixture = la2->getIntersection(*la3);
|
---|
200 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
201 | fixture = la3->getIntersection(*la1);
|
---|
202 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
203 |
|
---|
204 | // axes and plane lines
|
---|
205 | fixture = la1->getIntersection(*lp1);
|
---|
206 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
207 | fixture = la2->getIntersection(*lp2);
|
---|
208 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
209 | fixture = la3->getIntersection(*lp3);
|
---|
210 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
211 |
|
---|
212 | fixture = la1->getIntersection(*lp3);
|
---|
213 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
214 | fixture = la2->getIntersection(*lp1);
|
---|
215 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
216 | fixture = la3->getIntersection(*lp2);
|
---|
217 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
218 |
|
---|
219 | // two plane lines
|
---|
220 | fixture = lp1->getIntersection(*lp2);
|
---|
221 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
222 | fixture = lp2->getIntersection(*lp3);
|
---|
223 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
224 | fixture = lp3->getIntersection(*lp1);
|
---|
225 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
226 |
|
---|
227 | // When we have two times the same line, we check if the point is on the line
|
---|
228 | fixture = la1->getIntersection(*la1);
|
---|
229 | CPPUNIT_ASSERT(la1->isContained(fixture));
|
---|
230 | fixture = la2->getIntersection(*la2);
|
---|
231 | CPPUNIT_ASSERT(la2->isContained(fixture));
|
---|
232 | fixture = la3->getIntersection(*la3);
|
---|
233 | CPPUNIT_ASSERT(la3->isContained(fixture));
|
---|
234 |
|
---|
235 | fixture = lp1->getIntersection(*lp1);
|
---|
236 | CPPUNIT_ASSERT(lp1->isContained(fixture));
|
---|
237 | fixture = lp2->getIntersection(*lp2);
|
---|
238 | CPPUNIT_ASSERT(lp2->isContained(fixture));
|
---|
239 | fixture = lp3->getIntersection(*lp3);
|
---|
240 | CPPUNIT_ASSERT(lp3->isContained(fixture));
|
---|
241 |
|
---|
242 | // lines that are askew should produce an Error
|
---|
243 | CPPUNIT_ASSERT_THROW(lp1->getIntersection(*la3),SkewException);
|
---|
244 | CPPUNIT_ASSERT_THROW(lp2->getIntersection(*la1),SkewException);
|
---|
245 | CPPUNIT_ASSERT_THROW(lp3->getIntersection(*la2),SkewException);
|
---|
246 |
|
---|
247 | CPPUNIT_ASSERT_THROW(la1->getIntersection(*lp2),SkewException);
|
---|
248 | CPPUNIT_ASSERT_THROW(la2->getIntersection(*lp3),SkewException);
|
---|
249 | CPPUNIT_ASSERT_THROW(la3->getIntersection(*lp1),SkewException);
|
---|
250 | }
|
---|
251 |
|
---|
252 | void LineUnittest::rotationTest(){
|
---|
253 | Vector fixture;
|
---|
254 |
|
---|
255 | // rotate zero Vector along the axes lines by various degrees
|
---|
256 | fixture = la1->rotateVector(zeroVec,1.);
|
---|
257 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
258 | fixture = la2->rotateVector(zeroVec,1.);
|
---|
259 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
260 | fixture = la3->rotateVector(zeroVec,1.);
|
---|
261 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
262 |
|
---|
263 | fixture = la1->rotateVector(zeroVec,2.);
|
---|
264 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
265 | fixture = la2->rotateVector(zeroVec,2.);
|
---|
266 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
267 | fixture = la3->rotateVector(zeroVec,2.);
|
---|
268 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
269 |
|
---|
270 | // rotate vectors on the axis around their lines
|
---|
271 | fixture = la1->rotateVector(unitVec[0],1.);
|
---|
272 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
273 | fixture = la2->rotateVector(unitVec[1],1.);
|
---|
274 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
275 | fixture = la3->rotateVector(unitVec[2],1.);
|
---|
276 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
277 |
|
---|
278 | fixture = la1->rotateVector(unitVec[0],2.);
|
---|
279 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
280 | fixture = la2->rotateVector(unitVec[1],2.);
|
---|
281 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
282 | fixture = la3->rotateVector(unitVec[2],2.);
|
---|
283 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
284 |
|
---|
285 | // more vectors on the axis
|
---|
286 | fixture = la1->rotateVector(2*unitVec[0],1.);
|
---|
287 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[0]);
|
---|
288 | fixture = la2->rotateVector(2*unitVec[1],1.);
|
---|
289 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[1]);
|
---|
290 | fixture = la3->rotateVector(2*unitVec[2],1.);
|
---|
291 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[2]);
|
---|
292 |
|
---|
293 | fixture = la1->rotateVector(2*unitVec[0],2.);
|
---|
294 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[0]);
|
---|
295 | fixture = la2->rotateVector(2*unitVec[1],2.);
|
---|
296 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[1]);
|
---|
297 | fixture = la3->rotateVector(2*unitVec[2],2.);
|
---|
298 | CPPUNIT_ASSERT_EQUAL(fixture,2*unitVec[2]);
|
---|
299 |
|
---|
300 | // negative factors
|
---|
301 | fixture = la1->rotateVector(-1*unitVec[0],1.);
|
---|
302 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
303 | fixture = la2->rotateVector(-1*unitVec[1],1.);
|
---|
304 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
305 | fixture = la3->rotateVector(-1*unitVec[2],1.);
|
---|
306 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
307 |
|
---|
308 | fixture = la1->rotateVector(-1*unitVec[0],2.);
|
---|
309 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
310 | fixture = la2->rotateVector(-1*unitVec[1],2.);
|
---|
311 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
312 | fixture = la3->rotateVector(-1*unitVec[2],2.);
|
---|
313 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
314 |
|
---|
315 |
|
---|
316 | // now the real rotations
|
---|
317 | // unitVec[1] around unitVec[0]
|
---|
318 | fixture = la1->rotateVector(unitVec[1],0);
|
---|
319 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
320 | fixture = la1->rotateVector(unitVec[1],1./2.*M_PI);
|
---|
321 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
322 | fixture = la1->rotateVector(unitVec[1],M_PI);
|
---|
323 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
324 | fixture = la1->rotateVector(unitVec[1],2*M_PI);
|
---|
325 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
326 |
|
---|
327 | // unitVec[2] around unitVec[1]
|
---|
328 | fixture = la2->rotateVector(unitVec[2],0);
|
---|
329 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
330 | fixture = la2->rotateVector(unitVec[2],1./2.*M_PI);
|
---|
331 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
332 | fixture = la2->rotateVector(unitVec[2],M_PI);
|
---|
333 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
334 | fixture = la2->rotateVector(unitVec[2],2*M_PI);
|
---|
335 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
336 |
|
---|
337 | // unitVec[0] around unitVec[2]
|
---|
338 | fixture = la3->rotateVector(unitVec[0],0);
|
---|
339 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
340 | fixture = la3->rotateVector(unitVec[0],1./2.*M_PI);
|
---|
341 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
342 | fixture = la3->rotateVector(unitVec[0],M_PI);
|
---|
343 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
344 | fixture = la3->rotateVector(unitVec[0],2*M_PI);
|
---|
345 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
346 |
|
---|
347 |
|
---|
348 | // and some rotation around the plane lines
|
---|
349 |
|
---|
350 | // Vectors on the line
|
---|
351 | fixture = lp1->rotateVector(unitVec[0],1.);
|
---|
352 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
353 | fixture = lp1->rotateVector(unitVec[1],1.);
|
---|
354 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
355 |
|
---|
356 | fixture = lp2->rotateVector(unitVec[1],1.);
|
---|
357 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
358 | fixture = lp2->rotateVector(unitVec[2],1.);
|
---|
359 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
360 |
|
---|
361 | fixture = lp3->rotateVector(unitVec[2],1.);
|
---|
362 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
363 | fixture = lp3->rotateVector(unitVec[0],1.);
|
---|
364 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
365 |
|
---|
366 | // the real stuff
|
---|
367 | fixture = lp1->rotateVector(zeroVec,M_PI);
|
---|
368 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,1,0));
|
---|
369 | fixture = lp2->rotateVector(zeroVec,M_PI);
|
---|
370 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(0,1,1));
|
---|
371 | fixture = lp3->rotateVector(zeroVec,M_PI);
|
---|
372 | CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,0,1));
|
---|
373 |
|
---|
374 | fixture = lp1->rotateVector(zeroVec,2*M_PI);
|
---|
375 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
376 | fixture = lp2->rotateVector(zeroVec,2*M_PI);
|
---|
377 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
378 | fixture = lp3->rotateVector(zeroVec,2*M_PI);
|
---|
379 | CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
|
---|
380 | }
|
---|
381 |
|
---|
382 | void LineUnittest::getRotationMatrixTest()
|
---|
383 | {
|
---|
384 | RealSpaceMatrix M;
|
---|
385 | Vector fixture;
|
---|
386 |
|
---|
387 | // check getRotationMatrix;
|
---|
388 | M = la1->getRotationMatrix(1.);
|
---|
389 | fixture = M * unitVec[0];
|
---|
390 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
391 | M = la2->getRotationMatrix(1.);
|
---|
392 | fixture = M * unitVec[1];
|
---|
393 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
394 | M = la3->getRotationMatrix(1.);
|
---|
395 | fixture = M * unitVec[2];
|
---|
396 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
397 |
|
---|
398 | // unitVec[1] around unitVec[0]
|
---|
399 | fixture = la1->rotateVector(unitVec[1],0);
|
---|
400 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
401 | fixture = la1->rotateVector(unitVec[1],1./2.*M_PI);
|
---|
402 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
403 | fixture = la1->rotateVector(unitVec[1],M_PI);
|
---|
404 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
405 | fixture = la1->rotateVector(unitVec[1],2*M_PI);
|
---|
406 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
|
---|
407 |
|
---|
408 | // unitVec[2] around unitVec[1]
|
---|
409 | fixture = la2->rotateVector(unitVec[2],0);
|
---|
410 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
411 | fixture = la2->rotateVector(unitVec[2],1./2.*M_PI);
|
---|
412 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
413 | fixture = la2->rotateVector(unitVec[2],M_PI);
|
---|
414 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
|
---|
415 | fixture = la2->rotateVector(unitVec[2],2*M_PI);
|
---|
416 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
|
---|
417 |
|
---|
418 | // unitVec[0] around unitVec[2]
|
---|
419 | fixture = la3->rotateVector(unitVec[0],0);
|
---|
420 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
421 | fixture = la3->rotateVector(unitVec[0],1./2.*M_PI);
|
---|
422 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
|
---|
423 | fixture = la3->rotateVector(unitVec[0],M_PI);
|
---|
424 | CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
|
---|
425 | fixture = la3->rotateVector(unitVec[0],2*M_PI);
|
---|
426 | CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
|
---|
427 | }
|
---|
428 |
|
---|
429 | void LineUnittest::sphereIntersectionTest(){
|
---|
430 | {
|
---|
431 | std::vector<Vector> res = la1->getSphereIntersections();
|
---|
432 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
433 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[0]));
|
---|
434 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[0]));
|
---|
435 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
436 | }
|
---|
437 |
|
---|
438 | {
|
---|
439 | std::vector<Vector> res = la2->getSphereIntersections();
|
---|
440 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
441 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[1]));
|
---|
442 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[1]));
|
---|
443 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
444 | }
|
---|
445 |
|
---|
446 | {
|
---|
447 | std::vector<Vector> res = la3->getSphereIntersections();
|
---|
448 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
449 | CPPUNIT_ASSERT(testDirection(res[0],unitVec[2]));
|
---|
450 | CPPUNIT_ASSERT(testDirection(res[1],unitVec[2]));
|
---|
451 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
452 | }
|
---|
453 |
|
---|
454 | {
|
---|
455 | std::vector<Vector> res = lp1->getSphereIntersections();
|
---|
456 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
457 | CPPUNIT_ASSERT((res[0]==unitVec[0]) || (res[0]==unitVec[1]));
|
---|
458 | CPPUNIT_ASSERT((res[1]==unitVec[0]) || (res[1]==unitVec[1]));
|
---|
459 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
460 | }
|
---|
461 |
|
---|
462 | {
|
---|
463 | std::vector<Vector> res = lp2->getSphereIntersections();
|
---|
464 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
465 | CPPUNIT_ASSERT((res[0]==unitVec[1]) || (res[0]==unitVec[2]));
|
---|
466 | CPPUNIT_ASSERT((res[1]==unitVec[1]) || (res[1]==unitVec[2]));
|
---|
467 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
468 | }
|
---|
469 |
|
---|
470 | {
|
---|
471 | std::vector<Vector> res = lp3->getSphereIntersections();
|
---|
472 | CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
|
---|
473 | CPPUNIT_ASSERT((res[0]==unitVec[2]) || (res[0]==unitVec[0]));
|
---|
474 | CPPUNIT_ASSERT((res[1]==unitVec[2]) || (res[1]==unitVec[0]));
|
---|
475 | CPPUNIT_ASSERT(res[0]!=res[1]);
|
---|
476 | }
|
---|
477 | }
|
---|