source: src/unittests/tesselation_boundarytriangleunittest.cpp@ b5c53d

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 b5c53d was 88b400, checked in by Frederik Heber <heber@…>, 14 years ago

converted #define's to enums, consts and typedefs [Meyers, "Effective C++", item 1].

basic changes:

  • #define bla 1.3 -> const double bla = 1.3
  • #define bla "test" -> const char * const bla = "test
  • use class specific constants! (HULLEPSILON)

const int Class::bla = 1.3; (in .cpp)
static const int bla; (in .hpp inside class private section)

  • "enum hack": #define bla 5 -> enum { bla = 5 };
    • if const int bla=5; impossible
    • e.g. necessary if constant is used in array declaration (int blabla[bla];)

details:

  • new file defs.cpp where const double reside in and are referenced by extern "C" const double
  • joiner.cpp: main() had to be changed due to concatenation of two #define possible, of two const char * not
  • class specific constants: HULLEPSILON, BONDTHRESHOLD, SPHERERADIUS
  • extended GetPathLengthonCircumCircle to additional parameter HULLEPSILON
  • Property mode set to 100644
File size: 7.1 KB
RevLine 
[e9c677]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>
[d74077]15#include <iostream>
[e9c677]16
17#include "defs.hpp"
[d74077]18#include "TesselPoint.hpp"
19#include "BoundaryPointSet.hpp"
20#include "BoundaryLineSet.hpp"
21#include "BoundaryTriangleSet.hpp"
22#include "CandidateForTesselation.hpp"
[e9c677]23#include "tesselation_boundarytriangleunittest.hpp"
24
[9b6b2f]25#ifdef HAVE_TESTRUNNER
26#include "UnitTestMain.hpp"
27#endif /*HAVE_TESTRUNNER*/
28
[88b400]29const double TesselationBoundaryTriangleTest::SPHERERADIUS=2.;
[e9c677]30
31/********************************************** Test classes **************************************/
32
33// Registers the fixture into the 'registry'
34CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest );
35
36
37void TesselationBoundaryTriangleTest::setUp()
38{
39 setVerbosity(5);
40
41 // create nodes
[5c8592]42 tesselpoints[0] = new TesselPoint;
[d74077]43 tesselpoints[0]->setPosition(Vector(0., 0., 0.));
[68f03d]44 tesselpoints[0]->setName("1");
[5c8592]45 tesselpoints[0]->nr = 1;
46 points[0] = new BoundaryPointSet(tesselpoints[0]);
47 tesselpoints[1] = new TesselPoint;
[d74077]48 tesselpoints[1]->setPosition(Vector(0., 1., 0.));
[68f03d]49 tesselpoints[1]->setName("2");
[5c8592]50 tesselpoints[1]->nr = 2;
51 points[1] = new BoundaryPointSet(tesselpoints[1]);
52 tesselpoints[2] = new TesselPoint;
[d74077]53 tesselpoints[2]->setPosition(Vector(1., 0., 0.));
[68f03d]54 tesselpoints[2]->setName("3");
55 tesselpoints[2]->nr = 3;
[5c8592]56 points[2] = new BoundaryPointSet(tesselpoints[2] );
[e9c677]57
58 // create line
59 lines[0] = new BoundaryLineSet(points[0], points[1], 0);
60 lines[1] = new BoundaryLineSet(points[1], points[2], 1);
61 lines[2] = new BoundaryLineSet(points[0], points[2], 2);
62
63 // create triangle
64 triangle = new BoundaryTriangleSet(lines, 0);
65 triangle->GetNormalVector(Vector(0.,0.,1.));
66};
67
68
69void TesselationBoundaryTriangleTest::tearDown()
70{
71 delete(triangle);
[5c8592]72 for (int i=0;i<3;++i) {
73 // TesselPoint does not delete its vector as it only got a reference
74 delete tesselpoints[i];
75 }
[e9c677]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
[1bd79e]88 Point = Vector(-1.,0.5,0.);
[d74077]89 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]90 Point = Vector(0.,0.5,0.);
[e9c677]91 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]92 Point = Vector(-4.,0.5,0.);
[d74077]93 CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]94 Point = Vector(0.,0.5,0.);
[e9c677]95 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
96
97 // simple test on x line
[1bd79e]98 Point = Vector(0.5,-1.,0.);
[d74077]99 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]100 Point = Vector(0.5,0.,0.);
[e9c677]101 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]102 Point = Vector(0.5,-6.,0.);
[d74077]103 CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]104 Point = Vector(0.5,0.,0.);
[e9c677]105 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
106
107 // simple test on slanted line
[1bd79e]108 Point = Vector(1.,1.,0.);
[d74077]109 CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]110 Point = Vector(0.5,0.5,0.);
[e9c677]111 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]112 Point = Vector(5.,5.,0.);
[d74077]113 CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]114 Point = Vector(0.5,0.5,0.);
[e9c677]115 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
116
117 // simple test on first node
[1bd79e]118 Point = Vector(-1.,-1.,0.);
[d74077]119 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]120 Point = Vector(0.,0.,0.);
[e9c677]121 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
122
123 // simple test on second node
[1bd79e]124 Point = Vector(0.,2.,0.);
[d74077]125 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]126 Point = Vector(0.,1.,0.);
[e9c677]127 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
128
129 // simple test on third node
[1bd79e]130 Point = Vector(2.,0.,0.);
[d74077]131 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]132 Point = Vector(1.,0.,0.);
[e9c677]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
[1bd79e]144 Point = Vector(1./3.,1./3.,+5.);
[d74077]145 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]146 Point = Vector(1./3.,1./3.,0.);
[e9c677]147 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]148 Point = Vector(1./3.,1./3.,-5.);
[d74077]149 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]150 Point = Vector(1./3.,1./3.,0.);
[e9c677]151 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
152
153 // simple test on y line
[1bd79e]154 Point = Vector(-1.,0.5,+2.);
[d74077]155 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]156 Point = Vector(0.,0.5,0.);
[e9c677]157 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]158 Point = Vector(-1.,0.5,-3.);
[d74077]159 CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]160 Point = Vector(0.,0.5,0.);
[e9c677]161 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
162
163 // simple test on x line
[1bd79e]164 Point = Vector(0.5,-1.,+1.);
[d74077]165 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]166 Point = Vector(0.5,0.,0.);
[e9c677]167 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]168 Point = Vector(0.5,-1.,-2.);
[d74077]169 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]170 Point = Vector(0.5,0.,0.);
[e9c677]171 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
172
173 // simple test on slanted line
[1bd79e]174 Point = Vector(1.,1.,+3.);
[d74077]175 CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]176 Point = Vector(0.5,0.5,0.);
[e9c677]177 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]178 Point = Vector(1.,1.,-4.);
[d74077]179 CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]180 Point = Vector(0.5,0.5,0.);
[e9c677]181 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
182
183 // simple test on first node
[1bd79e]184 Point = Vector(-1.,-1.,5.);
[d74077]185 CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]186 Point = Vector(0.,0.,0.);
[e9c677]187 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
188
189 // simple test on second node
[1bd79e]190 Point = Vector(0.,2.,5.);
[d74077]191 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]192 Point = Vector(0.,1.,0.);
[e9c677]193 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
194
195 // simple test on third node
[1bd79e]196 Point = Vector(2.,0.,5.);
[d74077]197 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]198 Point = Vector(1.,0.,0.);
[e9c677]199 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
200};
Note: See TracBrowser for help on using the repository browser.