source: LinearAlgebra/src/unittests/PlaneUnitTest.cpp@ 2ba2ed

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 2ba2ed was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 8.4 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[6d608d]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[94d5ac6]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/>.
[bcf653]21 */
22
[fa5a6a]23/*
24 * PlaneUnittest.cpp
25 *
26 * Created on: Apr 30, 2010
27 * Author: crueger
28 */
29
[bf3817]30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
[fa5a6a]35#include <cppunit/CompilerOutputter.h>
36#include <cppunit/extensions/TestFactoryRegistry.h>
37#include <cppunit/ui/text/TestRunner.h>
38
[3dcb1f]39#include <cmath>
[9b410d]40#include <limits>
[3dcb1f]41
[bf4b9f]42#include "defs.hpp"
43#include "Exceptions.hpp"
44#include "Line.hpp"
45#include "Vector.hpp"
[5bc8229]46
47#include "PlaneUnitTest.hpp"
48
[fa5a6a]49#ifdef HAVE_TESTRUNNER
50#include "UnitTestMain.hpp"
51#endif /*HAVE_TESTRUNNER*/
52
53CPPUNIT_TEST_SUITE_REGISTRATION( PlaneUnittest );
54
55void PlaneUnittest::setUp(){
[407782]56 p1 = new Plane(unitVec[0],unitVec[1],unitVec[2]);
57 p2 = new Plane(unitVec[0],unitVec[1],zeroVec);
58 p3 = new Plane(unitVec[0],zeroVec,unitVec[2]);
59 p4 = new Plane(zeroVec,unitVec[1],unitVec[2]);
[fa5a6a]60}
61
62void PlaneUnittest::tearDown(){
63 delete p1;
64 delete p2;
65 delete p3;
66 delete p4;
67}
68
69void PlaneUnittest::constructionErrorTest(){
70 // try several method of construction..
71 // see if error checking works
72
73 // three points
[407782]74 CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],unitVec[2]));
[fa5a6a]75 // when only two points are differnt this gives an error
[407782]76 CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[1],unitVec[1]),LinearDependenceException);
[fa5a6a]77 // same with only one point
[407782]78 CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],unitVec[0]),LinearDependenceException);
[fa5a6a]79
80 // use two vector giving two directions
[407782]81 CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],unitVec[1],0));
[fa5a6a]82 // and again this is actually only one vector
[407782]83 CPPUNIT_ASSERT_THROW(Plane(unitVec[0],unitVec[0],0),LinearDependenceException);
[fa5a6a]84 // Zero vector does not give a good direction
[407782]85 CPPUNIT_ASSERT_THROW(Plane(unitVec[0],zeroVec,0),ZeroVectorException);
[fa5a6a]86
87 // use a normalvector and an scalar offset
[407782]88 CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],0));
[fa5a6a]89 // The zero vector is no good as a normalvector
90 CPPUNIT_ASSERT_THROW(Plane(zeroVec,0),ZeroVectorException);
91
92 // use a normalvector and an offset vector
[407782]93 CPPUNIT_ASSERT_NO_THROW(Plane(unitVec[0],zeroVec));
[fa5a6a]94 // and the bad zeroVector again
95 CPPUNIT_ASSERT_THROW(Plane(zeroVec,zeroVec),ZeroVectorException);
96}
97
98
99// we need to test normals independent of the direction
100bool testNormal(const Vector &normal1, const Vector &normal2){
101 return (normal1==normal2) || (normal1==-1*normal2);
102}
103
104void PlaneUnittest::constructionResultTest(){
105 {
106 // construct with three points on plane
[407782]107 Plane p1(unitVec[0],unitVec[1],zeroVec);
108 CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
[fa5a6a]109 CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
110
[407782]111 Plane p2(unitVec[0],unitVec[2],zeroVec);
112 CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
[fa5a6a]113 CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
114
[407782]115 Plane p3(unitVec[1],unitVec[2],zeroVec);
116 CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
[fa5a6a]117 CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
118 }
119 {
120 // construct with two directions + offset
[407782]121 Plane p1(unitVec[0],unitVec[1],0);
122 CPPUNIT_ASSERT(testNormal(unitVec[2],p1.getNormal()));
[fa5a6a]123 CPPUNIT_ASSERT_EQUAL(0.,p1.getOffset());
124
[407782]125 Plane p2(unitVec[0],unitVec[2],0);
126 CPPUNIT_ASSERT(testNormal(unitVec[1],p2.getNormal()));
[fa5a6a]127 CPPUNIT_ASSERT_EQUAL(0.,p2.getOffset());
128
[407782]129 Plane p3(unitVec[1],unitVec[2],0);
130 CPPUNIT_ASSERT(testNormal(unitVec[0],p3.getNormal()));
[fa5a6a]131 CPPUNIT_ASSERT_EQUAL(0.,p3.getOffset());
132 }
133}
134
135void PlaneUnittest::pointsTest(){
136 std::vector<Vector> points1 = p1->getPointsOnPlane();
137 CPPUNIT_ASSERT(p1->isContained(points1[0]));
138 CPPUNIT_ASSERT(p1->isContained(points1[1]));
139 CPPUNIT_ASSERT(p1->isContained(points1[2]));
140 // check that the three points differ
141 CPPUNIT_ASSERT(points1[0]!=points1[1]);
142 CPPUNIT_ASSERT(points1[0]!=points1[2]);
143 CPPUNIT_ASSERT(points1[1]!=points1[2]);
144
145
146 std::vector<Vector> points2 = p2->getPointsOnPlane();
147 CPPUNIT_ASSERT(p2->isContained(points2[0]));
148 CPPUNIT_ASSERT(p2->isContained(points2[1]));
149 CPPUNIT_ASSERT(p2->isContained(points2[2]));
150 // check that the three points differ
151 CPPUNIT_ASSERT(points2[0]!=points2[1]);
152 CPPUNIT_ASSERT(points2[0]!=points2[2]);
153 CPPUNIT_ASSERT(points2[1]!=points2[2]);
154
155 std::vector<Vector> points3 = p3->getPointsOnPlane();
156 CPPUNIT_ASSERT(p3->isContained(points3[0]));
157 CPPUNIT_ASSERT(p3->isContained(points3[1]));
158 CPPUNIT_ASSERT(p3->isContained(points3[2]));
159 // check that the three points differ
160 CPPUNIT_ASSERT(points3[0]!=points3[1]);
161 CPPUNIT_ASSERT(points3[0]!=points3[2]);
162 CPPUNIT_ASSERT(points3[1]!=points3[2]);
163
164 std::vector<Vector> points4 = p4->getPointsOnPlane();
165 CPPUNIT_ASSERT(p4->isContained(points4[0]));
166 CPPUNIT_ASSERT(p4->isContained(points4[1]));
167 CPPUNIT_ASSERT(p4->isContained(points4[2]));
168 // check that the three points differ
169 CPPUNIT_ASSERT(points4[0]!=points4[1]);
170 CPPUNIT_ASSERT(points4[0]!=points4[2]);
171 CPPUNIT_ASSERT(points4[1]!=points4[2]);
172}
173
174
175void PlaneUnittest::operationsTest(){
176 {
[407782]177 Vector t = (1./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
[71129f]178 CPPUNIT_ASSERT(fabs(p1->distance(zeroVec)-t.Norm()) <= LINALG_MYEPSILON());
[fa5a6a]179 CPPUNIT_ASSERT_EQUAL(t,p1->getClosestPoint(zeroVec));
180 }
181
[71129f]182 CPPUNIT_ASSERT(fabs(p2->distance(unitVec[2])-1) <= LINALG_MYEPSILON());
[407782]183 CPPUNIT_ASSERT_EQUAL(zeroVec,p2->getClosestPoint(unitVec[2]));
[71129f]184 CPPUNIT_ASSERT(fabs(p3->distance(unitVec[1])-1) <= LINALG_MYEPSILON());
[407782]185 CPPUNIT_ASSERT_EQUAL(zeroVec,p3->getClosestPoint(unitVec[1]));
[71129f]186 CPPUNIT_ASSERT(fabs(p4->distance(unitVec[0])-1) <= LINALG_MYEPSILON());
[407782]187 CPPUNIT_ASSERT_EQUAL(zeroVec,p4->getClosestPoint(unitVec[0]));
[ccf826]188}
[fa5a6a]189
[ccf826]190void PlaneUnittest::mirrorTest(){
191 Vector fixture;
192
193 // some Vectors that lie on the planes
[407782]194 fixture = p1->mirrorVector(unitVec[0]);
195 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
196 fixture = p1->mirrorVector(unitVec[1]);
197 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
198 fixture = p1->mirrorVector(unitVec[2]);
199 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
[ccf826]200
201 fixture = p2->mirrorVector(zeroVec);
202 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
[407782]203 fixture = p2->mirrorVector(unitVec[0]);
204 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
205 fixture = p2->mirrorVector(unitVec[1]);
206 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
[ccf826]207
208 fixture = p3->mirrorVector(zeroVec);
209 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
[407782]210 fixture = p3->mirrorVector(unitVec[0]);
211 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]);
212 fixture = p3->mirrorVector(unitVec[2]);
213 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
[ccf826]214
215 fixture = p4->mirrorVector(zeroVec);
216 CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
[407782]217 fixture = p4->mirrorVector(unitVec[1]);
218 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]);
219 fixture = p4->mirrorVector(unitVec[2]);
220 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]);
[ccf826]221
222 // some Vectors outside of the planes
223 {
[407782]224 Vector t = (2./3.)*(unitVec[0]+unitVec[1]+unitVec[2]);
[ccf826]225 fixture = p1->mirrorVector(zeroVec);
226 CPPUNIT_ASSERT_EQUAL(fixture,t);
227 }
[fa5a6a]228
[407782]229 fixture = p2->mirrorVector(unitVec[2]);
230 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]);
231 fixture = p3->mirrorVector(unitVec[1]);
232 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]);
233 fixture = p4->mirrorVector(unitVec[0]);
234 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]);
[fa5a6a]235}
[27ac00]236
237void PlaneUnittest::LineIntersectionTest(){
238 Vector fixture;
239 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???
240 Line l1 = makeLineThrough(zeroVec,Vector(2,1,0));
[407782]241 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[0], zeroVec).GetIntersection(l1) );
[27ac00]242 CPPUNIT_ASSERT_EQUAL( zeroVec, fixture );
243
244 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ???
[407782]245 Line l2 = makeLineThrough(unitVec[0],Vector(0,1,1));
246 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unitVec[1], Vector(2,1,0)).GetIntersection(l2) );
[27ac00]247 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );
248}
Note: See TracBrowser for help on using the repository browser.