source: src/unittests/LineUnittest.cpp@ 6e00dd

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 6e00dd was 42a101, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Removed RotateVector() function in favor of Line::rotateVector() method.

Line::rotateVector() is able to rotate any vector around any line in space.

  • Property mode set to 100644
File size: 11.0 KB
Line 
1/*
2 * LineUnittest.cpp
3 *
4 * Created on: May 27, 2010
5 * Author: crueger
6 */
7
8#include "LineUnittest.hpp"
9
10#include "vector.hpp"
11#include "Exceptions/LinearDependenceException.hpp"
12#include "Exceptions/SkewException.hpp"
13
14#include <cppunit/CompilerOutputter.h>
15#include <cppunit/extensions/TestFactoryRegistry.h>
16#include <cppunit/ui/text/TestRunner.h>
17
18#include <iostream>
19
20using namespace std;
21
22#ifdef HAVE_TESTRUNNER
23#include "UnitTestMain.hpp"
24#endif /*HAVE_TESTRUNNER*/
25
26CPPUNIT_TEST_SUITE_REGISTRATION( LineUnittest );
27
28void LineUnittest::setUp(){
29 // three lines along the axes
30 la1 = new Line(zeroVec,e1);
31 la2 = new Line(zeroVec,e2);
32 la3 = new Line(zeroVec,e3);
33
34 // the lines along the planes defined by two coordinate axes
35 lp1 = new Line(e1,e1-e2);
36 lp2 = new Line(e2,e2-e3);
37 lp3 = new Line(e3,e3-e1);
38}
39void LineUnittest::tearDown(){
40 delete la1;
41 delete la2;
42 delete la3;
43
44 delete lp1;
45 delete lp2;
46 delete lp3;
47}
48
49void LineUnittest::constructionErrorTest(){
50 // test some constructions
51
52 // direction+origin should never fail
53 CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e1));
54 CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e2));
55 CPPUNIT_ASSERT_NO_THROW(Line(zeroVec,e3));
56
57 // two points fails if both points are the same
58 CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e1,e2));
59 CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e2,e3));
60 CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e3,e1));
61 // for zerovectors
62 CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e1,zeroVec));
63 CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e2,zeroVec));
64 CPPUNIT_ASSERT_NO_THROW(makeLineThrough(e3,zeroVec));
65 // now we pass two times the same point
66 CPPUNIT_ASSERT_THROW(makeLineThrough(zeroVec,zeroVec),LinearDependenceException);
67 CPPUNIT_ASSERT_THROW(makeLineThrough(e1,e1),LinearDependenceException);
68 CPPUNIT_ASSERT_THROW(makeLineThrough(e2,e2),LinearDependenceException);
69 CPPUNIT_ASSERT_THROW(makeLineThrough(e3,e3),LinearDependenceException);
70
71}
72
73bool testDirection(const Vector &dir1,const Vector &dir2){
74 return (dir1==dir2) || (dir1==-1*dir2);
75}
76
77void LineUnittest::constructionResultTest(){
78 // test all directions
79 CPPUNIT_ASSERT(testDirection(la1->getDirection(),e1));
80 CPPUNIT_ASSERT(testDirection(la2->getDirection(),e2));
81 CPPUNIT_ASSERT(testDirection(la3->getDirection(),e3));
82
83 // test origins
84 CPPUNIT_ASSERT_EQUAL(la1->getOrigin(),zeroVec);
85 CPPUNIT_ASSERT_EQUAL(la2->getOrigin(),zeroVec);
86 CPPUNIT_ASSERT_EQUAL(la2->getOrigin(),zeroVec);
87
88 // test if desired points are on the lines
89 CPPUNIT_ASSERT(la1->isContained(zeroVec));
90 CPPUNIT_ASSERT(la2->isContained(zeroVec));
91 CPPUNIT_ASSERT(la3->isContained(zeroVec));
92
93 CPPUNIT_ASSERT(la1->isContained(e1));
94 CPPUNIT_ASSERT(la2->isContained(e2));
95 CPPUNIT_ASSERT(la3->isContained(e3));
96
97 CPPUNIT_ASSERT(lp1->isContained(e1));
98 CPPUNIT_ASSERT(lp2->isContained(e2));
99 CPPUNIT_ASSERT(lp3->isContained(e3));
100
101 CPPUNIT_ASSERT(lp1->isContained(e2));
102 CPPUNIT_ASSERT(lp2->isContained(e3));
103 CPPUNIT_ASSERT(lp3->isContained(e1));
104}
105
106void LineUnittest::isContainedTest(){
107 // Zerovector on the axes lines
108 CPPUNIT_ASSERT(la1->isContained(zeroVec));
109 CPPUNIT_ASSERT(la2->isContained(zeroVec));
110 CPPUNIT_ASSERT(la3->isContained(zeroVec));
111
112 // multiples of the second support vector
113 CPPUNIT_ASSERT(la1->isContained(e1));
114 CPPUNIT_ASSERT(la2->isContained(e2));
115 CPPUNIT_ASSERT(la3->isContained(e3));
116
117 CPPUNIT_ASSERT(la1->isContained(2*e1));
118 CPPUNIT_ASSERT(la2->isContained(2*e2));
119 CPPUNIT_ASSERT(la3->isContained(2*e3));
120
121 CPPUNIT_ASSERT(la1->isContained(3*e1));
122 CPPUNIT_ASSERT(la2->isContained(3*e2));
123 CPPUNIT_ASSERT(la3->isContained(3*e3));
124
125 // negative multiples
126 CPPUNIT_ASSERT(la1->isContained(-1*e1));
127 CPPUNIT_ASSERT(la2->isContained(-1*e2));
128 CPPUNIT_ASSERT(la3->isContained(-1*e3));
129
130 CPPUNIT_ASSERT(la1->isContained(-2*e1));
131 CPPUNIT_ASSERT(la2->isContained(-2*e2));
132 CPPUNIT_ASSERT(la3->isContained(-2*e3));
133
134 // points that should not be on the lines
135 CPPUNIT_ASSERT(!la1->isContained(e2));
136 CPPUNIT_ASSERT(!la2->isContained(e3));
137 CPPUNIT_ASSERT(!la3->isContained(e1));
138
139 CPPUNIT_ASSERT(!la1->isContained(2*e2));
140 CPPUNIT_ASSERT(!la2->isContained(2*e3));
141 CPPUNIT_ASSERT(!la3->isContained(2*e1));
142
143 CPPUNIT_ASSERT(!la1->isContained(-1*e2));
144 CPPUNIT_ASSERT(!la2->isContained(-1*e3));
145 CPPUNIT_ASSERT(!la3->isContained(-1*e1));
146
147 // For the plane lines
148 CPPUNIT_ASSERT(lp1->isContained(e1));
149 CPPUNIT_ASSERT(lp2->isContained(e2));
150 CPPUNIT_ASSERT(lp3->isContained(e3));
151
152 CPPUNIT_ASSERT(lp1->isContained(e2));
153 CPPUNIT_ASSERT(lp2->isContained(e3));
154 CPPUNIT_ASSERT(lp3->isContained(e1));
155
156 CPPUNIT_ASSERT(lp1->isContained(e1+2*(e1-e2)));
157 CPPUNIT_ASSERT(lp2->isContained(e2+2*(e2-e3)));
158 CPPUNIT_ASSERT(lp3->isContained(e3+2*(e3-e1)));
159
160 CPPUNIT_ASSERT(lp1->isContained(e1-2*(e1-e2)));
161 CPPUNIT_ASSERT(lp2->isContained(e2-2*(e2-e3)));
162 CPPUNIT_ASSERT(lp3->isContained(e3-2*(e3-e1)));
163}
164
165void LineUnittest::intersectionTest(){
166 Vector fixture;
167
168 // intersection of the axis lines
169 fixture = la1->getIntersection(*la2);
170 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
171 fixture = la2->getIntersection(*la3);
172 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
173 fixture = la3->getIntersection(*la1);
174 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
175
176 // axes and plane lines
177 fixture = la1->getIntersection(*lp1);
178 CPPUNIT_ASSERT_EQUAL(fixture,e1);
179 fixture = la2->getIntersection(*lp2);
180 CPPUNIT_ASSERT_EQUAL(fixture,e2);
181 fixture = la3->getIntersection(*lp3);
182 CPPUNIT_ASSERT_EQUAL(fixture,e3);
183
184 fixture = la1->getIntersection(*lp3);
185 CPPUNIT_ASSERT_EQUAL(fixture,e1);
186 fixture = la2->getIntersection(*lp1);
187 CPPUNIT_ASSERT_EQUAL(fixture,e2);
188 fixture = la3->getIntersection(*lp2);
189 CPPUNIT_ASSERT_EQUAL(fixture,e3);
190
191 // two plane lines
192 fixture = lp1->getIntersection(*lp2);
193 CPPUNIT_ASSERT_EQUAL(fixture,e2);
194 fixture = lp2->getIntersection(*lp3);
195 CPPUNIT_ASSERT_EQUAL(fixture,e3);
196 fixture = lp3->getIntersection(*lp1);
197 CPPUNIT_ASSERT_EQUAL(fixture,e1);
198
199 // When we have two times the same line, we check if the point is on the line
200 fixture = la1->getIntersection(*la1);
201 CPPUNIT_ASSERT(la1->isContained(fixture));
202 fixture = la2->getIntersection(*la2);
203 CPPUNIT_ASSERT(la2->isContained(fixture));
204 fixture = la3->getIntersection(*la3);
205 CPPUNIT_ASSERT(la3->isContained(fixture));
206
207 fixture = lp1->getIntersection(*lp1);
208 CPPUNIT_ASSERT(lp1->isContained(fixture));
209 fixture = lp2->getIntersection(*lp2);
210 CPPUNIT_ASSERT(lp2->isContained(fixture));
211 fixture = lp3->getIntersection(*lp3);
212 CPPUNIT_ASSERT(lp3->isContained(fixture));
213
214 // lines that are askew should produce an Error
215 CPPUNIT_ASSERT_THROW(lp1->getIntersection(*la3),SkewException);
216 CPPUNIT_ASSERT_THROW(lp2->getIntersection(*la1),SkewException);
217 CPPUNIT_ASSERT_THROW(lp3->getIntersection(*la2),SkewException);
218
219 CPPUNIT_ASSERT_THROW(la1->getIntersection(*lp2),SkewException);
220 CPPUNIT_ASSERT_THROW(la2->getIntersection(*lp3),SkewException);
221 CPPUNIT_ASSERT_THROW(la3->getIntersection(*lp1),SkewException);
222}
223
224void LineUnittest::rotationTest(){
225 Vector fixture;
226
227 // rotate zero Vector along the axes lines by various degrees
228 fixture = la1->rotateVector(zeroVec,1.);
229 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
230 fixture = la2->rotateVector(zeroVec,1.);
231 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
232 fixture = la3->rotateVector(zeroVec,1.);
233 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
234
235 fixture = la1->rotateVector(zeroVec,2.);
236 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
237 fixture = la2->rotateVector(zeroVec,2.);
238 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
239 fixture = la3->rotateVector(zeroVec,2.);
240 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
241
242 // rotate vectors on the axis around their lines
243 fixture = la1->rotateVector(e1,1.);
244 CPPUNIT_ASSERT_EQUAL(fixture,e1);
245 fixture = la2->rotateVector(e2,1.);
246 CPPUNIT_ASSERT_EQUAL(fixture,e2);
247 fixture = la3->rotateVector(e3,1.);
248 CPPUNIT_ASSERT_EQUAL(fixture,e3);
249
250 fixture = la1->rotateVector(e1,2.);
251 CPPUNIT_ASSERT_EQUAL(fixture,e1);
252 fixture = la2->rotateVector(e2,2.);
253 CPPUNIT_ASSERT_EQUAL(fixture,e2);
254 fixture = la3->rotateVector(e3,2.);
255 CPPUNIT_ASSERT_EQUAL(fixture,e3);
256
257 // more vectors on the axis
258 fixture = la1->rotateVector(2*e1,1.);
259 CPPUNIT_ASSERT_EQUAL(fixture,2*e1);
260 fixture = la2->rotateVector(2*e2,1.);
261 CPPUNIT_ASSERT_EQUAL(fixture,2*e2);
262 fixture = la3->rotateVector(2*e3,1.);
263 CPPUNIT_ASSERT_EQUAL(fixture,2*e3);
264
265 fixture = la1->rotateVector(2*e1,2.);
266 CPPUNIT_ASSERT_EQUAL(fixture,2*e1);
267 fixture = la2->rotateVector(2*e2,2.);
268 CPPUNIT_ASSERT_EQUAL(fixture,2*e2);
269 fixture = la3->rotateVector(2*e3,2.);
270 CPPUNIT_ASSERT_EQUAL(fixture,2*e3);
271
272 // negative factors
273 fixture = la1->rotateVector(-1*e1,1.);
274 CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
275 fixture = la2->rotateVector(-1*e2,1.);
276 CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
277 fixture = la3->rotateVector(-1*e3,1.);
278 CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
279
280 fixture = la1->rotateVector(-1*e1,2.);
281 CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
282 fixture = la2->rotateVector(-1*e2,2.);
283 CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
284 fixture = la3->rotateVector(-1*e3,2.);
285 CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
286
287
288
289 // now the real rotations
290 // e2 around e1
291 fixture = la1->rotateVector(e2,0);
292 CPPUNIT_ASSERT_EQUAL(fixture,e2);
293 fixture = la1->rotateVector(e2,1./2.*M_PI);
294 CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
295 fixture = la1->rotateVector(e2,M_PI);
296 CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
297 fixture = la1->rotateVector(e2,2*M_PI);
298 CPPUNIT_ASSERT_EQUAL(fixture,e2);
299
300 // e3 around e2
301 fixture = la2->rotateVector(e3,0);
302 CPPUNIT_ASSERT_EQUAL(fixture,e3);
303 fixture = la2->rotateVector(e3,1./2.*M_PI);
304 CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
305 fixture = la2->rotateVector(e3,M_PI);
306 CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
307 fixture = la2->rotateVector(e3,2*M_PI);
308 CPPUNIT_ASSERT_EQUAL(fixture,e3);
309
310 // e1 around e3
311 fixture = la3->rotateVector(e1,0);
312 CPPUNIT_ASSERT_EQUAL(fixture,e1);
313 fixture = la3->rotateVector(e1,1./2.*M_PI);
314 CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
315 fixture = la3->rotateVector(e1,M_PI);
316 CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
317 fixture = la3->rotateVector(e1,2*M_PI);
318 CPPUNIT_ASSERT_EQUAL(fixture,e1);
319
320
321 // and some rotation around the plane lines
322
323 // Vectors on the line
324 fixture = lp1->rotateVector(e1,1.);
325 CPPUNIT_ASSERT_EQUAL(fixture,e1);
326 fixture = lp1->rotateVector(e2,1.);
327 CPPUNIT_ASSERT_EQUAL(fixture,e2);
328
329 fixture = lp2->rotateVector(e2,1.);
330 CPPUNIT_ASSERT_EQUAL(fixture,e2);
331 fixture = lp2->rotateVector(e3,1.);
332 CPPUNIT_ASSERT_EQUAL(fixture,e3);
333
334 fixture = lp3->rotateVector(e3,1.);
335 CPPUNIT_ASSERT_EQUAL(fixture,e3);
336 fixture = lp3->rotateVector(e1,1.);
337 CPPUNIT_ASSERT_EQUAL(fixture,e1);
338
339 // the real stuff
340 fixture = lp1->rotateVector(zeroVec,M_PI);
341 CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,1,0));
342 fixture = lp2->rotateVector(zeroVec,M_PI);
343 CPPUNIT_ASSERT_EQUAL(fixture,Vector(0,1,1));
344 fixture = lp3->rotateVector(zeroVec,M_PI);
345 CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,0,1));
346
347 fixture = lp1->rotateVector(zeroVec,2*M_PI);
348 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
349 fixture = lp2->rotateVector(zeroVec,2*M_PI);
350 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
351 fixture = lp3->rotateVector(zeroVec,2*M_PI);
352 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
353}
Note: See TracBrowser for help on using the repository browser.