source: src/unittests/tesselation_boundarytriangleunittest.cpp@ f761c4

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 f761c4 was 920c70, checked in by Frederik Heber <heber@…>, 15 years ago

Removed all Malloc/Calloc/ReAlloc (&Free) and replaced by new and delete/delete[].

Due to the new MemDebug framework there is no need (or even unnecessary/unwanted competition between it and) for the MemoryAllocator and ..UsageObserver anymore.
They can however still be used with c codes such as pcp and alikes.

In Molecuilder lots of glibc corruptions arose and the C-like syntax make it generally harder to get allocation and deallocation straight.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 6.9 KB
Line 
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>
15
16#include "defs.hpp"
17#include "tesselation.hpp"
18#include "tesselation_boundarytriangleunittest.hpp"
19
20#ifdef HAVE_TESTRUNNER
21#include "UnitTestMain.hpp"
22#endif /*HAVE_TESTRUNNER*/
23
24#define SPHERERADIUS 2.
25
26/********************************************** Test classes **************************************/
27
28// Registers the fixture into the 'registry'
29CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest );
30
31
32void TesselationBoundaryTriangleTest::setUp()
33{
34 setVerbosity(5);
35
36 // create nodes
37 tesselpoints[0] = new TesselPoint;
38 tesselpoints[0]->node = new Vector(0., 0., 0.);
39 tesselpoints[0]->setName("1");
40 tesselpoints[0]->nr = 1;
41 points[0] = new BoundaryPointSet(tesselpoints[0]);
42 tesselpoints[1] = new TesselPoint;
43 tesselpoints[1]->node = new Vector(0., 1., 0.);
44 tesselpoints[1]->setName("2");
45 tesselpoints[1]->nr = 2;
46 points[1] = new BoundaryPointSet(tesselpoints[1]);
47 tesselpoints[2] = new TesselPoint;
48 tesselpoints[2]->node = new Vector(1., 0., 0.);
49 tesselpoints[2]->setName("3");
50 tesselpoints[2]->nr = 3;
51 points[2] = new BoundaryPointSet(tesselpoints[2] );
52
53 // create line
54 lines[0] = new BoundaryLineSet(points[0], points[1], 0);
55 lines[1] = new BoundaryLineSet(points[1], points[2], 1);
56 lines[2] = new BoundaryLineSet(points[0], points[2], 2);
57
58 // create triangle
59 triangle = new BoundaryTriangleSet(lines, 0);
60 triangle->GetNormalVector(Vector(0.,0.,1.));
61};
62
63
64void TesselationBoundaryTriangleTest::tearDown()
65{
66 delete(triangle);
67 for (int i=0;i<3;++i) {
68 // TesselPoint does not delete its vector as it only got a reference
69 delete tesselpoints[i]->node;
70 delete tesselpoints[i];
71 }
72 logger::purgeInstance();
73 errorLogger::purgeInstance();
74};
75
76/** UnitTest for Tesselation::IsInnerPoint()
77 */
78void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest()
79{
80 Vector TestIntersection;
81 Vector Point;
82
83 // simple test on y line
84 Point = Vector(-1.,0.5,0.);
85 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
86 Point = Vector(0.,0.5,0.);
87 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
88 Point = Vector(-4.,0.5,0.);
89 CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
90 Point = Vector(0.,0.5,0.);
91 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
92
93 // simple test on x line
94 Point = Vector(0.5,-1.,0.);
95 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
96 Point = Vector(0.5,0.,0.);
97 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
98 Point = Vector(0.5,-6.,0.);
99 CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
100 Point = Vector(0.5,0.,0.);
101 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
102
103 // simple test on slanted line
104 Point = Vector(1.,1.,0.);
105 CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
106 Point = Vector(0.5,0.5,0.);
107 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
108 Point = Vector(5.,5.,0.);
109 CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
110 Point = Vector(0.5,0.5,0.);
111 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
112
113 // simple test on first node
114 Point = Vector(-1.,-1.,0.);
115 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
116 Point = Vector(0.,0.,0.);
117 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
118
119 // simple test on second node
120 Point = Vector(0.,2.,0.);
121 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
122 Point = Vector(0.,1.,0.);
123 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
124
125 // simple test on third node
126 Point = Vector(2.,0.,0.);
127 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
128 Point = Vector(1.,0.,0.);
129 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
130};
131
132/** UnitTest for Tesselation::IsInnerPoint()
133 */
134void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest()
135{
136 Vector TestIntersection;
137 Vector Point;
138
139 // straight down/up
140 Point = Vector(1./3.,1./3.,+5.);
141 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
142 Point = Vector(1./3.,1./3.,0.);
143 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
144 Point = Vector(1./3.,1./3.,-5.);
145 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
146 Point = Vector(1./3.,1./3.,0.);
147 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
148
149 // simple test on y line
150 Point = Vector(-1.,0.5,+2.);
151 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
152 Point = Vector(0.,0.5,0.);
153 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
154 Point = Vector(-1.,0.5,-3.);
155 CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
156 Point = Vector(0.,0.5,0.);
157 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
158
159 // simple test on x line
160 Point = Vector(0.5,-1.,+1.);
161 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
162 Point = Vector(0.5,0.,0.);
163 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
164 Point = Vector(0.5,-1.,-2.);
165 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
166 Point = Vector(0.5,0.,0.);
167 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
168
169 // simple test on slanted line
170 Point = Vector(1.,1.,+3.);
171 CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
172 Point = Vector(0.5,0.5,0.);
173 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
174 Point = Vector(1.,1.,-4.);
175 CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
176 Point = Vector(0.5,0.5,0.);
177 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
178
179 // simple test on first node
180 Point = Vector(-1.,-1.,5.);
181 CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
182 Point = Vector(0.,0.,0.);
183 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
184
185 // simple test on second node
186 Point = Vector(0.,2.,5.);
187 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
188 Point = Vector(0.,1.,0.);
189 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
190
191 // simple test on third node
192 Point = Vector(2.,0.,5.);
193 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
194 Point = Vector(1.,0.,0.);
195 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
196};
Note: See TracBrowser for help on using the repository browser.