source: src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp@ 2199c2

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 2199c2 was 2199c2, checked in by Frederik Heber <heber@…>, 9 years ago

Extended SphericalPointDistribution::Polygon_t to WeightedPolygon_t.

  • contains additionally the weights from the already present points.
  • in order to deal sensibly with present bonds of higher degree (>1) that shift neighboring occupied orbitals even further away, we additionally pass on the bond degree. This indicates how many points of the N points have to be accumulated for this on present bond.
  • TESTS: Regression test FragmentMolecule-cylces failing for the moment.
  • Property mode set to 100644
File size: 45.1 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::WeightedPolygon_t polygon;
93 polygon += std::make_pair(Vector(1.,0.,0.), 1);
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::WeightedPolygon_t polygon;
108 polygon += std::make_pair( Vector(0.,1.,0.), 1);
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::WeightedPolygon_t polygon;
123 polygon += std::make_pair( Vector(0.,0.,-1.), 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::WeightedPolygon_t polygon;
139 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
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
152void perturbPolygon(
153 SphericalPointDistribution::WeightedPolygon_t &_polygon,
154 double _amplitude
155 )
156{
157 for (SphericalPointDistribution::WeightedPolygon_t::iterator iter = _polygon.begin();
158 iter != _polygon.end(); ++iter) {
159 Vector perturber;
160 perturber.GetOneNormalVector(iter->first);
161 perturber.Scale(_amplitude);
162 iter->first = iter->first + perturber;
163 (iter->first).Normalize();
164 }
165}
166
167static
168bool areEqualToWithinBounds(
169 const SphericalPointDistribution::Polygon_t &_polygon,
170 const SphericalPointDistribution::Polygon_t &_otherpolygon,
171 double _amplitude
172 )
173{
174 // same size?
175 if (_polygon.size() != _otherpolygon.size())
176 return false;
177 // same points ? We just check witrh trivial mapping, nothing fancy ...
178 bool status = true;
179 SphericalPointDistribution::Polygon_t::const_iterator iter = _polygon.begin();
180 SphericalPointDistribution::Polygon_t::const_iterator otheriter = _otherpolygon.begin();
181 for (; iter != _polygon.end(); ++iter, ++otheriter) {
182 status &= (*iter - *otheriter).Norm() < _amplitude;
183 }
184 return status;
185}
186
187/** UnitTest for areEqualToWithinBounds()
188 */
189void SphericalPointDistributionTest::areEqualToWithinBoundsTest()
190{
191 // test with no points
192 {
193 SphericalPointDistribution::Polygon_t polygon;
194 SphericalPointDistribution::Polygon_t expected = polygon;
195 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
196 }
197 // test with one point
198 {
199 SphericalPointDistribution::Polygon_t polygon;
200 polygon += Vector(1.,0.,0.);
201 SphericalPointDistribution::Polygon_t expected = polygon;
202 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
203 }
204 // test with two points
205 {
206 SphericalPointDistribution::Polygon_t polygon;
207 polygon += Vector(1.,0.,0.);
208 polygon += Vector(0.,1.,0.);
209 SphericalPointDistribution::Polygon_t expected = polygon;
210 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
211 }
212
213 // test with two points in different order: THIS GOES WRONG: We only check trivially
214 {
215 SphericalPointDistribution::Polygon_t polygon;
216 polygon += Vector(1.,0.,0.);
217 polygon += Vector(0.,1.,0.);
218 SphericalPointDistribution::Polygon_t expected;
219 expected += Vector(0.,1.,0.);
220 expected += Vector(1.,0.,0.);
221 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
222 }
223
224 // test with two different points
225 {
226 SphericalPointDistribution::Polygon_t polygon;
227 polygon += Vector(1.,0.,0.);
228 polygon += Vector(0.,1.,0.);
229 SphericalPointDistribution::Polygon_t expected;
230 expected += Vector(1.01,0.,0.);
231 expected += Vector(0.,1.,0.);
232 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, 0.05) );
233 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.005) );
234 }
235
236 // test with different number of points
237 {
238 SphericalPointDistribution::Polygon_t polygon;
239 polygon += Vector(1.,0.,0.);
240 polygon += Vector(0.,1.,0.);
241 SphericalPointDistribution::Polygon_t expected;
242 expected += Vector(0.,1.,0.);
243 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.05) );
244 }
245}
246
247
248/** UnitTest for matchSphericalPointDistributions() with three points
249 */
250void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_3()
251{
252 SphericalPointDistribution SPD(1.);
253
254 // test with one point, matching trivially
255 {
256 SphericalPointDistribution::WeightedPolygon_t polygon;
257 polygon += std::make_pair( Vector(1.,0.,0.), 1);
258 SphericalPointDistribution::Polygon_t newpolygon =
259 SPD.get<3>();
260 SphericalPointDistribution::Polygon_t expected = newpolygon;
261 expected.pop_front(); // remove first point
262 SphericalPointDistribution::Polygon_t remaining =
263 SphericalPointDistribution::matchSphericalPointDistributions(
264 polygon,
265 newpolygon);
266 CPPUNIT_ASSERT_EQUAL( expected, remaining );
267 }
268
269 // test with one point, just a flip of x and y axis
270 {
271 SphericalPointDistribution::WeightedPolygon_t polygon;
272 polygon += std::make_pair( Vector(0.,1.,0.), 1);
273 SphericalPointDistribution::Polygon_t newpolygon =
274 SPD.get<3>();
275 SphericalPointDistribution::Polygon_t expected = newpolygon;
276 expected.pop_front(); // remove first point
277 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
278 iter != expected.end(); ++iter) {
279 std::swap((*iter)[0], (*iter)[1]);
280 (*iter)[0] *= -1.;
281 }
282 SphericalPointDistribution::Polygon_t remaining =
283 SphericalPointDistribution::matchSphericalPointDistributions(
284 polygon,
285 newpolygon);
286 CPPUNIT_ASSERT_EQUAL( expected, remaining );
287 }
288
289 // test with two points, matching trivially
290 {
291 SphericalPointDistribution::WeightedPolygon_t polygon;
292 polygon += std::make_pair( Vector(1.,0.,0.), 1);
293 polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
294 SphericalPointDistribution::Polygon_t newpolygon =
295 SPD.get<3>();
296 SphericalPointDistribution::Polygon_t expected = newpolygon;
297 expected.pop_front(); // remove first point
298 expected.pop_front(); // remove second point
299 SphericalPointDistribution::Polygon_t remaining =
300 SphericalPointDistribution::matchSphericalPointDistributions(
301 polygon,
302 newpolygon);
303 CPPUNIT_ASSERT_EQUAL( expected, remaining );
304 // also slightly perturbed
305 const double amplitude = 0.05;
306 perturbPolygon(polygon, amplitude);
307 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
308 }
309
310 // test with two points, full rotation
311 {
312 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
313 SphericalPointDistribution::WeightedPolygon_t polygon;
314 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
315 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
316 SphericalPointDistribution::Polygon_t newpolygon =
317 SPD.get<3>();
318 SphericalPointDistribution::Polygon_t expected = newpolygon;
319 expected.pop_front(); // remove first point
320 expected.pop_front(); // remove second point
321 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
322 iter != expected.end(); ++iter)
323 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
324 SphericalPointDistribution::Polygon_t remaining =
325 SphericalPointDistribution::matchSphericalPointDistributions(
326 polygon,
327 newpolygon);
328 CPPUNIT_ASSERT_EQUAL( expected, remaining );
329 // also slightly perturbed
330 const double amplitude = 0.05;
331 perturbPolygon(polygon, amplitude);
332 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
333 }
334
335 // test with three points, matching trivially
336 {
337 SphericalPointDistribution::WeightedPolygon_t polygon;
338 polygon += std::make_pair( Vector(1.,0.,0.), 1);
339 polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
340 polygon += std::make_pair( Vector(-0.5, -sqrt(3)*0.5,0.), 1);
341 SphericalPointDistribution::Polygon_t newpolygon =
342 SPD.get<3>();
343 SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
344 SphericalPointDistribution::Polygon_t remaining =
345 SphericalPointDistribution::matchSphericalPointDistributions(
346 polygon,
347 newpolygon);
348 CPPUNIT_ASSERT_EQUAL( expected, remaining );
349 // also slightly perturbed
350 const double amplitude = 0.05;
351 perturbPolygon(polygon, amplitude);
352 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
353 }
354
355
356 // test with three points, full rotation
357 {
358 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
359 SphericalPointDistribution::WeightedPolygon_t polygon;
360 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
361 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
362 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, -sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
363 SphericalPointDistribution::Polygon_t newpolygon =
364 SPD.get<3>();
365 SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
366 SphericalPointDistribution::Polygon_t remaining =
367 SphericalPointDistribution::matchSphericalPointDistributions(
368 polygon,
369 newpolygon);
370 CPPUNIT_ASSERT_EQUAL( expected, remaining );
371 // also slightly perturbed
372 const double amplitude = 0.05;
373 perturbPolygon(polygon, amplitude);
374 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
375 }
376}
377
378/** UnitTest for matchSphericalPointDistributions() with four points
379 */
380void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_4()
381{
382 SphericalPointDistribution SPD(1.);
383
384 // test with one point, matching trivially
385 {
386 SphericalPointDistribution::WeightedPolygon_t polygon;
387 polygon += std::make_pair( Vector(1.,0.,0.), 1);
388 SphericalPointDistribution::Polygon_t newpolygon =
389 SPD.get<4>();
390 SphericalPointDistribution::Polygon_t expected = newpolygon;
391 expected.pop_front(); // remove first point
392 SphericalPointDistribution::Polygon_t remaining =
393 SphericalPointDistribution::matchSphericalPointDistributions(
394 polygon,
395 newpolygon);
396 CPPUNIT_ASSERT_EQUAL( expected, remaining );
397 }
398
399 // test with one point, just a flip of axis
400 {
401 SphericalPointDistribution::WeightedPolygon_t polygon;
402 polygon += std::make_pair( Vector(0.,1.,0.), 1);
403 SphericalPointDistribution::Polygon_t newpolygon =
404 SPD.get<4>();
405 SphericalPointDistribution::Polygon_t expected = newpolygon;
406 expected.pop_front(); // remove first point
407 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
408 iter != expected.end(); ++iter) {
409 std::swap((*iter)[0], (*iter)[1]);
410 (*iter)[0] *= -1.;
411 }
412 SphericalPointDistribution::Polygon_t remaining =
413 SphericalPointDistribution::matchSphericalPointDistributions(
414 polygon,
415 newpolygon);
416 CPPUNIT_ASSERT_EQUAL( expected, remaining );
417 }
418
419 // test with two points, matching trivially
420 {
421 SphericalPointDistribution::WeightedPolygon_t polygon;
422 polygon += std::make_pair( Vector(1.,0.,0.), 1);
423 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
424 SphericalPointDistribution::Polygon_t newpolygon =
425 SPD.get<4>();
426 SphericalPointDistribution::Polygon_t expected = newpolygon;
427 expected.pop_front(); // remove first point
428 expected.pop_front(); // remove second point
429 SphericalPointDistribution::Polygon_t remaining =
430 SphericalPointDistribution::matchSphericalPointDistributions(
431 polygon,
432 newpolygon);
433 CPPUNIT_ASSERT_EQUAL( expected, remaining );
434 // also slightly perturbed
435 const double amplitude = 0.05;
436 perturbPolygon(polygon, amplitude);
437 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
438 }
439
440 // test with two points, matching trivially, also with slightly perturbed
441 {
442 SphericalPointDistribution::WeightedPolygon_t polygon;
443 polygon += std::make_pair( Vector(1.,0.,0.), 1);
444 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
445 SphericalPointDistribution::Polygon_t newpolygon =
446 SPD.get<4>();
447 SphericalPointDistribution::Polygon_t expected = newpolygon;
448 expected.pop_front(); // remove first point
449 expected.pop_front(); // remove second point
450 SphericalPointDistribution::Polygon_t remaining =
451 SphericalPointDistribution::matchSphericalPointDistributions(
452 polygon,
453 newpolygon);
454 CPPUNIT_ASSERT_EQUAL( expected, remaining );
455 // also slightly perturbed
456 const double amplitude = 0.05;
457 perturbPolygon(polygon, amplitude);
458 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
459 }
460
461 // test with two points, full rotation
462 {
463 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
464 SphericalPointDistribution::WeightedPolygon_t polygon;
465 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
466 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
467 SphericalPointDistribution::Polygon_t newpolygon =
468 SPD.get<4>();
469 SphericalPointDistribution::Polygon_t expected = newpolygon;
470 expected.pop_front(); // remove first point
471 expected.pop_front(); // remove second point
472 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
473 iter != expected.end(); ++iter)
474 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
475 SphericalPointDistribution::Polygon_t remaining =
476 SphericalPointDistribution::matchSphericalPointDistributions(
477 polygon,
478 newpolygon);
479 CPPUNIT_ASSERT_EQUAL( expected, remaining );
480 // also slightly perturbed
481 const double amplitude = 0.05;
482 perturbPolygon(polygon, amplitude);
483 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
484 }
485
486 // test with three points, matching trivially
487 {
488 SphericalPointDistribution::WeightedPolygon_t polygon;
489 polygon += std::make_pair( Vector(1.,0.,0.), 1);
490 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
491 polygon += std::make_pair( Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 1);
492 SphericalPointDistribution::Polygon_t newpolygon =
493 SPD.get<4>();
494 SphericalPointDistribution::Polygon_t expected = newpolygon;
495 expected.pop_front(); // remove first point
496 expected.pop_front(); // remove second point
497 expected.pop_front(); // remove third point
498 SphericalPointDistribution::Polygon_t remaining =
499 SphericalPointDistribution::matchSphericalPointDistributions(
500 polygon,
501 newpolygon);
502 CPPUNIT_ASSERT_EQUAL( expected, remaining );
503 // also slightly perturbed
504 const double amplitude = 0.05;
505 perturbPolygon(polygon, amplitude);
506 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
507 }
508
509 // test with three points, full rotation
510 {
511 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
512 SphericalPointDistribution::WeightedPolygon_t polygon;
513 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
514 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
515 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 47.6/180*M_PI), 1);
516 SphericalPointDistribution::Polygon_t newpolygon =
517 SPD.get<4>();
518 SphericalPointDistribution::Polygon_t expected = newpolygon;
519 expected.pop_front(); // remove first point
520 expected.pop_front(); // remove second point
521 expected.pop_front(); // remove third point
522 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
523 iter != expected.end(); ++iter)
524 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
525 SphericalPointDistribution::Polygon_t remaining =
526 SphericalPointDistribution::matchSphericalPointDistributions(
527 polygon,
528 newpolygon);
529 CPPUNIT_ASSERT_EQUAL( expected, remaining );
530 // also slightly perturbed
531 const double amplitude = 0.05;
532 perturbPolygon(polygon, amplitude);
533 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
534 }
535}
536
537/** UnitTest for matchSphericalPointDistributions() with five points
538 */
539void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_5()
540{
541 SphericalPointDistribution SPD(1.);
542
543 // test with one point, matching trivially
544 {
545 SphericalPointDistribution::WeightedPolygon_t polygon;
546 polygon += std::make_pair( Vector(1.,0.,0.), 1);
547 SphericalPointDistribution::Polygon_t newpolygon =
548 SPD.get<5>();
549 SphericalPointDistribution::Polygon_t expected = newpolygon;
550 expected.pop_front(); // remove first point
551 SphericalPointDistribution::Polygon_t remaining =
552 SphericalPointDistribution::matchSphericalPointDistributions(
553 polygon,
554 newpolygon);
555 CPPUNIT_ASSERT_EQUAL( expected, remaining );
556 }
557
558 // test with one point, just a flip of axis
559 {
560 SphericalPointDistribution::WeightedPolygon_t polygon;
561 polygon += std::make_pair( Vector(0.,1.,0.), 1);
562 SphericalPointDistribution::Polygon_t newpolygon =
563 SPD.get<5>();
564 SphericalPointDistribution::Polygon_t expected = newpolygon;
565 expected.pop_front(); // remove first point
566 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
567 iter != expected.end(); ++iter) {
568 std::swap((*iter)[0], (*iter)[1]);
569 (*iter)[0] *= -1.;
570 }
571 SphericalPointDistribution::Polygon_t remaining =
572 SphericalPointDistribution::matchSphericalPointDistributions(
573 polygon,
574 newpolygon);
575 CPPUNIT_ASSERT_EQUAL( expected, remaining );
576 }
577
578 // test with two points, matching trivially
579 {
580 SphericalPointDistribution::WeightedPolygon_t polygon;
581 polygon += std::make_pair( Vector(1.,0.,0.), 1);
582 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
583 SphericalPointDistribution::Polygon_t newpolygon =
584 SPD.get<5>();
585 SphericalPointDistribution::Polygon_t expected = newpolygon;
586 expected.pop_front(); // remove first point
587 expected.pop_front(); // remove second point
588 SphericalPointDistribution::Polygon_t remaining =
589 SphericalPointDistribution::matchSphericalPointDistributions(
590 polygon,
591 newpolygon);
592 CPPUNIT_ASSERT_EQUAL( expected, remaining );
593 // also slightly perturbed
594 const double amplitude = 0.05;
595 perturbPolygon(polygon, amplitude);
596 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
597 }
598
599 // test with two points, full rotation
600 {
601 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
602 SphericalPointDistribution::WeightedPolygon_t polygon;
603 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180.*M_PI), 1);
604 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180.*M_PI), 1);
605 SphericalPointDistribution::Polygon_t newpolygon =
606 SPD.get<5>();
607 SphericalPointDistribution::Polygon_t expected = newpolygon;
608 expected.pop_front(); // remove first point
609 expected.pop_front(); // remove second point
610 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
611 iter != expected.end(); ++iter)
612 *iter = RotationAxis.rotateVector(*iter, 47.6/180.*M_PI);
613 SphericalPointDistribution::Polygon_t remaining =
614 SphericalPointDistribution::matchSphericalPointDistributions(
615 polygon,
616 newpolygon);
617 // the three remaining points sit on a plane that may be rotated arbitrarily
618 // so we cannot simply check for equality between expected and remaining
619 // hence, we just check that they are orthogonal to the first two points
620 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
621 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
622 fixiter != polygon.end(); ++fixiter) {
623 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
624 iter != remaining.end(); ++iter) {
625 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
626 }
627 }
628 }
629
630 // test with three points, matching trivially
631 {
632 SphericalPointDistribution::WeightedPolygon_t polygon;
633 polygon += std::make_pair( Vector(1.,0.,0.), 1);
634 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
635 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
636 SphericalPointDistribution::Polygon_t newpolygon =
637 SPD.get<5>();
638 SphericalPointDistribution::Polygon_t expected = newpolygon;
639 expected.pop_front(); // remove first point
640 expected.pop_front(); // remove second point
641 expected.pop_front(); // remove third point
642 SphericalPointDistribution::Polygon_t remaining =
643 SphericalPointDistribution::matchSphericalPointDistributions(
644 polygon,
645 newpolygon);
646 CPPUNIT_ASSERT_EQUAL( expected, remaining );
647 // also slightly perturbed
648 const double amplitude = 0.05;
649 perturbPolygon(polygon, amplitude);
650 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
651 }
652
653 // test with three points, full rotation
654 {
655 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
656 SphericalPointDistribution::WeightedPolygon_t polygon;
657 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
658 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
659 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
660 SphericalPointDistribution::Polygon_t newpolygon =
661 SPD.get<5>();
662 SphericalPointDistribution::Polygon_t expected = newpolygon;
663 expected.pop_front(); // remove first point
664 expected.pop_front(); // remove second point
665 expected.pop_front(); // remove third point
666 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
667 iter != expected.end(); ++iter)
668 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
669 SphericalPointDistribution::Polygon_t remaining =
670 SphericalPointDistribution::matchSphericalPointDistributions(
671 polygon,
672 newpolygon);
673 CPPUNIT_ASSERT_EQUAL( expected, remaining );
674 // also slightly perturbed
675 const double amplitude = 0.05;
676 perturbPolygon(polygon, amplitude);
677 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
678 }
679}
680
681/** UnitTest for matchSphericalPointDistributions() with six points
682 */
683void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_6()
684{
685 SphericalPointDistribution SPD(1.);
686
687 // test with one point, matching trivially
688 {
689 SphericalPointDistribution::WeightedPolygon_t polygon;
690 polygon += std::make_pair( Vector(1.,0.,0.), 1);
691 SphericalPointDistribution::Polygon_t newpolygon =
692 SPD.get<6>();
693 SphericalPointDistribution::Polygon_t expected = newpolygon;
694 expected.pop_front(); // remove first point
695 SphericalPointDistribution::Polygon_t remaining =
696 SphericalPointDistribution::matchSphericalPointDistributions(
697 polygon,
698 newpolygon);
699 CPPUNIT_ASSERT_EQUAL( expected, remaining );
700 }
701
702 // test with one point, just a flip of axis
703 {
704 SphericalPointDistribution::WeightedPolygon_t polygon;
705 polygon += std::make_pair( Vector(0.,1.,0.), 1);
706 SphericalPointDistribution::Polygon_t newpolygon =
707 SPD.get<6>();
708 SphericalPointDistribution::Polygon_t expected = newpolygon;
709 expected.pop_front(); // remove first point
710 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
711 iter != expected.end(); ++iter) {
712 std::swap((*iter)[0], (*iter)[1]);
713 (*iter)[0] *= -1.;
714 }
715 SphericalPointDistribution::Polygon_t remaining =
716 SphericalPointDistribution::matchSphericalPointDistributions(
717 polygon,
718 newpolygon);
719 CPPUNIT_ASSERT_EQUAL( expected, remaining );
720 }
721
722 // test with two points, matching trivially
723 {
724 SphericalPointDistribution::WeightedPolygon_t polygon;
725 polygon += std::make_pair( Vector(1.,0.,0.), 1);
726 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
727 SphericalPointDistribution::Polygon_t newpolygon =
728 SPD.get<6>();
729 SphericalPointDistribution::Polygon_t expected = newpolygon;
730 expected.pop_front(); // remove first point
731 expected.pop_front(); // remove second spoint
732 SphericalPointDistribution::Polygon_t remaining =
733 SphericalPointDistribution::matchSphericalPointDistributions(
734 polygon,
735 newpolygon);
736 CPPUNIT_ASSERT_EQUAL( expected, remaining );
737 // also slightly perturbed
738 const double amplitude = 0.05;
739 perturbPolygon(polygon, amplitude);
740 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
741 }
742
743 // test with two points, full rotation
744 {
745 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
746 SphericalPointDistribution::WeightedPolygon_t polygon;
747 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
748 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
749 SphericalPointDistribution::Polygon_t newpolygon =
750 SPD.get<6>();
751 SphericalPointDistribution::Polygon_t expected = newpolygon;
752 expected.pop_front(); // remove first point
753 expected.pop_front(); // remove second spoint
754 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
755 iter != expected.end(); ++iter)
756 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
757 SphericalPointDistribution::Polygon_t remaining =
758 SphericalPointDistribution::matchSphericalPointDistributions(
759 polygon,
760 newpolygon);
761 // the four remaining points sit on a plane that may have been rotated arbitrarily
762 // so we cannot simply check for equality between expected and remaining
763 // hence, we just check that they are orthogonal to the first two points
764 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
765 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
766 fixiter != polygon.end(); ++fixiter) {
767 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
768 iter != remaining.end(); ++iter) {
769 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
770 }
771 }
772 }
773
774 // test with three points, matching trivially
775 {
776 SphericalPointDistribution::WeightedPolygon_t polygon;
777 polygon += std::make_pair( Vector(1.,0.,0.), 1);
778 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
779 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
780 SphericalPointDistribution::Polygon_t newpolygon =
781 SPD.get<6>();
782 SphericalPointDistribution::Polygon_t expected = newpolygon;
783 expected.pop_front(); // remove first point
784 expected.pop_front(); // remove second point
785 expected.pop_front(); // remove third point
786 SphericalPointDistribution::Polygon_t remaining =
787 SphericalPointDistribution::matchSphericalPointDistributions(
788 polygon,
789 newpolygon);
790 CPPUNIT_ASSERT_EQUAL( expected, remaining );
791 // also slightly perturbed
792 const double amplitude = 0.05;
793 perturbPolygon(polygon, amplitude);
794 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
795 }
796
797 // test with three points, full rotation
798 {
799 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
800 SphericalPointDistribution::WeightedPolygon_t polygon;
801 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
802 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
803 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
804 SphericalPointDistribution::Polygon_t newpolygon =
805 SPD.get<6>();
806 SphericalPointDistribution::Polygon_t expected = newpolygon;
807 expected.pop_front(); // remove first point
808 expected.pop_front(); // remove second point
809 expected.pop_front(); // remove third point
810 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
811 iter != expected.end(); ++iter)
812 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
813 SphericalPointDistribution::Polygon_t remaining =
814 SphericalPointDistribution::matchSphericalPointDistributions(
815 polygon,
816 newpolygon);
817 CPPUNIT_ASSERT_EQUAL( expected, remaining );
818 // also slightly perturbed
819 const double amplitude = 0.05;
820 perturbPolygon(polygon, amplitude);
821 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
822 }
823}
824
825/** UnitTest for matchSphericalPointDistributions() with seven points
826 */
827void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_7()
828{
829 SphericalPointDistribution SPD(1.);
830
831 // test with one point, matching trivially
832 {
833 SphericalPointDistribution::WeightedPolygon_t polygon;
834 polygon += std::make_pair( Vector(1.,0.,0.), 1);
835 SphericalPointDistribution::Polygon_t newpolygon =
836 SPD.get<7>();
837 SphericalPointDistribution::Polygon_t expected = newpolygon;
838 expected.pop_front(); // remove first point
839 SphericalPointDistribution::Polygon_t remaining =
840 SphericalPointDistribution::matchSphericalPointDistributions(
841 polygon,
842 newpolygon);
843 CPPUNIT_ASSERT_EQUAL( expected, remaining );
844 }
845
846 // test with one point, just a flip of axis
847 {
848 SphericalPointDistribution::WeightedPolygon_t polygon;
849 polygon += std::make_pair( Vector(0.,1.,0.), 1);
850 SphericalPointDistribution::Polygon_t newpolygon =
851 SPD.get<7>();
852 SphericalPointDistribution::Polygon_t expected = newpolygon;
853 expected.pop_front(); // remove first point
854 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
855 iter != expected.end(); ++iter) {
856 std::swap((*iter)[0], (*iter)[1]);
857 (*iter)[0] *= -1.;
858 }
859 SphericalPointDistribution::Polygon_t remaining =
860 SphericalPointDistribution::matchSphericalPointDistributions(
861 polygon,
862 newpolygon);
863 CPPUNIT_ASSERT_EQUAL( expected, remaining );
864 }
865
866 // test with two points, matching trivially
867 {
868 SphericalPointDistribution::WeightedPolygon_t polygon;
869 polygon += std::make_pair( Vector(1.,0.,0.), 1);
870 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
871 SphericalPointDistribution::Polygon_t newpolygon =
872 SPD.get<7>();
873 SphericalPointDistribution::Polygon_t expected = newpolygon;
874 expected.pop_front(); // remove first point
875 expected.pop_front(); // remove second point
876 SphericalPointDistribution::Polygon_t remaining =
877 SphericalPointDistribution::matchSphericalPointDistributions(
878 polygon,
879 newpolygon);
880 CPPUNIT_ASSERT_EQUAL( expected, remaining );
881 // also slightly perturbed
882 const double amplitude = 0.05;
883 perturbPolygon(polygon, amplitude);
884 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
885 }
886
887 // test with two points, full rotation
888 {
889 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
890 SphericalPointDistribution::WeightedPolygon_t polygon;
891 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
892 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
893 SphericalPointDistribution::Polygon_t newpolygon =
894 SPD.get<7>();
895 SphericalPointDistribution::Polygon_t expected = newpolygon;
896 expected.pop_front(); // remove first point
897 expected.pop_front(); // remove second point
898 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
899 iter != expected.end(); ++iter)
900 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
901 SphericalPointDistribution::Polygon_t remaining =
902 SphericalPointDistribution::matchSphericalPointDistributions(
903 polygon,
904 newpolygon);
905 // the five remaining points sit on a plane that may have been rotated arbitrarily
906 // so we cannot simply check for equality between expected and remaining
907 // hence, we just check that they are orthogonal to the first two points
908 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
909 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
910 fixiter != polygon.end(); ++fixiter) {
911 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
912 iter != remaining.end(); ++iter) {
913 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
914 }
915 }
916 }
917
918 // test with three points, matching trivially
919 {
920 SphericalPointDistribution::WeightedPolygon_t polygon;
921 polygon += std::make_pair( Vector(1.,0.,0.), 1);
922 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
923 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
924 SphericalPointDistribution::Polygon_t newpolygon =
925 SPD.get<7>();
926 SphericalPointDistribution::Polygon_t expected = newpolygon;
927 expected.pop_front(); // remove first point
928 expected.pop_front(); // remove second point
929 expected.pop_front(); // remove third point
930 SphericalPointDistribution::Polygon_t remaining =
931 SphericalPointDistribution::matchSphericalPointDistributions(
932 polygon,
933 newpolygon);
934 CPPUNIT_ASSERT_EQUAL( expected, remaining );
935 // also slightly perturbed
936 const double amplitude = 0.05;
937 perturbPolygon(polygon, amplitude);
938 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
939 }
940
941 // test with three points, full rotation
942 {
943 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
944 SphericalPointDistribution::WeightedPolygon_t polygon;
945 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
946 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
947 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
948 SphericalPointDistribution::Polygon_t newpolygon =
949 SPD.get<7>();
950 SphericalPointDistribution::Polygon_t expected = newpolygon;
951 expected.pop_front(); // remove first point
952 expected.pop_front(); // remove second point
953 expected.pop_front(); // remove third point
954 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
955 iter != expected.end(); ++iter)
956 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
957 SphericalPointDistribution::Polygon_t remaining =
958 SphericalPointDistribution::matchSphericalPointDistributions(
959 polygon,
960 newpolygon);
961 CPPUNIT_ASSERT_EQUAL( expected, remaining );
962 // also slightly perturbed
963 const double amplitude = 0.05;
964 perturbPolygon(polygon, amplitude);
965 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
966 }
967}
968
969/** UnitTest for matchSphericalPointDistributions() with eight points
970 */
971void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_8()
972{
973 SphericalPointDistribution SPD(1.);
974
975 // test with one point, matching trivially
976 {
977 SphericalPointDistribution::WeightedPolygon_t polygon;
978 polygon += std::make_pair( Vector(1.,0.,0.), 1);
979 SphericalPointDistribution::Polygon_t newpolygon =
980 SPD.get<8>();
981 SphericalPointDistribution::Polygon_t expected = newpolygon;
982 expected.pop_front(); // remove first point
983 SphericalPointDistribution::Polygon_t remaining =
984 SphericalPointDistribution::matchSphericalPointDistributions(
985 polygon,
986 newpolygon);
987 CPPUNIT_ASSERT_EQUAL( expected, remaining );
988 }
989
990 // test with one point, just a flip of axis
991 {
992 SphericalPointDistribution::WeightedPolygon_t polygon;
993 polygon += std::make_pair( Vector(0.,1.,0.), 1);
994 SphericalPointDistribution::Polygon_t newpolygon =
995 SPD.get<8>();
996 SphericalPointDistribution::Polygon_t expected = newpolygon;
997 expected.pop_front(); // remove first point
998 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
999 iter != expected.end(); ++iter) {
1000 std::swap((*iter)[0], (*iter)[1]);
1001 (*iter)[0] *= -1.;
1002 }
1003 SphericalPointDistribution::Polygon_t remaining =
1004 SphericalPointDistribution::matchSphericalPointDistributions(
1005 polygon,
1006 newpolygon);
1007 CPPUNIT_ASSERT_EQUAL( expected, remaining );
1008 }
1009
1010 // test with two points, matching trivially
1011 {
1012 SphericalPointDistribution::WeightedPolygon_t polygon;
1013 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1014 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
1015 SphericalPointDistribution::Polygon_t newpolygon =
1016 SPD.get<8>();
1017 SphericalPointDistribution::Polygon_t expected = newpolygon;
1018 expected.pop_front(); // remove first point
1019 expected.pop_front(); // remove second point
1020 SphericalPointDistribution::Polygon_t remaining =
1021 SphericalPointDistribution::matchSphericalPointDistributions(
1022 polygon,
1023 newpolygon);
1024 CPPUNIT_ASSERT_EQUAL( expected, remaining );
1025 // also slightly perturbed
1026 const double amplitude = 0.05;
1027 perturbPolygon(polygon, amplitude);
1028 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1029 }
1030
1031 // test with two points, full rotation
1032 {
1033 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1034 SphericalPointDistribution::WeightedPolygon_t polygon;
1035 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1036 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
1037 SphericalPointDistribution::Polygon_t newpolygon =
1038 SPD.get<8>();
1039 SphericalPointDistribution::Polygon_t expected = newpolygon;
1040 expected.pop_front(); // remove first point
1041 expected.pop_front(); // remove second point
1042 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1043 iter != expected.end(); ++iter)
1044 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1045 SphericalPointDistribution::Polygon_t remaining =
1046 SphericalPointDistribution::matchSphericalPointDistributions(
1047 polygon,
1048 newpolygon);
1049 // the six remaining points sit on two planes that may have been rotated arbitrarily
1050 // so we cannot simply check for equality between expected and remaining
1051 // hence, we just check that they are orthogonal to the first two points
1052 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
1053 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
1054 fixiter != polygon.end(); ++fixiter) {
1055 SphericalPointDistribution::Polygon_t::const_iterator expectiter = expected.begin();
1056 SphericalPointDistribution::Polygon_t::const_iterator remainiter = remaining.begin();
1057 for (;remainiter != remaining.end(); ++expectiter, ++remainiter) {
1058 // check that points in expected/remaining have same angle to the given ones
1059// CPPUNIT_ASSERT_EQUAL( (*expectiter).Angle(*fixiter), (*remainiter).Angle(*fixiter) );
1060 CPPUNIT_ASSERT( fabs( (*expectiter).Angle(fixiter->first) - (*remainiter).Angle(fixiter->first) )
1061 < std::numeric_limits<double>::epsilon()*1e4 );
1062 }
1063 }
1064 }
1065
1066 // test with three points, matching trivially
1067 {
1068 SphericalPointDistribution::WeightedPolygon_t polygon;
1069 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1070 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
1071 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 1);
1072 SphericalPointDistribution::Polygon_t newpolygon =
1073 SPD.get<8>();
1074 SphericalPointDistribution::Polygon_t expected = newpolygon;
1075 expected.pop_front(); // remove first point
1076 expected.pop_front(); // remove second point
1077 expected.pop_front(); // remove third point
1078 SphericalPointDistribution::Polygon_t remaining =
1079 SphericalPointDistribution::matchSphericalPointDistributions(
1080 polygon,
1081 newpolygon);
1082 CPPUNIT_ASSERT_EQUAL( expected, remaining );
1083 // also slightly perturbed
1084 const double amplitude = 0.05;
1085 perturbPolygon(polygon, amplitude);
1086 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1087 }
1088
1089 // test with three points, full rotation
1090 {
1091 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1092 SphericalPointDistribution::WeightedPolygon_t polygon;
1093 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1094 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
1095 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 47.6/180*M_PI), 1);
1096 SphericalPointDistribution::Polygon_t newpolygon =
1097 SPD.get<8>();
1098 SphericalPointDistribution::Polygon_t expected = newpolygon;
1099 expected.pop_front(); // remove first point
1100 expected.pop_front(); // remove second point
1101 expected.pop_front(); // remove third point
1102 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1103 iter != expected.end(); ++iter)
1104 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1105 SphericalPointDistribution::Polygon_t remaining =
1106 SphericalPointDistribution::matchSphericalPointDistributions(
1107 polygon,
1108 newpolygon);
1109 CPPUNIT_ASSERT_EQUAL( expected, remaining );
1110 // also slightly perturbed
1111 const double amplitude = 0.05;
1112 perturbPolygon(polygon, amplitude);
1113 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1114 }
1115}
Note: See TracBrowser for help on using the repository browser.