source: src/unittests/LineUnittest.cpp@ 3dcb1f

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 3dcb1f was 3dcb1f, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Added two functions to Box class to translate Vectors from Box-Space to normal space

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