source: src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp@ 158ecb

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 158ecb was 158ecb, checked in by Frederik Heber <heber@…>, 9 years ago

Extended SphericalPointDistributionUnitTest to two and three matching points for all functions.

  • marked test as XFAIL for the moment.
  • Property mode set to 100644
File size: 35.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2014 Frederik Heber. All rights reserved.
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/>.
21 */
22
23/*
24 * SphericalPointDistributionUnitTest.cpp
25 *
26 * Created on: May 29, 2014
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41// include headers that implement a archive in simple text format
42#include <boost/archive/text_oarchive.hpp>
43#include <boost/archive/text_iarchive.hpp>
44
45#include "SphericalPointDistributionUnitTest.hpp"
46
47#include <boost/assign.hpp>
48#include <boost/math/quaternion.hpp>
49
50#include "CodePatterns/Assert.hpp"
51#include "CodePatterns/Log.hpp"
52
53#include "LinearAlgebra/Line.hpp"
54
55#include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
56
57#include "LinearAlgebra/Line.hpp"
58
59#ifdef HAVE_TESTRUNNER
60#include "UnitTestMain.hpp"
61#endif /*HAVE_TESTRUNNER*/
62
63using namespace boost::assign;
64
65/********************************************** Test classes **************************************/
66
67// Registers the fixture into the 'registry'
68CPPUNIT_TEST_SUITE_REGISTRATION( SphericalPointDistributionTest );
69
70
71void SphericalPointDistributionTest::setUp()
72{
73 // failing asserts should be thrown
74 ASSERT_DO(Assert::Throw);
75
76 setVerbosity(6);
77}
78
79
80void SphericalPointDistributionTest::tearDown()
81{
82}
83
84
85/** UnitTest for matchSphericalPointDistributions() with two points
86 */
87void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_2()
88{
89 SphericalPointDistribution SPD(1.);
90 // test with one point, matching trivially
91 {
92 SphericalPointDistribution::Polygon_t polygon;
93 polygon += Vector(1.,0.,0.);
94 SphericalPointDistribution::Polygon_t newpolygon =
95 SPD.get<2>();
96 SphericalPointDistribution::Polygon_t expected;
97 expected += Vector(-1.,0.,0.);
98 SphericalPointDistribution::Polygon_t remaining =
99 SphericalPointDistribution::matchSphericalPointDistributions(
100 polygon,
101 newpolygon);
102 CPPUNIT_ASSERT_EQUAL( expected, remaining );
103 }
104
105 // test with one point, just a flip of axis
106 {
107 SphericalPointDistribution::Polygon_t polygon;
108 polygon += Vector(0.,1.,0.);
109 SphericalPointDistribution::Polygon_t newpolygon =
110 SPD.get<2>();
111 SphericalPointDistribution::Polygon_t expected;
112 expected += Vector(0.,-1.,0.);
113 SphericalPointDistribution::Polygon_t remaining =
114 SphericalPointDistribution::matchSphericalPointDistributions(
115 polygon,
116 newpolygon);
117 CPPUNIT_ASSERT_EQUAL( expected, remaining );
118 }
119
120 // test with one point, just a flip to another axis
121 {
122 SphericalPointDistribution::Polygon_t polygon;
123 polygon += Vector(0.,0.,-1.);
124 SphericalPointDistribution::Polygon_t newpolygon =
125 SPD.get<2>();
126 SphericalPointDistribution::Polygon_t expected;
127 expected += Vector(0.,0.,1.);
128 SphericalPointDistribution::Polygon_t remaining =
129 SphericalPointDistribution::matchSphericalPointDistributions(
130 polygon,
131 newpolygon);
132 CPPUNIT_ASSERT_EQUAL( expected, remaining );
133 }
134
135 // test with one point, full rotation
136 {
137 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
138 SphericalPointDistribution::Polygon_t polygon;
139 polygon += RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI);
140 SphericalPointDistribution::Polygon_t newpolygon =
141 SPD.get<2>();
142 SphericalPointDistribution::Polygon_t expected;
143 expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
144 SphericalPointDistribution::Polygon_t remaining =
145 SphericalPointDistribution::matchSphericalPointDistributions(
146 polygon,
147 newpolygon);
148 CPPUNIT_ASSERT_EQUAL( expected, remaining );
149 }
150}
151
152/** UnitTest for matchSphericalPointDistributions() with three points
153 */
154void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_3()
155{
156 SphericalPointDistribution SPD(1.);
157
158 // test with one point, matching trivially
159 {
160 SphericalPointDistribution::Polygon_t polygon;
161 polygon += Vector(1.,0.,0.);
162 SphericalPointDistribution::Polygon_t newpolygon =
163 SPD.get<3>();
164 SphericalPointDistribution::Polygon_t expected = newpolygon;
165 expected.pop_front(); // remove first point
166 SphericalPointDistribution::Polygon_t remaining =
167 SphericalPointDistribution::matchSphericalPointDistributions(
168 polygon,
169 newpolygon);
170 CPPUNIT_ASSERT_EQUAL( expected, remaining );
171 }
172
173 // test with one point, just a flip of x and y axis
174 {
175 SphericalPointDistribution::Polygon_t polygon;
176 polygon += Vector(0.,1.,0.);
177 SphericalPointDistribution::Polygon_t newpolygon =
178 SPD.get<3>();
179 SphericalPointDistribution::Polygon_t expected = newpolygon;
180 expected.pop_front(); // remove first point
181 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
182 iter != expected.end(); ++iter) {
183 std::swap((*iter)[0], (*iter)[1]);
184 (*iter)[0] *= -1.;
185 }
186 SphericalPointDistribution::Polygon_t remaining =
187 SphericalPointDistribution::matchSphericalPointDistributions(
188 polygon,
189 newpolygon);
190 CPPUNIT_ASSERT_EQUAL( expected, remaining );
191 }
192
193 // test with two points, matching trivially
194 {
195 SphericalPointDistribution::Polygon_t polygon;
196 polygon += Vector(1.,0.,0.), Vector(-0.5, sqrt(3)*0.5,0.);
197 SphericalPointDistribution::Polygon_t newpolygon =
198 SPD.get<3>();
199 SphericalPointDistribution::Polygon_t expected = newpolygon;
200 expected.pop_front(); // remove first point
201 expected.pop_front(); // remove second point
202 SphericalPointDistribution::Polygon_t remaining =
203 SphericalPointDistribution::matchSphericalPointDistributions(
204 polygon,
205 newpolygon);
206 CPPUNIT_ASSERT_EQUAL( expected, remaining );
207 }
208
209 // test with two points, full rotation
210 {
211 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
212 SphericalPointDistribution::Polygon_t polygon;
213 polygon +=
214 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
215 RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI);
216 SphericalPointDistribution::Polygon_t newpolygon =
217 SPD.get<3>();
218 SphericalPointDistribution::Polygon_t expected = newpolygon;
219 expected.pop_front(); // remove first point
220 expected.pop_front(); // remove second point
221 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
222 iter != expected.end(); ++iter)
223 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
224 SphericalPointDistribution::Polygon_t remaining =
225 SphericalPointDistribution::matchSphericalPointDistributions(
226 polygon,
227 newpolygon);
228 CPPUNIT_ASSERT_EQUAL( expected, remaining );
229 }
230
231 // test with three points, matching trivially
232 {
233 SphericalPointDistribution::Polygon_t polygon;
234 polygon += Vector(1.,0.,0.), Vector(-0.5, sqrt(3)*0.5,0.), Vector(-0.5, -sqrt(3)*0.5,0.);
235 SphericalPointDistribution::Polygon_t newpolygon =
236 SPD.get<3>();
237 SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
238 SphericalPointDistribution::Polygon_t remaining =
239 SphericalPointDistribution::matchSphericalPointDistributions(
240 polygon,
241 newpolygon);
242 CPPUNIT_ASSERT_EQUAL( expected, remaining );
243 }
244
245
246 // test with three points, full rotation
247 {
248 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
249 SphericalPointDistribution::Polygon_t polygon;
250 polygon +=
251 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
252 RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI),
253 RotationAxis.rotateVector(Vector(-0.5, -sqrt(3)*0.5,0.), 47.6/180*M_PI);
254 SphericalPointDistribution::Polygon_t newpolygon =
255 SPD.get<3>();
256 SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
257 SphericalPointDistribution::Polygon_t remaining =
258 SphericalPointDistribution::matchSphericalPointDistributions(
259 polygon,
260 newpolygon);
261 CPPUNIT_ASSERT_EQUAL( expected, remaining );
262 }
263}
264
265/** UnitTest for matchSphericalPointDistributions() with four points
266 */
267void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_4()
268{
269 SphericalPointDistribution SPD(1.);
270
271 // test with one point, matching trivially
272 {
273 SphericalPointDistribution::Polygon_t polygon;
274 polygon += Vector(1.,0.,0.);
275 SphericalPointDistribution::Polygon_t newpolygon =
276 SPD.get<4>();
277 SphericalPointDistribution::Polygon_t expected = newpolygon;
278 expected.pop_front(); // remove first point
279 SphericalPointDistribution::Polygon_t remaining =
280 SphericalPointDistribution::matchSphericalPointDistributions(
281 polygon,
282 newpolygon);
283 CPPUNIT_ASSERT_EQUAL( expected, remaining );
284 }
285
286 // test with one point, just a flip of axis
287 {
288 SphericalPointDistribution::Polygon_t polygon;
289 polygon += Vector(0.,1.,0.);
290 SphericalPointDistribution::Polygon_t newpolygon =
291 SPD.get<4>();
292 SphericalPointDistribution::Polygon_t expected = newpolygon;
293 expected.pop_front(); // remove first point
294 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
295 iter != expected.end(); ++iter) {
296 std::swap((*iter)[0], (*iter)[1]);
297 (*iter)[0] *= -1.;
298 }
299 SphericalPointDistribution::Polygon_t remaining =
300 SphericalPointDistribution::matchSphericalPointDistributions(
301 polygon,
302 newpolygon);
303 CPPUNIT_ASSERT_EQUAL( expected, remaining );
304 }
305
306 // test with two points, matching trivially
307 {
308 SphericalPointDistribution::Polygon_t polygon;
309 polygon += Vector(1.,0.,0.), Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.);
310 SphericalPointDistribution::Polygon_t newpolygon =
311 SPD.get<4>();
312 SphericalPointDistribution::Polygon_t expected = newpolygon;
313 expected.pop_front(); // remove first point
314 expected.pop_front(); // remove second point
315 SphericalPointDistribution::Polygon_t remaining =
316 SphericalPointDistribution::matchSphericalPointDistributions(
317 polygon,
318 newpolygon);
319 CPPUNIT_ASSERT_EQUAL( expected, remaining );
320 }
321
322 // test with two points, full rotation
323 {
324 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
325 SphericalPointDistribution::Polygon_t polygon;
326 polygon +=
327 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
328 RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI);
329 SphericalPointDistribution::Polygon_t newpolygon =
330 SPD.get<4>();
331 SphericalPointDistribution::Polygon_t expected = newpolygon;
332 expected.pop_front(); // remove first point
333 expected.pop_front(); // remove second point
334 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
335 iter != expected.end(); ++iter)
336 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
337 SphericalPointDistribution::Polygon_t remaining =
338 SphericalPointDistribution::matchSphericalPointDistributions(
339 polygon,
340 newpolygon);
341 CPPUNIT_ASSERT_EQUAL( expected, remaining );
342 }
343
344 // test with three points, matching trivially
345 {
346 SphericalPointDistribution::Polygon_t polygon;
347 polygon +=
348 Vector(1.,0.,0.),
349 Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.),
350 Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3));
351 SphericalPointDistribution::Polygon_t newpolygon =
352 SPD.get<4>();
353 SphericalPointDistribution::Polygon_t expected = newpolygon;
354 expected.pop_front(); // remove first point
355 expected.pop_front(); // remove second point
356 expected.pop_front(); // remove third point
357 SphericalPointDistribution::Polygon_t remaining =
358 SphericalPointDistribution::matchSphericalPointDistributions(
359 polygon,
360 newpolygon);
361 CPPUNIT_ASSERT_EQUAL( expected, remaining );
362 }
363
364 // test with three points, full rotation
365 {
366 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
367 SphericalPointDistribution::Polygon_t polygon;
368 polygon +=
369 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
370 RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI),
371 RotationAxis.rotateVector(Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 47.6/180*M_PI);
372 SphericalPointDistribution::Polygon_t newpolygon =
373 SPD.get<4>();
374 SphericalPointDistribution::Polygon_t expected = newpolygon;
375 expected.pop_front(); // remove first point
376 expected.pop_front(); // remove second point
377 expected.pop_front(); // remove third point
378 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
379 iter != expected.end(); ++iter)
380 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
381 SphericalPointDistribution::Polygon_t remaining =
382 SphericalPointDistribution::matchSphericalPointDistributions(
383 polygon,
384 newpolygon);
385 CPPUNIT_ASSERT_EQUAL( expected, remaining );
386 }
387}
388
389/** UnitTest for matchSphericalPointDistributions() with five points
390 */
391void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_5()
392{
393 SphericalPointDistribution SPD(1.);
394
395 // test with one point, matching trivially
396 {
397 SphericalPointDistribution::Polygon_t polygon;
398 polygon += Vector(1.,0.,0.);
399 SphericalPointDistribution::Polygon_t newpolygon =
400 SPD.get<5>();
401 SphericalPointDistribution::Polygon_t expected = newpolygon;
402 expected.pop_front(); // remove first point
403 SphericalPointDistribution::Polygon_t remaining =
404 SphericalPointDistribution::matchSphericalPointDistributions(
405 polygon,
406 newpolygon);
407 CPPUNIT_ASSERT_EQUAL( expected, remaining );
408 }
409
410 // test with one point, just a flip of axis
411 {
412 SphericalPointDistribution::Polygon_t polygon;
413 polygon += Vector(0.,1.,0.);
414 SphericalPointDistribution::Polygon_t newpolygon =
415 SPD.get<5>();
416 SphericalPointDistribution::Polygon_t expected = newpolygon;
417 expected.pop_front(); // remove first point
418 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
419 iter != expected.end(); ++iter) {
420 std::swap((*iter)[0], (*iter)[1]);
421 (*iter)[0] *= -1.;
422 }
423 SphericalPointDistribution::Polygon_t remaining =
424 SphericalPointDistribution::matchSphericalPointDistributions(
425 polygon,
426 newpolygon);
427 CPPUNIT_ASSERT_EQUAL( expected, remaining );
428 }
429
430 // test with two points, matching trivially
431 {
432 SphericalPointDistribution::Polygon_t polygon;
433 polygon += Vector(1.,0.,0.), Vector(-1.,0.,0.);
434 SphericalPointDistribution::Polygon_t newpolygon =
435 SPD.get<5>();
436 SphericalPointDistribution::Polygon_t expected = newpolygon;
437 expected.pop_front(); // remove first point
438 expected.pop_front(); // remove second point
439 SphericalPointDistribution::Polygon_t remaining =
440 SphericalPointDistribution::matchSphericalPointDistributions(
441 polygon,
442 newpolygon);
443 CPPUNIT_ASSERT_EQUAL( expected, remaining );
444 }
445
446 // test with two points, full rotation
447 {
448 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
449 SphericalPointDistribution::Polygon_t polygon;
450 polygon +=
451 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180.*M_PI),
452 RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180.*M_PI);
453 SphericalPointDistribution::Polygon_t newpolygon =
454 SPD.get<5>();
455 SphericalPointDistribution::Polygon_t expected = newpolygon;
456 expected.pop_front(); // remove first point
457 expected.pop_front(); // remove second point
458 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
459 iter != expected.end(); ++iter)
460 *iter = RotationAxis.rotateVector(*iter, 47.6/180.*M_PI);
461 SphericalPointDistribution::Polygon_t remaining =
462 SphericalPointDistribution::matchSphericalPointDistributions(
463 polygon,
464 newpolygon);
465 // the three remaining points sit on a plane that may be rotated arbitrarily
466 // so we cannot simply check for equality between expected and remaining
467 // hence, we just check that they are orthogonal to the first two points
468 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
469 for (SphericalPointDistribution::Polygon_t::const_iterator fixiter = polygon.begin();
470 fixiter != polygon.end(); ++fixiter) {
471 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
472 iter != remaining.end(); ++iter) {
473 CPPUNIT_ASSERT( (*fixiter).IsNormalTo(*iter) );
474 }
475 }
476 }
477
478 // test with three points, matching trivially
479 {
480 SphericalPointDistribution::Polygon_t polygon;
481 polygon +=
482 Vector(1.,0.,0.),
483 Vector(-1., 0.0, 0.0),
484 Vector(0.0, 1., 0.0);
485 SphericalPointDistribution::Polygon_t newpolygon =
486 SPD.get<5>();
487 SphericalPointDistribution::Polygon_t expected = newpolygon;
488 expected.pop_front(); // remove first point
489 expected.pop_front(); // remove second point
490 expected.pop_front(); // remove third point
491 SphericalPointDistribution::Polygon_t remaining =
492 SphericalPointDistribution::matchSphericalPointDistributions(
493 polygon,
494 newpolygon);
495 CPPUNIT_ASSERT_EQUAL( expected, remaining );
496 }
497
498 // test with three points, full rotation
499 {
500 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
501 SphericalPointDistribution::Polygon_t polygon;
502 polygon +=
503 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
504 RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI),
505 RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI);
506 SphericalPointDistribution::Polygon_t newpolygon =
507 SPD.get<5>();
508 SphericalPointDistribution::Polygon_t expected = newpolygon;
509 expected.pop_front(); // remove first point
510 expected.pop_front(); // remove second point
511 expected.pop_front(); // remove third point
512 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
513 iter != expected.end(); ++iter)
514 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
515 SphericalPointDistribution::Polygon_t remaining =
516 SphericalPointDistribution::matchSphericalPointDistributions(
517 polygon,
518 newpolygon);
519 CPPUNIT_ASSERT_EQUAL( expected, remaining );
520 }
521}
522
523/** UnitTest for matchSphericalPointDistributions() with six points
524 */
525void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_6()
526{
527 SphericalPointDistribution SPD(1.);
528
529 // test with one point, matching trivially
530 {
531 SphericalPointDistribution::Polygon_t polygon;
532 polygon += Vector(1.,0.,0.);
533 SphericalPointDistribution::Polygon_t newpolygon =
534 SPD.get<6>();
535 SphericalPointDistribution::Polygon_t expected = newpolygon;
536 expected.pop_front(); // remove first point
537 SphericalPointDistribution::Polygon_t remaining =
538 SphericalPointDistribution::matchSphericalPointDistributions(
539 polygon,
540 newpolygon);
541 CPPUNIT_ASSERT_EQUAL( expected, remaining );
542 }
543
544 // test with one point, just a flip of axis
545 {
546 SphericalPointDistribution::Polygon_t polygon;
547 polygon += Vector(0.,1.,0.);
548 SphericalPointDistribution::Polygon_t newpolygon =
549 SPD.get<6>();
550 SphericalPointDistribution::Polygon_t expected = newpolygon;
551 expected.pop_front(); // remove first point
552 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
553 iter != expected.end(); ++iter) {
554 std::swap((*iter)[0], (*iter)[1]);
555 (*iter)[0] *= -1.;
556 }
557 SphericalPointDistribution::Polygon_t remaining =
558 SphericalPointDistribution::matchSphericalPointDistributions(
559 polygon,
560 newpolygon);
561 CPPUNIT_ASSERT_EQUAL( expected, remaining );
562 }
563
564 // test with two points, matching trivially
565 {
566 SphericalPointDistribution::Polygon_t polygon;
567 polygon += Vector(1.,0.,0.), Vector(-1.,0.,0.);
568 SphericalPointDistribution::Polygon_t newpolygon =
569 SPD.get<6>();
570 SphericalPointDistribution::Polygon_t expected = newpolygon;
571 expected.pop_front(); // remove first point
572 expected.pop_front(); // remove second spoint
573 SphericalPointDistribution::Polygon_t remaining =
574 SphericalPointDistribution::matchSphericalPointDistributions(
575 polygon,
576 newpolygon);
577 CPPUNIT_ASSERT_EQUAL( expected, remaining );
578 }
579
580 // test with two points, full rotation
581 {
582 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
583 SphericalPointDistribution::Polygon_t polygon;
584 polygon +=
585 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
586 RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
587 SphericalPointDistribution::Polygon_t newpolygon =
588 SPD.get<6>();
589 SphericalPointDistribution::Polygon_t expected = newpolygon;
590 expected.pop_front(); // remove first point
591 expected.pop_front(); // remove second spoint
592 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
593 iter != expected.end(); ++iter)
594 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
595 SphericalPointDistribution::Polygon_t remaining =
596 SphericalPointDistribution::matchSphericalPointDistributions(
597 polygon,
598 newpolygon);
599 // the four remaining points sit on a plane that may have been rotated arbitrarily
600 // so we cannot simply check for equality between expected and remaining
601 // hence, we just check that they are orthogonal to the first two points
602 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
603 for (SphericalPointDistribution::Polygon_t::const_iterator fixiter = polygon.begin();
604 fixiter != polygon.end(); ++fixiter) {
605 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
606 iter != remaining.end(); ++iter) {
607 CPPUNIT_ASSERT( (*fixiter).IsNormalTo(*iter) );
608 }
609 }
610 }
611
612 // test with three points, matching trivially
613 {
614 SphericalPointDistribution::Polygon_t polygon;
615 polygon +=
616 Vector(1.,0.,0.),
617 Vector(-1., 0.0, 0.0),
618 Vector(0.0, 1., 0.0);
619 SphericalPointDistribution::Polygon_t newpolygon =
620 SPD.get<6>();
621 SphericalPointDistribution::Polygon_t expected = newpolygon;
622 expected.pop_front(); // remove first point
623 expected.pop_front(); // remove second point
624 expected.pop_front(); // remove third point
625 SphericalPointDistribution::Polygon_t remaining =
626 SphericalPointDistribution::matchSphericalPointDistributions(
627 polygon,
628 newpolygon);
629 CPPUNIT_ASSERT_EQUAL( expected, remaining );
630 }
631
632 // test with three points, full rotation
633 {
634 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
635 SphericalPointDistribution::Polygon_t polygon;
636 polygon +=
637 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
638 RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI),
639 RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI);
640 SphericalPointDistribution::Polygon_t newpolygon =
641 SPD.get<6>();
642 SphericalPointDistribution::Polygon_t expected = newpolygon;
643 expected.pop_front(); // remove first point
644 expected.pop_front(); // remove second point
645 expected.pop_front(); // remove third point
646 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
647 iter != expected.end(); ++iter)
648 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
649 SphericalPointDistribution::Polygon_t remaining =
650 SphericalPointDistribution::matchSphericalPointDistributions(
651 polygon,
652 newpolygon);
653 CPPUNIT_ASSERT_EQUAL( expected, remaining );
654 }
655}
656
657/** UnitTest for matchSphericalPointDistributions() with seven points
658 */
659void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_7()
660{
661 SphericalPointDistribution SPD(1.);
662
663 // test with one point, matching trivially
664 {
665 SphericalPointDistribution::Polygon_t polygon;
666 polygon += Vector(1.,0.,0.);
667 SphericalPointDistribution::Polygon_t newpolygon =
668 SPD.get<7>();
669 SphericalPointDistribution::Polygon_t expected = newpolygon;
670 expected.pop_front(); // remove first point
671 SphericalPointDistribution::Polygon_t remaining =
672 SphericalPointDistribution::matchSphericalPointDistributions(
673 polygon,
674 newpolygon);
675 CPPUNIT_ASSERT_EQUAL( expected, remaining );
676 }
677
678 // test with one point, just a flip of axis
679 {
680 SphericalPointDistribution::Polygon_t polygon;
681 polygon += Vector(0.,1.,0.);
682 SphericalPointDistribution::Polygon_t newpolygon =
683 SPD.get<7>();
684 SphericalPointDistribution::Polygon_t expected = newpolygon;
685 expected.pop_front(); // remove first point
686 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
687 iter != expected.end(); ++iter) {
688 std::swap((*iter)[0], (*iter)[1]);
689 (*iter)[0] *= -1.;
690 }
691 SphericalPointDistribution::Polygon_t remaining =
692 SphericalPointDistribution::matchSphericalPointDistributions(
693 polygon,
694 newpolygon);
695 CPPUNIT_ASSERT_EQUAL( expected, remaining );
696 }
697
698 // test with two points, matching trivially
699 {
700 SphericalPointDistribution::Polygon_t polygon;
701 polygon += Vector(1.,0.,0.), Vector(-1.,0.,0.);
702 SphericalPointDistribution::Polygon_t newpolygon =
703 SPD.get<7>();
704 SphericalPointDistribution::Polygon_t expected = newpolygon;
705 expected.pop_front(); // remove first point
706 expected.pop_front(); // remove second point
707 SphericalPointDistribution::Polygon_t remaining =
708 SphericalPointDistribution::matchSphericalPointDistributions(
709 polygon,
710 newpolygon);
711 CPPUNIT_ASSERT_EQUAL( expected, remaining );
712 }
713
714 // test with two points, full rotation
715 {
716 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
717 SphericalPointDistribution::Polygon_t polygon;
718 polygon +=
719 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
720 RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
721 SphericalPointDistribution::Polygon_t newpolygon =
722 SPD.get<7>();
723 SphericalPointDistribution::Polygon_t expected = newpolygon;
724 expected.pop_front(); // remove first point
725 expected.pop_front(); // remove second point
726 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
727 iter != expected.end(); ++iter)
728 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
729 SphericalPointDistribution::Polygon_t remaining =
730 SphericalPointDistribution::matchSphericalPointDistributions(
731 polygon,
732 newpolygon);
733 // the five remaining points sit on a plane that may have been rotated arbitrarily
734 // so we cannot simply check for equality between expected and remaining
735 // hence, we just check that they are orthogonal to the first two points
736 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
737 for (SphericalPointDistribution::Polygon_t::const_iterator fixiter = polygon.begin();
738 fixiter != polygon.end(); ++fixiter) {
739 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
740 iter != remaining.end(); ++iter) {
741 CPPUNIT_ASSERT( (*fixiter).IsNormalTo(*iter) );
742 }
743 }
744 }
745
746 // test with three points, matching trivially
747 {
748 SphericalPointDistribution::Polygon_t polygon;
749 polygon +=
750 Vector(1.,0.,0.),
751 Vector(-1., 0.0, 0.0),
752 Vector(0.0, 1., 0.0);
753 SphericalPointDistribution::Polygon_t newpolygon =
754 SPD.get<7>();
755 SphericalPointDistribution::Polygon_t expected = newpolygon;
756 expected.pop_front(); // remove first point
757 expected.pop_front(); // remove second point
758 expected.pop_front(); // remove third point
759 SphericalPointDistribution::Polygon_t remaining =
760 SphericalPointDistribution::matchSphericalPointDistributions(
761 polygon,
762 newpolygon);
763 CPPUNIT_ASSERT_EQUAL( expected, remaining );
764 }
765
766 // test with three points, full rotation
767 {
768 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
769 SphericalPointDistribution::Polygon_t polygon;
770 polygon +=
771 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
772 RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI),
773 RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI);
774 SphericalPointDistribution::Polygon_t newpolygon =
775 SPD.get<7>();
776 SphericalPointDistribution::Polygon_t expected = newpolygon;
777 expected.pop_front(); // remove first point
778 expected.pop_front(); // remove second point
779 expected.pop_front(); // remove third point
780 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
781 iter != expected.end(); ++iter)
782 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
783 SphericalPointDistribution::Polygon_t remaining =
784 SphericalPointDistribution::matchSphericalPointDistributions(
785 polygon,
786 newpolygon);
787 CPPUNIT_ASSERT_EQUAL( expected, remaining );
788 }
789}
790
791/** UnitTest for matchSphericalPointDistributions() with eight points
792 */
793void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_8()
794{
795 SphericalPointDistribution SPD(1.);
796
797 // test with one point, matching trivially
798 {
799 SphericalPointDistribution::Polygon_t polygon;
800 polygon += Vector(1.,0.,0.);
801 SphericalPointDistribution::Polygon_t newpolygon =
802 SPD.get<8>();
803 SphericalPointDistribution::Polygon_t expected = newpolygon;
804 expected.pop_front(); // remove first point
805 SphericalPointDistribution::Polygon_t remaining =
806 SphericalPointDistribution::matchSphericalPointDistributions(
807 polygon,
808 newpolygon);
809 CPPUNIT_ASSERT_EQUAL( expected, remaining );
810 }
811
812 // test with one point, just a flip of axis
813 {
814 SphericalPointDistribution::Polygon_t polygon;
815 polygon += Vector(0.,1.,0.);
816 SphericalPointDistribution::Polygon_t newpolygon =
817 SPD.get<8>();
818 SphericalPointDistribution::Polygon_t expected = newpolygon;
819 expected.pop_front(); // remove first point
820 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
821 iter != expected.end(); ++iter) {
822 std::swap((*iter)[0], (*iter)[1]);
823 (*iter)[0] *= -1.;
824 }
825 SphericalPointDistribution::Polygon_t remaining =
826 SphericalPointDistribution::matchSphericalPointDistributions(
827 polygon,
828 newpolygon);
829 CPPUNIT_ASSERT_EQUAL( expected, remaining );
830 }
831
832 // test with two points, matching trivially
833 {
834 SphericalPointDistribution::Polygon_t polygon;
835 polygon += Vector(1.,0.,0.), Vector(-1.,0.,0.);
836 SphericalPointDistribution::Polygon_t newpolygon =
837 SPD.get<8>();
838 SphericalPointDistribution::Polygon_t expected = newpolygon;
839 expected.pop_front(); // remove first point
840 expected.pop_front(); // remove second point
841 SphericalPointDistribution::Polygon_t remaining =
842 SphericalPointDistribution::matchSphericalPointDistributions(
843 polygon,
844 newpolygon);
845 CPPUNIT_ASSERT_EQUAL( expected, remaining );
846 }
847
848 // test with two points, full rotation
849 {
850 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
851 SphericalPointDistribution::Polygon_t polygon;
852 polygon +=
853 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
854 RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
855 SphericalPointDistribution::Polygon_t newpolygon =
856 SPD.get<8>();
857 SphericalPointDistribution::Polygon_t expected = newpolygon;
858 expected.pop_front(); // remove first point
859 expected.pop_front(); // remove second point
860 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
861 iter != expected.end(); ++iter)
862 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
863 SphericalPointDistribution::Polygon_t remaining =
864 SphericalPointDistribution::matchSphericalPointDistributions(
865 polygon,
866 newpolygon);
867 // the six remaining points sit on two planes that may have been rotated arbitrarily
868 // so we cannot simply check for equality between expected and remaining
869 // hence, we just check that they are orthogonal to the first two points
870 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
871 for (SphericalPointDistribution::Polygon_t::const_iterator fixiter = polygon.begin();
872 fixiter != polygon.end(); ++fixiter) {
873 SphericalPointDistribution::Polygon_t::const_iterator expectiter = expected.begin();
874 SphericalPointDistribution::Polygon_t::const_iterator remainiter = remaining.begin();
875 for (;remainiter != remaining.end(); ++expectiter, ++remainiter) {
876 // check that points in expected/remaining have same angle to the given ones
877// CPPUNIT_ASSERT_EQUAL( (*expectiter).Angle(*fixiter), (*remainiter).Angle(*fixiter) );
878 CPPUNIT_ASSERT( fabs( (*expectiter).Angle(*fixiter) - (*remainiter).Angle(*fixiter) )
879 < std::numeric_limits<double>::epsilon()*1e4 );
880 }
881 }
882 }
883
884 // test with three points, matching trivially
885 {
886 SphericalPointDistribution::Polygon_t polygon;
887 polygon +=
888 Vector(1.,0.,0.),
889 Vector(-1., 0.0, 0.0),
890 Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0);
891 SphericalPointDistribution::Polygon_t newpolygon =
892 SPD.get<8>();
893 SphericalPointDistribution::Polygon_t expected = newpolygon;
894 expected.pop_front(); // remove first point
895 expected.pop_front(); // remove second point
896 expected.pop_front(); // remove third point
897 SphericalPointDistribution::Polygon_t remaining =
898 SphericalPointDistribution::matchSphericalPointDistributions(
899 polygon,
900 newpolygon);
901 CPPUNIT_ASSERT_EQUAL( expected, remaining );
902 }
903
904 // test with three points, full rotation
905 {
906 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
907 SphericalPointDistribution::Polygon_t polygon;
908 polygon +=
909 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
910 RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI),
911 RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 47.6/180*M_PI);
912 SphericalPointDistribution::Polygon_t newpolygon =
913 SPD.get<8>();
914 SphericalPointDistribution::Polygon_t expected = newpolygon;
915 expected.pop_front(); // remove first point
916 expected.pop_front(); // remove second point
917 expected.pop_front(); // remove third point
918 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
919 iter != expected.end(); ++iter)
920 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
921 SphericalPointDistribution::Polygon_t remaining =
922 SphericalPointDistribution::matchSphericalPointDistributions(
923 polygon,
924 newpolygon);
925 CPPUNIT_ASSERT_EQUAL( expected, remaining );
926 }
927}
Note: See TracBrowser for help on using the repository browser.