source: src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp@ 2d8c4e

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 2d8c4e was 6393ff, checked in by Frederik Heber <heber@…>, 9 years ago

Added getConnections() to SphericalPointDistribution.

  • we use tesselation in order to extract the connection information between nearest neighboring points from the BoundaryLines of the tesselation. The triangles are ideal as they assure that no point lies within a triangle, hence all these points may be safely combined.
  • functions reside in extra module as with get().
  • added extensive unit tests.
  • Property mode set to 100644
File size: 62.2 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 <algorithm>
48#include <boost/assign.hpp>
49#include <boost/math/quaternion.hpp>
50
51#include "CodePatterns/Assert.hpp"
52#include "CodePatterns/Log.hpp"
53
54#include "LinearAlgebra/Line.hpp"
55
56#include "Atom/TesselPoint.hpp"
57#include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
58#include "LinkedCell/linkedcell.hpp"
59#include "LinkedCell/PointCloudAdaptor.hpp"
60#include "Tesselation/BoundaryLineSet.hpp"
61#include "Tesselation/tesselation.hpp"
62
63#ifdef HAVE_TESTRUNNER
64#include "UnitTestMain.hpp"
65#endif /*HAVE_TESTRUNNER*/
66
67using namespace boost::assign;
68
69/********************************************** Test classes **************************************/
70
71// Registers the fixture into the 'registry'
72CPPUNIT_TEST_SUITE_REGISTRATION( SphericalPointDistributionTest );
73
74/** due to root-taking in function we only have limited numerical precision,
75 * basically half of the double range.
76 */
77const double CenterAccuracy = sqrt(std::numeric_limits<double>::epsilon()*1e2);
78
79void SphericalPointDistributionTest::setUp()
80{
81 // failing asserts should be thrown
82 ASSERT_DO(Assert::Throw);
83
84 setVerbosity(2);
85}
86
87
88void SphericalPointDistributionTest::tearDown()
89{
90}
91
92/** UnitTest for calculateCenterOfMinimumDistance()
93 */
94void SphericalPointDistributionTest::calculateCenterOfMinimumDistanceTest()
95{
96 // single point
97 {
98 SphericalPointDistribution::VectorArray_t points;
99 points +=
100 Vector(1.,0.,0.);
101 SphericalPointDistribution::IndexList_t indices;
102 indices += 0;
103 const Vector expected = points[0];
104 const Vector center =
105 SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
106// std::cout << " Difference is " << (expected - center).Norm() << std::endl;
107// CPPUNIT_ASSERT_EQUAL ( expected, center );
108 CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
109 }
110
111 // single point, rotated
112 {
113 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
114 SphericalPointDistribution::VectorArray_t points;
115 points +=
116 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI);
117 SphericalPointDistribution::IndexList_t indices;
118 indices += 0;
119 const Vector expected = points[0];
120 const Vector center =
121 SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
122// std::cout << " Difference is " << (expected - center).Norm() << std::endl;
123// CPPUNIT_ASSERT_EQUAL ( expected, center );
124 CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
125 }
126
127 // two points
128 {
129 SphericalPointDistribution::VectorArray_t points;
130 points +=
131 Vector(1.,0.,0.),
132 Vector(0.,1.,0.);
133 SphericalPointDistribution::IndexList_t indices;
134 indices += 0,1;
135 const Vector expected = Vector(M_SQRT1_2,M_SQRT1_2,0.);
136 const Vector center =
137 SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
138// std::cout << " Difference is " << (expected - center).Norm() << std::endl;
139// CPPUNIT_ASSERT_EQUAL ( expected, center );
140 CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
141 }
142
143 // two points, rotated
144 {
145 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
146 SphericalPointDistribution::VectorArray_t points;
147 points +=
148 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
149 RotationAxis.rotateVector(Vector(0.,1.,0.), 47.6/180*M_PI);
150 SphericalPointDistribution::IndexList_t indices;
151 indices += 0,1;
152 const Vector expected = RotationAxis.rotateVector(Vector(M_SQRT1_2,M_SQRT1_2,0.), 47.6/180*M_PI);
153 const Vector center =
154 SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
155// std::cout << " Difference is " << (expected - center).Norm() << std::endl;
156// CPPUNIT_ASSERT_EQUAL ( expected, center );
157 CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
158 }
159
160 // three points in line
161 {
162 SphericalPointDistribution::VectorArray_t points;
163 points +=
164 Vector(1.,0.,0.),
165 Vector(0.,1.,0.),
166 Vector(-1.,0.,0.);
167 SphericalPointDistribution::IndexList_t indices;
168 indices += 0,1,2;
169 const Vector expected = points[1];
170 const Vector center =
171 SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
172// std::cout << " Difference is " << (expected - center).Norm() << std::endl;
173// CPPUNIT_ASSERT_EQUAL ( expected, center );
174 CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
175 }
176
177 // three points in line, rotated
178 {
179 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
180 SphericalPointDistribution::VectorArray_t points;
181 points +=
182 RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI),
183 RotationAxis.rotateVector(Vector(0.,1.,0.), 47.6/180*M_PI),
184 RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
185 SphericalPointDistribution::IndexList_t indices;
186 indices += 0,1,2;
187 const Vector expected = points[1];
188 const Vector center =
189 SphericalPointDistribution::calculateCenterOfMinimumDistance(points, indices);
190// std::cout << " Difference is " << (expected - center).Norm() << std::endl;
191// CPPUNIT_ASSERT_EQUAL ( expected, center );
192 CPPUNIT_ASSERT( expected.IsEqualTo(center, CenterAccuracy));
193 }
194}
195
196static
197bool areEqualToWithinBounds(
198 const SphericalPointDistribution::Polygon_t &_polygon,
199 const SphericalPointDistribution::Polygon_t &_otherpolygon,
200 double _amplitude
201 )
202{
203 // same size?
204 if (_polygon.size() != _otherpolygon.size())
205 return false;
206 // same points ? We just check witrh trivial mapping, nothing fancy ...
207 bool status = true;
208 SphericalPointDistribution::Polygon_t::const_iterator iter = _polygon.begin();
209 SphericalPointDistribution::Polygon_t::const_iterator otheriter = _otherpolygon.begin();
210 for (; iter != _polygon.end(); ++iter, ++otheriter) {
211 status &= (*iter).IsEqualTo(*otheriter, _amplitude);
212 }
213 return status;
214}
215
216/** UnitTest for areEqualToWithinBounds()
217 */
218void SphericalPointDistributionTest::areEqualToWithinBoundsTest()
219{
220 // test with no points
221 {
222 SphericalPointDistribution::Polygon_t polygon;
223 SphericalPointDistribution::Polygon_t expected = polygon;
224 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
225 }
226 // test with one point
227 {
228 SphericalPointDistribution::Polygon_t polygon;
229 polygon += Vector(1.,0.,0.);
230 SphericalPointDistribution::Polygon_t expected = polygon;
231 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
232 }
233 // test with two points
234 {
235 SphericalPointDistribution::Polygon_t polygon;
236 polygon += Vector(1.,0.,0.);
237 polygon += Vector(0.,1.,0.);
238 SphericalPointDistribution::Polygon_t expected = polygon;
239 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
240 }
241
242 // test with two points in different order: THIS GOES WRONG: We only check trivially
243 {
244 SphericalPointDistribution::Polygon_t polygon;
245 polygon += Vector(1.,0.,0.);
246 polygon += Vector(0.,1.,0.);
247 SphericalPointDistribution::Polygon_t expected;
248 expected += Vector(0.,1.,0.);
249 expected += Vector(1.,0.,0.);
250 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
251 }
252
253 // test with two different points
254 {
255 SphericalPointDistribution::Polygon_t polygon;
256 polygon += Vector(1.,0.,0.);
257 polygon += Vector(0.,1.,0.);
258 SphericalPointDistribution::Polygon_t expected;
259 expected += Vector(1.01,0.,0.);
260 expected += Vector(0.,1.,0.);
261 CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, 0.05) );
262 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.005) );
263 }
264
265 // test with different number of points
266 {
267 SphericalPointDistribution::Polygon_t polygon;
268 polygon += Vector(1.,0.,0.);
269 polygon += Vector(0.,1.,0.);
270 SphericalPointDistribution::Polygon_t expected;
271 expected += Vector(0.,1.,0.);
272 CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.05) );
273 }
274}
275
276/** UnitTest for getConnections()
277 */
278template <>
279void SphericalPointDistributionTest_assistant::getConnectionTest<0>()
280{
281 const int N=0;
282 SphericalPointDistribution SPD(1.);
283
284 // create empty adjacency
285 SphericalPointDistribution::adjacency_t adjacency;
286
287 // get the implemented connections
288 SphericalPointDistribution::adjacency_t expected =
289 SPD.getConnections<N>();
290
291 // and compare the two
292 CPPUNIT_ASSERT_EQUAL( expected, adjacency );
293}
294
295/** UnitTest for getConnections()
296 */
297template <>
298void SphericalPointDistributionTest_assistant::getConnectionTest<1>()
299{
300 const int N=1;
301 SphericalPointDistribution SPD(1.);
302
303 // create empty adjacency
304 SphericalPointDistribution::adjacency_t adjacency;
305
306 // get the implemented connections
307 SphericalPointDistribution::adjacency_t expected =
308 SPD.getConnections<N>();
309
310 // and compare the two
311 CPPUNIT_ASSERT_EQUAL( expected, adjacency );
312}
313
314/** UnitTest for getConnections()
315 */
316template <>
317void SphericalPointDistributionTest_assistant::getConnectionTest<2>()
318{
319 const int N=2;
320 SphericalPointDistribution SPD(1.);
321
322 // create empty adjacency
323 SphericalPointDistribution::adjacency_t adjacency;
324 adjacency +=
325 make_pair<
326 unsigned int,
327 SphericalPointDistribution::IndexSet_t >
328 (0, list_of<unsigned int>(1));
329 adjacency +=
330 make_pair<
331 unsigned int,
332 SphericalPointDistribution::IndexSet_t >
333 (1, list_of<unsigned int>(0));
334
335 // get the implemented connections
336 SphericalPointDistribution::adjacency_t expected =
337 SPD.getConnections<N>();
338
339 // and compare the two
340 CPPUNIT_ASSERT_EQUAL( expected, adjacency );
341}
342
343void perturbPolygon(
344 SphericalPointDistribution::WeightedPolygon_t &_polygon,
345 double _amplitude
346 )
347{
348 for (SphericalPointDistribution::WeightedPolygon_t::iterator iter = _polygon.begin();
349 iter != _polygon.end(); ++iter) {
350 Vector perturber;
351 perturber.GetOneNormalVector(iter->first);
352 perturber.Scale(_amplitude);
353 iter->first = iter->first + perturber;
354 (iter->first).Normalize();
355 }
356}
357
358/** UnitTest for joinPoints()
359 */
360void SphericalPointDistributionTest::joinPointsTest()
361{
362 // test with simple configuration of three points
363 {
364 SphericalPointDistribution::Polygon_t newpolygon;
365 newpolygon += Vector(1.,0.,0.);
366 newpolygon += Vector(0.,1.,0.);
367 newpolygon += Vector(0.,0.,1.);
368 SphericalPointDistribution::Polygon_t expectedpolygon = newpolygon;
369 SphericalPointDistribution::IndexTupleList_t matching;
370 matching += SphericalPointDistribution::IndexList_t(1,0);
371 matching += SphericalPointDistribution::IndexList_t(1,1);
372 matching += SphericalPointDistribution::IndexList_t(1,2);
373 SphericalPointDistribution::IndexList_t IndexList =
374 SphericalPointDistribution::joinPoints(
375 newpolygon,
376 SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
377 matching);
378 SphericalPointDistribution::IndexList_t expected;
379 expected += 0,1,2;
380 CPPUNIT_ASSERT_EQUAL( expected, IndexList );
381 CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
382 }
383
384 // test with simple configuration of three points, only two are picked
385 {
386 SphericalPointDistribution::Polygon_t newpolygon;
387 newpolygon += Vector(1.,0.,0.);
388 newpolygon += Vector(0.,1.,0.);
389 newpolygon += Vector(0.,0.,1.);
390 SphericalPointDistribution::Polygon_t expectedpolygon = newpolygon;
391 SphericalPointDistribution::IndexTupleList_t matching;
392 matching += SphericalPointDistribution::IndexList_t(1,1);
393 matching += SphericalPointDistribution::IndexList_t(1,2);
394 SphericalPointDistribution::IndexList_t IndexList =
395 SphericalPointDistribution::joinPoints(
396 newpolygon,
397 SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
398 matching);
399 SphericalPointDistribution::IndexList_t expected;
400 expected += 1,2;
401 CPPUNIT_ASSERT_EQUAL( expected, IndexList );
402 CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
403 }
404
405 // test with simple configuration of three points, two are joined
406 {
407 SphericalPointDistribution::Polygon_t newpolygon;
408 newpolygon += Vector(1.,0.,0.);
409 newpolygon += Vector(0.,1.,0.);
410 newpolygon += Vector(0.,0.,1.);
411 SphericalPointDistribution::Polygon_t expectedpolygon;
412 expectedpolygon += Vector(1.,0.,0.);
413 expectedpolygon += Vector(0.,M_SQRT1_2,M_SQRT1_2);
414 SphericalPointDistribution::IndexTupleList_t matching;
415 SphericalPointDistribution::IndexList_t joined;
416 joined += 1,2;
417 matching += SphericalPointDistribution::IndexList_t(1,0);
418 matching += joined;
419 SphericalPointDistribution::IndexList_t IndexList =
420 SphericalPointDistribution::joinPoints(
421 newpolygon,
422 SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
423 matching);
424 SphericalPointDistribution::IndexList_t expected;
425 expected += 0,1;
426 CPPUNIT_ASSERT_EQUAL( expected, IndexList );
427 CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
428 }
429
430 // test with simple configuration of six points, two are joined, jumbled indices
431 {
432 SphericalPointDistribution::Polygon_t newpolygon;
433 newpolygon += Vector(1.,0.,1.);
434 newpolygon += Vector(1.,0.,0.);
435 newpolygon += Vector(1.,1.,0.);
436 newpolygon += Vector(0.,1.,0.);
437 newpolygon += Vector(0.,0.,1.);
438 newpolygon += Vector(1.,0.,1.);
439 SphericalPointDistribution::Polygon_t expectedpolygon;
440 expectedpolygon += Vector(1.,0.,1.);
441 expectedpolygon += Vector(1.,0.,0.);
442 expectedpolygon += Vector(1.,1.,0.);
443 expectedpolygon += Vector(1.,0.,1.);
444 expectedpolygon += Vector(0.,M_SQRT1_2,M_SQRT1_2); // new centers go last
445 SphericalPointDistribution::IndexTupleList_t matching;
446 SphericalPointDistribution::IndexList_t joined;
447 joined += 3,4;
448 matching += SphericalPointDistribution::IndexList_t(1,1);
449 matching += joined;
450 SphericalPointDistribution::IndexList_t IndexList =
451 SphericalPointDistribution::joinPoints(
452 newpolygon,
453 SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
454 matching);
455 SphericalPointDistribution::IndexList_t expected;
456 expected += 1,4;
457 CPPUNIT_ASSERT_EQUAL( expected, IndexList );
458 CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
459 }
460}
461
462/** UnitTest for matchSphericalPointDistributions() with two points
463 */
464void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_2()
465{
466 SphericalPointDistribution SPD(1.);
467 // test with one point, matching trivially
468 {
469 SphericalPointDistribution::WeightedPolygon_t polygon;
470 polygon += std::make_pair(Vector(1.,0.,0.), 1);
471 SphericalPointDistribution::Polygon_t newpolygon =
472 SPD.get<2>();
473 SphericalPointDistribution::Polygon_t expected;
474 expected += Vector(-1.,0.,0.);
475 SphericalPointDistribution::Polygon_t remaining =
476 SphericalPointDistribution::matchSphericalPointDistributions(
477 polygon,
478 newpolygon);
479// CPPUNIT_ASSERT_EQUAL( expected, remaining );
480 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
481 }
482
483 // test with one point, just a flip of axis
484 {
485 SphericalPointDistribution::WeightedPolygon_t polygon;
486 polygon += std::make_pair( Vector(0.,1.,0.), 1);
487 SphericalPointDistribution::Polygon_t newpolygon =
488 SPD.get<2>();
489 SphericalPointDistribution::Polygon_t expected;
490 expected += Vector(0.,-1.,0.);
491 SphericalPointDistribution::Polygon_t remaining =
492 SphericalPointDistribution::matchSphericalPointDistributions(
493 polygon,
494 newpolygon);
495// CPPUNIT_ASSERT_EQUAL( expected, remaining );
496 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
497 }
498
499 // test with one point, just a flip to another axis
500 {
501 SphericalPointDistribution::WeightedPolygon_t polygon;
502 polygon += std::make_pair( Vector(0.,0.,-1.), 1);
503 SphericalPointDistribution::Polygon_t newpolygon =
504 SPD.get<2>();
505 SphericalPointDistribution::Polygon_t expected;
506 expected += Vector(0.,0.,1.);
507 SphericalPointDistribution::Polygon_t remaining =
508 SphericalPointDistribution::matchSphericalPointDistributions(
509 polygon,
510 newpolygon);
511// CPPUNIT_ASSERT_EQUAL( expected, remaining );
512 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
513 }
514
515 // test with one point, full rotation
516 {
517 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
518 SphericalPointDistribution::WeightedPolygon_t polygon;
519 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
520 SphericalPointDistribution::Polygon_t newpolygon =
521 SPD.get<2>();
522 SphericalPointDistribution::Polygon_t expected;
523 expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
524 SphericalPointDistribution::Polygon_t remaining =
525 SphericalPointDistribution::matchSphericalPointDistributions(
526 polygon,
527 newpolygon);
528// CPPUNIT_ASSERT_EQUAL( expected, remaining );
529 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
530 }
531}
532
533/** UnitTest for matchSphericalPointDistributions() with three points
534 */
535void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_3()
536{
537 SphericalPointDistribution SPD(1.);
538
539 // test with one point, matching trivially
540 {
541 SphericalPointDistribution::WeightedPolygon_t polygon;
542 polygon += std::make_pair( Vector(1.,0.,0.), 1);
543 SphericalPointDistribution::Polygon_t newpolygon =
544 SPD.get<3>();
545 SphericalPointDistribution::Polygon_t expected = newpolygon;
546 expected.pop_front(); // remove first point
547 SphericalPointDistribution::Polygon_t remaining =
548 SphericalPointDistribution::matchSphericalPointDistributions(
549 polygon,
550 newpolygon);
551// CPPUNIT_ASSERT_EQUAL( expected, remaining );
552 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
553 }
554
555 // test with one point, just a flip of x and y axis
556 {
557 SphericalPointDistribution::WeightedPolygon_t polygon;
558 polygon += std::make_pair( Vector(0.,1.,0.), 1);
559 SphericalPointDistribution::Polygon_t newpolygon =
560 SPD.get<3>();
561 SphericalPointDistribution::Polygon_t expected = newpolygon;
562 expected.pop_front(); // remove first point
563 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
564 iter != expected.end(); ++iter) {
565 std::swap((*iter)[0], (*iter)[1]);
566 (*iter)[0] *= -1.;
567 }
568 SphericalPointDistribution::Polygon_t remaining =
569 SphericalPointDistribution::matchSphericalPointDistributions(
570 polygon,
571 newpolygon);
572// CPPUNIT_ASSERT_EQUAL( expected, remaining );
573 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
574 }
575
576 // test with two points, matching trivially
577 {
578 SphericalPointDistribution::WeightedPolygon_t polygon;
579 polygon += std::make_pair( Vector(1.,0.,0.), 1);
580 polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
581 SphericalPointDistribution::Polygon_t newpolygon =
582 SPD.get<3>();
583 SphericalPointDistribution::Polygon_t expected = newpolygon;
584 expected.pop_front(); // remove first point
585 expected.pop_front(); // remove second point
586 SphericalPointDistribution::Polygon_t remaining =
587 SphericalPointDistribution::matchSphericalPointDistributions(
588 polygon,
589 newpolygon);
590// CPPUNIT_ASSERT_EQUAL( expected, remaining );
591 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
592 // also slightly perturbed
593 const double amplitude = 0.05;
594 perturbPolygon(polygon, amplitude);
595 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
596 }
597
598 // test with two points, full rotation
599 {
600 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
601 SphericalPointDistribution::WeightedPolygon_t polygon;
602 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
603 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
604 SphericalPointDistribution::Polygon_t newpolygon =
605 SPD.get<3>();
606 SphericalPointDistribution::Polygon_t expected = newpolygon;
607 expected.pop_front(); // remove first point
608 expected.pop_front(); // remove second point
609 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
610 iter != expected.end(); ++iter)
611 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
612 SphericalPointDistribution::Polygon_t remaining =
613 SphericalPointDistribution::matchSphericalPointDistributions(
614 polygon,
615 newpolygon);
616// CPPUNIT_ASSERT_EQUAL( expected, remaining );
617 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
618 // also slightly perturbed
619 const double amplitude = 0.05;
620 perturbPolygon(polygon, amplitude);
621 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
622 }
623
624 // test with three points, matching trivially
625 {
626 SphericalPointDistribution::WeightedPolygon_t polygon;
627 polygon += std::make_pair( Vector(1.,0.,0.), 1);
628 polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
629 polygon += std::make_pair( Vector(-0.5, -sqrt(3)*0.5,0.), 1);
630 SphericalPointDistribution::Polygon_t newpolygon =
631 SPD.get<3>();
632 SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
633 SphericalPointDistribution::Polygon_t remaining =
634 SphericalPointDistribution::matchSphericalPointDistributions(
635 polygon,
636 newpolygon);
637// CPPUNIT_ASSERT_EQUAL( expected, remaining );
638 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
639 // also slightly perturbed
640 const double amplitude = 0.05;
641 perturbPolygon(polygon, amplitude);
642 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
643 }
644
645
646 // test with three points, full rotation
647 {
648 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
649 SphericalPointDistribution::WeightedPolygon_t polygon;
650 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
651 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
652 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, -sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
653 SphericalPointDistribution::Polygon_t newpolygon =
654 SPD.get<3>();
655 SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
656 SphericalPointDistribution::Polygon_t remaining =
657 SphericalPointDistribution::matchSphericalPointDistributions(
658 polygon,
659 newpolygon);
660// CPPUNIT_ASSERT_EQUAL( expected, remaining );
661 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
662 // also slightly perturbed
663 const double amplitude = 0.05;
664 perturbPolygon(polygon, amplitude);
665 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
666 }
667}
668
669/** UnitTest for matchSphericalPointDistributions() with four points
670 */
671void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_4()
672{
673 SphericalPointDistribution SPD(1.);
674
675 // test with one point, matching trivially
676 {
677 SphericalPointDistribution::WeightedPolygon_t polygon;
678 polygon += std::make_pair( Vector(1.,0.,0.), 1);
679 SphericalPointDistribution::Polygon_t newpolygon =
680 SPD.get<4>();
681 SphericalPointDistribution::Polygon_t expected = newpolygon;
682 expected.pop_front(); // remove first point
683 SphericalPointDistribution::Polygon_t remaining =
684 SphericalPointDistribution::matchSphericalPointDistributions(
685 polygon,
686 newpolygon);
687 // CPPUNIT_ASSERT_EQUAL( expected, remaining );
688 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
689 }
690
691 // test with one point, just a flip of axis
692 {
693 SphericalPointDistribution::WeightedPolygon_t polygon;
694 polygon += std::make_pair( Vector(0.,1.,0.), 1);
695 SphericalPointDistribution::Polygon_t newpolygon =
696 SPD.get<4>();
697 SphericalPointDistribution::Polygon_t expected = newpolygon;
698 expected.pop_front(); // remove first point
699 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
700 iter != expected.end(); ++iter) {
701 std::swap((*iter)[0], (*iter)[1]);
702 (*iter)[0] *= -1.;
703 }
704 SphericalPointDistribution::Polygon_t remaining =
705 SphericalPointDistribution::matchSphericalPointDistributions(
706 polygon,
707 newpolygon);
708// CPPUNIT_ASSERT_EQUAL( expected, remaining );
709 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
710 }
711
712 // test with two points, matching trivially
713 {
714 SphericalPointDistribution::WeightedPolygon_t polygon;
715 polygon += std::make_pair( Vector(1.,0.,0.), 1);
716 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
717 SphericalPointDistribution::Polygon_t newpolygon =
718 SPD.get<4>();
719 SphericalPointDistribution::Polygon_t expected = newpolygon;
720 expected.pop_front(); // remove first point
721 expected.pop_front(); // remove second point
722 SphericalPointDistribution::Polygon_t remaining =
723 SphericalPointDistribution::matchSphericalPointDistributions(
724 polygon,
725 newpolygon);
726// CPPUNIT_ASSERT_EQUAL( expected, remaining );
727 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
728 // also slightly perturbed
729 const double amplitude = 0.05;
730 perturbPolygon(polygon, amplitude);
731 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
732 }
733
734 // test with two points, matching trivially, also with slightly perturbed
735 {
736 SphericalPointDistribution::WeightedPolygon_t polygon;
737 polygon += std::make_pair( Vector(1.,0.,0.), 1);
738 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
739 SphericalPointDistribution::Polygon_t newpolygon =
740 SPD.get<4>();
741 SphericalPointDistribution::Polygon_t expected = newpolygon;
742 expected.pop_front(); // remove first point
743 expected.pop_front(); // remove second point
744 SphericalPointDistribution::Polygon_t remaining =
745 SphericalPointDistribution::matchSphericalPointDistributions(
746 polygon,
747 newpolygon);
748// CPPUNIT_ASSERT_EQUAL( expected, remaining );
749 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
750 // also slightly perturbed
751 const double amplitude = 0.05;
752 perturbPolygon(polygon, amplitude);
753 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
754 }
755
756 // test with two points, full rotation
757 {
758 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
759 SphericalPointDistribution::WeightedPolygon_t polygon;
760 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
761 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
762 SphericalPointDistribution::Polygon_t newpolygon =
763 SPD.get<4>();
764 SphericalPointDistribution::Polygon_t expected = newpolygon;
765 expected.pop_front(); // remove first point
766 expected.pop_front(); // remove second point
767 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
768 iter != expected.end(); ++iter)
769 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
770 SphericalPointDistribution::Polygon_t remaining =
771 SphericalPointDistribution::matchSphericalPointDistributions(
772 polygon,
773 newpolygon);
774// CPPUNIT_ASSERT_EQUAL( expected, remaining );
775 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
776 // also slightly perturbed
777 const double amplitude = 0.05;
778 perturbPolygon(polygon, amplitude);
779 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
780 }
781
782 // test with three points, matching trivially
783 {
784 SphericalPointDistribution::WeightedPolygon_t polygon;
785 polygon += std::make_pair( Vector(1.,0.,0.), 1);
786 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
787 polygon += std::make_pair( Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 1);
788 SphericalPointDistribution::Polygon_t newpolygon =
789 SPD.get<4>();
790 SphericalPointDistribution::Polygon_t expected = newpolygon;
791 expected.pop_front(); // remove first point
792 expected.pop_front(); // remove second point
793 expected.pop_front(); // remove third point
794 SphericalPointDistribution::Polygon_t remaining =
795 SphericalPointDistribution::matchSphericalPointDistributions(
796 polygon,
797 newpolygon);
798// CPPUNIT_ASSERT_EQUAL( expected, remaining );
799 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
800 // also slightly perturbed
801 const double amplitude = 0.05;
802 perturbPolygon(polygon, amplitude);
803 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
804 }
805
806 // test with three points, full rotation
807 {
808 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
809 SphericalPointDistribution::WeightedPolygon_t polygon;
810 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
811 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
812 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 47.6/180*M_PI), 1);
813 SphericalPointDistribution::Polygon_t newpolygon =
814 SPD.get<4>();
815 SphericalPointDistribution::Polygon_t expected = newpolygon;
816 expected.pop_front(); // remove first point
817 expected.pop_front(); // remove second point
818 expected.pop_front(); // remove third point
819 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
820 iter != expected.end(); ++iter)
821 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
822 SphericalPointDistribution::Polygon_t remaining =
823 SphericalPointDistribution::matchSphericalPointDistributions(
824 polygon,
825 newpolygon);
826// CPPUNIT_ASSERT_EQUAL( expected, remaining );
827 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
828 // also slightly perturbed
829 const double amplitude = 0.05;
830 perturbPolygon(polygon, amplitude);
831 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
832 }
833}
834
835/** UnitTest for matchSphericalPointDistributions() with four points and weights
836 * not all equal to one.
837 */
838void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_multiple()
839{
840 SphericalPointDistribution SPD(1.);
841
842 // test with four points: one point having weight of two
843 {
844 SphericalPointDistribution::WeightedPolygon_t polygon;
845 polygon += std::make_pair( Vector(1.,0.,0.), 2);
846 SphericalPointDistribution::Polygon_t newpolygon =
847 SPD.get<4>();
848 SphericalPointDistribution::Polygon_t expected;
849 expected += Vector(-0.5773502691896,-5.551115123126e-17,0.8164965809277);
850 expected += Vector(-0.5773502691896,-5.551115123126e-17,-0.8164965809277);
851 SphericalPointDistribution::Polygon_t remaining =
852 SphericalPointDistribution::matchSphericalPointDistributions(
853 polygon,
854 newpolygon);
855// std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
856// CPPUNIT_ASSERT_EQUAL( expected, remaining );
857 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
858 }
859
860 // test with five points: one point having weight of two
861 {
862 SphericalPointDistribution::WeightedPolygon_t polygon;
863 polygon += std::make_pair( Vector(1.,0.,0.), 2);
864 SphericalPointDistribution::Polygon_t newpolygon =
865 SPD.get<5>();
866 SphericalPointDistribution::Polygon_t expected;
867 expected += Vector(-0.7071067811865,0.7071067811865,0);
868 expected += Vector(-0.3535533905933,-0.3535533905933,0.8660254037844);
869 expected += Vector(-0.3535533905933,-0.3535533905933,-0.8660254037844);
870 SphericalPointDistribution::Polygon_t remaining =
871 SphericalPointDistribution::matchSphericalPointDistributions(
872 polygon,
873 newpolygon);
874// std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
875// CPPUNIT_ASSERT_EQUAL( expected, remaining );
876 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
877 }
878
879
880 // test with five points: one point having weight of two, one weight of one
881 {
882 SphericalPointDistribution::WeightedPolygon_t polygon;
883 polygon += std::make_pair( Vector(M_SQRT1_2,M_SQRT1_2,0.), 2);
884 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
885 SphericalPointDistribution::Polygon_t newpolygon =
886 SPD.get<5>();
887 SphericalPointDistribution::Polygon_t expected;
888 expected += Vector(0.3535533786708,-0.3535533955317,-0.8660254066357);
889 expected += Vector(0.3535534025157,-0.3535533856548,0.8660254009332);
890 SphericalPointDistribution::Polygon_t remaining =
891 SphericalPointDistribution::matchSphericalPointDistributions(
892 polygon,
893 newpolygon);
894// std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
895// CPPUNIT_ASSERT_EQUAL( expected, remaining );
896 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
897 }
898
899 // test with six points: two points each having weight of two
900 {
901 SphericalPointDistribution::WeightedPolygon_t polygon;
902 polygon += std::make_pair( Vector(M_SQRT1_2,-M_SQRT1_2,0.), 2);
903 polygon += std::make_pair( Vector(-M_SQRT1_2,M_SQRT1_2,0.), 2);
904 SphericalPointDistribution::Polygon_t newpolygon =
905 SPD.get<6>();
906 SphericalPointDistribution::Polygon_t expected;
907 expected += Vector(0.,0.,-1.);
908 expected += Vector(0.,0.,1.);
909 SphericalPointDistribution::Polygon_t remaining =
910 SphericalPointDistribution::matchSphericalPointDistributions(
911 polygon,
912 newpolygon);
913// std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
914// CPPUNIT_ASSERT_EQUAL( expected, remaining );
915 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
916 }
917}
918
919/** UnitTest for matchSphericalPointDistributions() with five points
920 */
921void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_5()
922{
923 SphericalPointDistribution SPD(1.);
924
925 // test with one point, matching trivially
926 {
927 SphericalPointDistribution::WeightedPolygon_t polygon;
928 polygon += std::make_pair( Vector(1.,0.,0.), 1);
929 SphericalPointDistribution::Polygon_t newpolygon =
930 SPD.get<5>();
931 SphericalPointDistribution::Polygon_t expected = newpolygon;
932 expected.pop_front(); // remove first point
933 SphericalPointDistribution::Polygon_t remaining =
934 SphericalPointDistribution::matchSphericalPointDistributions(
935 polygon,
936 newpolygon);
937// CPPUNIT_ASSERT_EQUAL( expected, remaining );
938 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
939 }
940
941 // test with one point, just a flip of axis
942 {
943 SphericalPointDistribution::WeightedPolygon_t polygon;
944 polygon += std::make_pair( Vector(0.,1.,0.), 1);
945 SphericalPointDistribution::Polygon_t newpolygon =
946 SPD.get<5>();
947 SphericalPointDistribution::Polygon_t expected = newpolygon;
948 expected.pop_front(); // remove first point
949 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
950 iter != expected.end(); ++iter) {
951 std::swap((*iter)[0], (*iter)[1]);
952 (*iter)[0] *= -1.;
953 }
954 SphericalPointDistribution::Polygon_t remaining =
955 SphericalPointDistribution::matchSphericalPointDistributions(
956 polygon,
957 newpolygon);
958// CPPUNIT_ASSERT_EQUAL( expected, remaining );
959 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
960 }
961
962 // test with two points, matching trivially
963 {
964 SphericalPointDistribution::WeightedPolygon_t polygon;
965 polygon += std::make_pair( Vector(1.,0.,0.), 1);
966 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
967 SphericalPointDistribution::Polygon_t newpolygon =
968 SPD.get<5>();
969 SphericalPointDistribution::Polygon_t expected = newpolygon;
970 expected.pop_front(); // remove first point
971 expected.pop_front(); // remove second point
972 SphericalPointDistribution::Polygon_t remaining =
973 SphericalPointDistribution::matchSphericalPointDistributions(
974 polygon,
975 newpolygon);
976// CPPUNIT_ASSERT_EQUAL( expected, remaining );
977 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
978 // also slightly perturbed
979 const double amplitude = 0.05;
980 perturbPolygon(polygon, amplitude);
981 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
982 }
983
984 // test with two points, full rotation
985 {
986 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
987 SphericalPointDistribution::WeightedPolygon_t polygon;
988 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180.*M_PI), 1);
989 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180.*M_PI), 1);
990 SphericalPointDistribution::Polygon_t newpolygon =
991 SPD.get<5>();
992 SphericalPointDistribution::Polygon_t expected = newpolygon;
993 expected.pop_front(); // remove first point
994 expected.pop_front(); // remove second point
995 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
996 iter != expected.end(); ++iter)
997 *iter = RotationAxis.rotateVector(*iter, 47.6/180.*M_PI);
998 SphericalPointDistribution::Polygon_t remaining =
999 SphericalPointDistribution::matchSphericalPointDistributions(
1000 polygon,
1001 newpolygon);
1002 // the three remaining points sit on a plane that may be rotated arbitrarily
1003 // so we cannot simply check for equality between expected and remaining
1004 // hence, we just check that they are orthogonal to the first two points
1005 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
1006 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
1007 fixiter != polygon.end(); ++fixiter) {
1008 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
1009 iter != remaining.end(); ++iter) {
1010 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
1011 }
1012 }
1013 }
1014
1015 // test with three points, matching trivially
1016 {
1017 SphericalPointDistribution::WeightedPolygon_t polygon;
1018 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1019 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
1020 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
1021 SphericalPointDistribution::Polygon_t newpolygon =
1022 SPD.get<5>();
1023 SphericalPointDistribution::Polygon_t expected = newpolygon;
1024 expected.pop_front(); // remove first point
1025 expected.pop_front(); // remove second point
1026 expected.pop_front(); // remove third point
1027 SphericalPointDistribution::Polygon_t remaining =
1028 SphericalPointDistribution::matchSphericalPointDistributions(
1029 polygon,
1030 newpolygon);
1031// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1032 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1033 // also slightly perturbed
1034 const double amplitude = 0.05;
1035 perturbPolygon(polygon, amplitude);
1036 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1037 }
1038
1039 // test with three points, full rotation
1040 {
1041 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1042 SphericalPointDistribution::WeightedPolygon_t polygon;
1043 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1044 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
1045 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
1046 SphericalPointDistribution::Polygon_t newpolygon =
1047 SPD.get<5>();
1048 SphericalPointDistribution::Polygon_t expected = newpolygon;
1049 expected.pop_front(); // remove first point
1050 expected.pop_front(); // remove second point
1051 expected.pop_front(); // remove third point
1052 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1053 iter != expected.end(); ++iter)
1054 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1055 SphericalPointDistribution::Polygon_t remaining =
1056 SphericalPointDistribution::matchSphericalPointDistributions(
1057 polygon,
1058 newpolygon);
1059// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1060 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1061 // also slightly perturbed
1062 const double amplitude = 0.05;
1063 perturbPolygon(polygon, amplitude);
1064 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1065 }
1066}
1067
1068/** UnitTest for matchSphericalPointDistributions() with six points
1069 */
1070void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_6()
1071{
1072 SphericalPointDistribution SPD(1.);
1073
1074 // test with one point, matching trivially
1075 {
1076 SphericalPointDistribution::WeightedPolygon_t polygon;
1077 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1078 SphericalPointDistribution::Polygon_t newpolygon =
1079 SPD.get<6>();
1080 SphericalPointDistribution::Polygon_t expected = newpolygon;
1081 expected.pop_front(); // remove first point
1082 SphericalPointDistribution::Polygon_t remaining =
1083 SphericalPointDistribution::matchSphericalPointDistributions(
1084 polygon,
1085 newpolygon);
1086// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1087 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1088 }
1089
1090 // test with one point, just a flip of axis
1091 {
1092 SphericalPointDistribution::WeightedPolygon_t polygon;
1093 polygon += std::make_pair( Vector(0.,1.,0.), 1);
1094 SphericalPointDistribution::Polygon_t newpolygon =
1095 SPD.get<6>();
1096 SphericalPointDistribution::Polygon_t expected = newpolygon;
1097 expected.pop_front(); // remove first point
1098 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1099 iter != expected.end(); ++iter) {
1100 std::swap((*iter)[0], (*iter)[1]);
1101 (*iter)[0] *= -1.;
1102 }
1103 SphericalPointDistribution::Polygon_t remaining =
1104 SphericalPointDistribution::matchSphericalPointDistributions(
1105 polygon,
1106 newpolygon);
1107// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1108 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1109 }
1110
1111 // test with two points, matching trivially
1112 {
1113 SphericalPointDistribution::WeightedPolygon_t polygon;
1114 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1115 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
1116 SphericalPointDistribution::Polygon_t newpolygon =
1117 SPD.get<6>();
1118 SphericalPointDistribution::Polygon_t expected = newpolygon;
1119 expected.pop_front(); // remove first point
1120 expected.pop_front(); // remove second spoint
1121 SphericalPointDistribution::Polygon_t remaining =
1122 SphericalPointDistribution::matchSphericalPointDistributions(
1123 polygon,
1124 newpolygon);
1125// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1126 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1127 // also slightly perturbed
1128 const double amplitude = 0.05;
1129 perturbPolygon(polygon, amplitude);
1130 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1131 }
1132
1133 // test with two points, full rotation
1134 {
1135 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1136 SphericalPointDistribution::WeightedPolygon_t polygon;
1137 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1138 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
1139 SphericalPointDistribution::Polygon_t newpolygon =
1140 SPD.get<6>();
1141 SphericalPointDistribution::Polygon_t expected = newpolygon;
1142 expected.pop_front(); // remove first point
1143 expected.pop_front(); // remove second spoint
1144 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1145 iter != expected.end(); ++iter)
1146 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1147 SphericalPointDistribution::Polygon_t remaining =
1148 SphericalPointDistribution::matchSphericalPointDistributions(
1149 polygon,
1150 newpolygon);
1151 // the four remaining points sit on a plane that may have been rotated arbitrarily
1152 // so we cannot simply check for equality between expected and remaining
1153 // hence, we just check that they are orthogonal to the first two points
1154 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
1155 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
1156 fixiter != polygon.end(); ++fixiter) {
1157 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
1158 iter != remaining.end(); ++iter) {
1159 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
1160 }
1161 }
1162 }
1163
1164 // test with three points, matching trivially
1165 {
1166 SphericalPointDistribution::WeightedPolygon_t polygon;
1167 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1168 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
1169 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
1170 SphericalPointDistribution::Polygon_t newpolygon =
1171 SPD.get<6>();
1172 SphericalPointDistribution::Polygon_t expected = newpolygon;
1173 expected.pop_front(); // remove first point
1174 expected.pop_front(); // remove second point
1175 expected.pop_front(); // remove third point
1176 SphericalPointDistribution::Polygon_t remaining =
1177 SphericalPointDistribution::matchSphericalPointDistributions(
1178 polygon,
1179 newpolygon);
1180// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1181 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1182 // also slightly perturbed
1183 const double amplitude = 0.05;
1184 perturbPolygon(polygon, amplitude);
1185 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1186 }
1187
1188 // test with three points, full rotation
1189 {
1190 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1191 SphericalPointDistribution::WeightedPolygon_t polygon;
1192 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1193 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
1194 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
1195 SphericalPointDistribution::Polygon_t newpolygon =
1196 SPD.get<6>();
1197 SphericalPointDistribution::Polygon_t expected = newpolygon;
1198 expected.pop_front(); // remove first point
1199 expected.pop_front(); // remove second point
1200 expected.pop_front(); // remove third point
1201 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1202 iter != expected.end(); ++iter)
1203 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1204 SphericalPointDistribution::Polygon_t remaining =
1205 SphericalPointDistribution::matchSphericalPointDistributions(
1206 polygon,
1207 newpolygon);
1208// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1209 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1210 // also slightly perturbed
1211 const double amplitude = 0.05;
1212 perturbPolygon(polygon, amplitude);
1213 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1214 }
1215}
1216
1217/** UnitTest for matchSphericalPointDistributions() with seven points
1218 */
1219void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_7()
1220{
1221 SphericalPointDistribution SPD(1.);
1222
1223 // test with one point, matching trivially
1224 {
1225 SphericalPointDistribution::WeightedPolygon_t polygon;
1226 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1227 SphericalPointDistribution::Polygon_t newpolygon =
1228 SPD.get<7>();
1229 SphericalPointDistribution::Polygon_t expected = newpolygon;
1230 expected.pop_front(); // remove first point
1231 SphericalPointDistribution::Polygon_t remaining =
1232 SphericalPointDistribution::matchSphericalPointDistributions(
1233 polygon,
1234 newpolygon);
1235// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1236 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1237 }
1238
1239 // test with one point, just a flip of axis
1240 {
1241 SphericalPointDistribution::WeightedPolygon_t polygon;
1242 polygon += std::make_pair( Vector(0.,1.,0.), 1);
1243 SphericalPointDistribution::Polygon_t newpolygon =
1244 SPD.get<7>();
1245 SphericalPointDistribution::Polygon_t expected = newpolygon;
1246 expected.pop_front(); // remove first point
1247 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1248 iter != expected.end(); ++iter) {
1249 std::swap((*iter)[0], (*iter)[1]);
1250 (*iter)[0] *= -1.;
1251 }
1252 SphericalPointDistribution::Polygon_t remaining =
1253 SphericalPointDistribution::matchSphericalPointDistributions(
1254 polygon,
1255 newpolygon);
1256// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1257 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1258 }
1259
1260 // test with two points, matching trivially
1261 {
1262 SphericalPointDistribution::WeightedPolygon_t polygon;
1263 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1264 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
1265 SphericalPointDistribution::Polygon_t newpolygon =
1266 SPD.get<7>();
1267 SphericalPointDistribution::Polygon_t expected = newpolygon;
1268 expected.pop_front(); // remove first point
1269 expected.pop_front(); // remove second point
1270 SphericalPointDistribution::Polygon_t remaining =
1271 SphericalPointDistribution::matchSphericalPointDistributions(
1272 polygon,
1273 newpolygon);
1274// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1275 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1276 // also slightly perturbed
1277 const double amplitude = 0.05;
1278 perturbPolygon(polygon, amplitude);
1279 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1280 }
1281
1282 // test with two points, full rotation
1283 {
1284 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1285 SphericalPointDistribution::WeightedPolygon_t polygon;
1286 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1287 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
1288 SphericalPointDistribution::Polygon_t newpolygon =
1289 SPD.get<7>();
1290 SphericalPointDistribution::Polygon_t expected = newpolygon;
1291 expected.pop_front(); // remove first point
1292 expected.pop_front(); // remove second point
1293 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1294 iter != expected.end(); ++iter)
1295 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1296 SphericalPointDistribution::Polygon_t remaining =
1297 SphericalPointDistribution::matchSphericalPointDistributions(
1298 polygon,
1299 newpolygon);
1300 // the five remaining points sit on a plane that may have been rotated arbitrarily
1301 // so we cannot simply check for equality between expected and remaining
1302 // hence, we just check that they are orthogonal to the first two points
1303 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
1304 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
1305 fixiter != polygon.end(); ++fixiter) {
1306 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
1307 iter != remaining.end(); ++iter) {
1308 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
1309 }
1310 }
1311 }
1312
1313 // test with three points, matching trivially
1314 {
1315 SphericalPointDistribution::WeightedPolygon_t polygon;
1316 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1317 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
1318 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
1319 SphericalPointDistribution::Polygon_t newpolygon =
1320 SPD.get<7>();
1321 SphericalPointDistribution::Polygon_t expected = newpolygon;
1322 expected.pop_front(); // remove first point
1323 expected.pop_front(); // remove second point
1324 expected.pop_front(); // remove third point
1325 SphericalPointDistribution::Polygon_t remaining =
1326 SphericalPointDistribution::matchSphericalPointDistributions(
1327 polygon,
1328 newpolygon);
1329// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1330 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1331 // also slightly perturbed
1332 const double amplitude = 0.05;
1333 perturbPolygon(polygon, amplitude);
1334 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1335 }
1336
1337 // test with three points, full rotation
1338 {
1339 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1340 SphericalPointDistribution::WeightedPolygon_t polygon;
1341 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1342 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
1343 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
1344 SphericalPointDistribution::Polygon_t newpolygon =
1345 SPD.get<7>();
1346 SphericalPointDistribution::Polygon_t expected = newpolygon;
1347 expected.pop_front(); // remove first point
1348 expected.pop_front(); // remove second point
1349 expected.pop_front(); // remove third point
1350 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1351 iter != expected.end(); ++iter)
1352 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1353 SphericalPointDistribution::Polygon_t remaining =
1354 SphericalPointDistribution::matchSphericalPointDistributions(
1355 polygon,
1356 newpolygon);
1357// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1358 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1359 // also slightly perturbed
1360 const double amplitude = 0.05;
1361 perturbPolygon(polygon, amplitude);
1362 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1363 }
1364}
1365
1366/** UnitTest for matchSphericalPointDistributions() with eight points
1367 */
1368void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_8()
1369{
1370 SphericalPointDistribution SPD(1.);
1371
1372 // test with one point, matching trivially
1373 {
1374 SphericalPointDistribution::WeightedPolygon_t polygon;
1375 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1376 SphericalPointDistribution::Polygon_t newpolygon =
1377 SPD.get<8>();
1378 SphericalPointDistribution::Polygon_t expected = newpolygon;
1379 expected.pop_front(); // remove first point
1380 SphericalPointDistribution::Polygon_t remaining =
1381 SphericalPointDistribution::matchSphericalPointDistributions(
1382 polygon,
1383 newpolygon);
1384// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1385 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1386 }
1387
1388 // test with one point, just a flip of axis
1389 {
1390 SphericalPointDistribution::WeightedPolygon_t polygon;
1391 polygon += std::make_pair( Vector(0.,1.,0.), 1);
1392 SphericalPointDistribution::Polygon_t newpolygon =
1393 SPD.get<8>();
1394 SphericalPointDistribution::Polygon_t expected = newpolygon;
1395 expected.pop_front(); // remove first point
1396 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1397 iter != expected.end(); ++iter) {
1398 std::swap((*iter)[0], (*iter)[1]);
1399 (*iter)[0] *= -1.;
1400 }
1401 SphericalPointDistribution::Polygon_t remaining =
1402 SphericalPointDistribution::matchSphericalPointDistributions(
1403 polygon,
1404 newpolygon);
1405// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1406 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1407 }
1408
1409 // test with two points, matching trivially
1410 {
1411 SphericalPointDistribution::WeightedPolygon_t polygon;
1412 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1413 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
1414 SphericalPointDistribution::Polygon_t newpolygon =
1415 SPD.get<8>();
1416 SphericalPointDistribution::Polygon_t expected = newpolygon;
1417 expected.pop_front(); // remove first point
1418 expected.pop_front(); // remove second point
1419 SphericalPointDistribution::Polygon_t remaining =
1420 SphericalPointDistribution::matchSphericalPointDistributions(
1421 polygon,
1422 newpolygon);
1423// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1424 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1425 // also slightly perturbed
1426 const double amplitude = 0.05;
1427 perturbPolygon(polygon, amplitude);
1428 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1429 }
1430
1431 // test with two points, full rotation
1432 {
1433 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1434 SphericalPointDistribution::WeightedPolygon_t polygon;
1435 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1436 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
1437 SphericalPointDistribution::Polygon_t newpolygon =
1438 SPD.get<8>();
1439 SphericalPointDistribution::Polygon_t expected = newpolygon;
1440 expected.pop_front(); // remove first point
1441 expected.pop_front(); // remove second point
1442 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1443 iter != expected.end(); ++iter)
1444 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1445 SphericalPointDistribution::Polygon_t remaining =
1446 SphericalPointDistribution::matchSphericalPointDistributions(
1447 polygon,
1448 newpolygon);
1449 // the six remaining points sit on two planes that may have been rotated arbitrarily
1450 // so we cannot simply check for equality between expected and remaining
1451 // hence, we just check that they are orthogonal to the first two points
1452 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
1453 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
1454 fixiter != polygon.end(); ++fixiter) {
1455 SphericalPointDistribution::Polygon_t::const_iterator expectiter = expected.begin();
1456 SphericalPointDistribution::Polygon_t::const_iterator remainiter = remaining.begin();
1457 for (;remainiter != remaining.end(); ++expectiter, ++remainiter) {
1458 // check that points in expected/remaining have same angle to the given ones
1459// CPPUNIT_ASSERT_EQUAL( (*expectiter).Angle(*fixiter), (*remainiter).Angle(*fixiter) );
1460 CPPUNIT_ASSERT( fabs( (*expectiter).Angle(fixiter->first) - (*remainiter).Angle(fixiter->first) )
1461 < std::numeric_limits<double>::epsilon()*1e4 );
1462 }
1463 }
1464 }
1465
1466 // test with three points, matching trivially
1467 {
1468 SphericalPointDistribution::WeightedPolygon_t polygon;
1469 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1470 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
1471 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 1);
1472 SphericalPointDistribution::Polygon_t newpolygon =
1473 SPD.get<8>();
1474 SphericalPointDistribution::Polygon_t expected = newpolygon;
1475 expected.pop_front(); // remove first point
1476 expected.pop_front(); // remove second point
1477 expected.pop_front(); // remove third point
1478 SphericalPointDistribution::Polygon_t remaining =
1479 SphericalPointDistribution::matchSphericalPointDistributions(
1480 polygon,
1481 newpolygon);
1482// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1483 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1484 // also slightly perturbed
1485 const double amplitude = 0.05;
1486 perturbPolygon(polygon, amplitude);
1487 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1488 }
1489
1490 // test with three points, full rotation
1491 {
1492 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
1493 SphericalPointDistribution::WeightedPolygon_t polygon;
1494 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1495 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
1496 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 47.6/180*M_PI), 1);
1497 SphericalPointDistribution::Polygon_t newpolygon =
1498 SPD.get<8>();
1499 SphericalPointDistribution::Polygon_t expected = newpolygon;
1500 expected.pop_front(); // remove first point
1501 expected.pop_front(); // remove second point
1502 expected.pop_front(); // remove third point
1503 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1504 iter != expected.end(); ++iter)
1505 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1506 SphericalPointDistribution::Polygon_t remaining =
1507 SphericalPointDistribution::matchSphericalPointDistributions(
1508 polygon,
1509 newpolygon);
1510// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1511 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
1512 // also slightly perturbed
1513 const double amplitude = 0.05;
1514 perturbPolygon(polygon, amplitude);
1515 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
1516 }
1517}
Note: See TracBrowser for help on using the repository browser.