source: src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp@ c1413b

Last change on this file since c1413b was e6ca85, checked in by Frederik Heber <heber@…>, 11 years ago

recurseMatching() now takes connections into account.

  • matchSphericalPointDistribution() replaced by getRemainingPoints() as that describes what it does. match...() sounds symmetrical which the function is no longer as connection is associated with former _newpolygon.
  • SphericalPointDistribution now has internal points and adjacency, initialized by initSelf().
  • findBestMatching() and getRemainingPoints() are no longer static functions.
  • all unit tests are working again, including the .._multiple() that tests for joint points due to bond degree greater than 1.
  • the huge case switch in SaturatedFragment::saturateAtom() now resides in initSelf().
  • Property mode set to 100644
File size: 56.2 KB
RevLine 
[11cc05]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
[42c742]47#include <algorithm>
[11cc05]48#include <boost/assign.hpp>
[0ae114]49#include <boost/math/quaternion.hpp>
[11cc05]50
51#include "CodePatterns/Assert.hpp"
[d734ff]52#include "CodePatterns/Log.hpp"
[11cc05]53
[0ae114]54#include "LinearAlgebra/Line.hpp"
55
[42c742]56#include "Atom/TesselPoint.hpp"
[11cc05]57#include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
[42c742]58#include "LinkedCell/linkedcell.hpp"
59#include "LinkedCell/PointCloudAdaptor.hpp"
60#include "Tesselation/BoundaryLineSet.hpp"
61#include "Tesselation/tesselation.hpp"
[a39f66]62
[11cc05]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
[a2f8a9]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);
[11cc05]78
79void SphericalPointDistributionTest::setUp()
80{
81 // failing asserts should be thrown
82 ASSERT_DO(Assert::Throw);
[d734ff]83
[42c742]84 setVerbosity(2);
[11cc05]85}
86
87
88void SphericalPointDistributionTest::tearDown()
89{
90}
91
[a2f8a9]92/** UnitTest for calculateCenterOfMinimumDistance()
[11cc05]93 */
[a2f8a9]94void SphericalPointDistributionTest::calculateCenterOfMinimumDistanceTest()
[11cc05]95{
[a2f8a9]96 // single point
[11cc05]97 {
[a2f8a9]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));
[11cc05]109 }
110
[a2f8a9]111 // single point, rotated
[11cc05]112 {
[a2f8a9]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));
[d734ff]125 }
126
[a2f8a9]127 // two points
[d734ff]128 {
[a2f8a9]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));
[11cc05]141 }
[0ae114]142
[a2f8a9]143 // two points, rotated
[0ae114]144 {
145 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[a2f8a9]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));
[0ae114]158 }
[11cc05]159
[a2f8a9]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));
[3da643]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) {
[a2f8a9]211 status &= (*iter).IsEqualTo(*otheriter, _amplitude);
[3da643]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
[42c742]276/** UnitTest for getConnections()
[a2f8a9]277 */
[42c742]278template <>
279void SphericalPointDistributionTest_assistant::getConnectionTest<0>()
[a2f8a9]280{
[42c742]281 const int N=0;
[a2f8a9]282 SphericalPointDistribution SPD(1.);
283
[42c742]284 // create empty adjacency
285 SphericalPointDistribution::adjacency_t adjacency;
[a2f8a9]286
[42c742]287 // get the implemented connections
288 SphericalPointDistribution::adjacency_t expected =
289 SPD.getConnections<N>();
[a2f8a9]290
[42c742]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 );
[a2f8a9]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
[1ae9aa]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}
[3da643]461
[e6ca85]462/** UnitTest for getRemainingPoints() with two points
[42c742]463 */
[e6ca85]464void SphericalPointDistributionTest::getRemainingPointsTest_2()
[42c742]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 expected;
472 expected += Vector(-1.,0.,0.);
473 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]474 SPD.getRemainingPoints(polygon, 2);
[42c742]475// CPPUNIT_ASSERT_EQUAL( expected, remaining );
476 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
477 }
478
479 // test with one point, just a flip of axis
480 {
481 SphericalPointDistribution::WeightedPolygon_t polygon;
482 polygon += std::make_pair( Vector(0.,1.,0.), 1);
483 SphericalPointDistribution::Polygon_t expected;
484 expected += Vector(0.,-1.,0.);
485 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]486 SPD.getRemainingPoints(polygon, 2);
[42c742]487// CPPUNIT_ASSERT_EQUAL( expected, remaining );
488 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
489 }
490
491 // test with one point, just a flip to another axis
492 {
493 SphericalPointDistribution::WeightedPolygon_t polygon;
494 polygon += std::make_pair( Vector(0.,0.,-1.), 1);
495 SphericalPointDistribution::Polygon_t expected;
496 expected += Vector(0.,0.,1.);
497 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]498 SPD.getRemainingPoints(polygon, 2);
[42c742]499// CPPUNIT_ASSERT_EQUAL( expected, remaining );
500 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
501 }
502
503 // test with one point, full rotation
504 {
505 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
506 SphericalPointDistribution::WeightedPolygon_t polygon;
507 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
508 SphericalPointDistribution::Polygon_t expected;
509 expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
510 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]511 SPD.getRemainingPoints(polygon, 2);
[42c742]512// CPPUNIT_ASSERT_EQUAL( expected, remaining );
513 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
514 }
515}
516
[e6ca85]517/** UnitTest for getRemainingPoints() with three points
[11cc05]518 */
[e6ca85]519void SphericalPointDistributionTest::getRemainingPointsTest_3()
[11cc05]520{
521 SphericalPointDistribution SPD(1.);
522
523 // test with one point, matching trivially
524 {
[260540]525 SphericalPointDistribution::WeightedPolygon_t polygon;
526 polygon += std::make_pair( Vector(1.,0.,0.), 1);
[e6ca85]527 SphericalPointDistribution::Polygon_t expected =
[11cc05]528 SPD.get<3>();
529 expected.pop_front(); // remove first point
530 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]531 SPD.getRemainingPoints(polygon, 3);
[a2f8a9]532// CPPUNIT_ASSERT_EQUAL( expected, remaining );
533 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[11cc05]534 }
[d734ff]535
[0ae114]536 // test with one point, just a flip of x and y axis
[d734ff]537 {
[260540]538 SphericalPointDistribution::WeightedPolygon_t polygon;
539 polygon += std::make_pair( Vector(0.,1.,0.), 1);
[e6ca85]540 SphericalPointDistribution::Polygon_t expected =
[d734ff]541 SPD.get<3>();
542 expected.pop_front(); // remove first point
[0ae114]543 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
544 iter != expected.end(); ++iter) {
545 std::swap((*iter)[0], (*iter)[1]);
546 (*iter)[0] *= -1.;
547 }
[d734ff]548 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]549 SPD.getRemainingPoints(polygon, 3);
[a2f8a9]550// CPPUNIT_ASSERT_EQUAL( expected, remaining );
551 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]552 }
[6aa6b7]553
554 // test with two points, matching trivially
555 {
[260540]556 SphericalPointDistribution::WeightedPolygon_t polygon;
557 polygon += std::make_pair( Vector(1.,0.,0.), 1);
558 polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
[e6ca85]559 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]560 SPD.get<3>();
561 expected.pop_front(); // remove first point
562 expected.pop_front(); // remove second point
563 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]564 SPD.getRemainingPoints(polygon, 3);
[a2f8a9]565// CPPUNIT_ASSERT_EQUAL( expected, remaining );
566 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]567 // also slightly perturbed
568 const double amplitude = 0.05;
569 perturbPolygon(polygon, amplitude);
570 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]571 }
572
573 // test with two points, full rotation
574 {
575 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]576 SphericalPointDistribution::WeightedPolygon_t polygon;
577 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
578 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
[e6ca85]579 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]580 SPD.get<3>();
581 expected.pop_front(); // remove first point
582 expected.pop_front(); // remove second point
583 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
584 iter != expected.end(); ++iter)
585 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
586 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]587 SPD.getRemainingPoints(polygon, 3);
[a2f8a9]588// CPPUNIT_ASSERT_EQUAL( expected, remaining );
589 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]590 // also slightly perturbed
591 const double amplitude = 0.05;
592 perturbPolygon(polygon, amplitude);
593 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]594 }
595
596 // test with three points, matching trivially
597 {
[260540]598 SphericalPointDistribution::WeightedPolygon_t polygon;
599 polygon += std::make_pair( Vector(1.,0.,0.), 1);
600 polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
601 polygon += std::make_pair( Vector(-0.5, -sqrt(3)*0.5,0.), 1);
[6aa6b7]602 SphericalPointDistribution::Polygon_t newpolygon =
603 SPD.get<3>();
604 SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
605 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]606 SPD.getRemainingPoints(polygon, 3);
[a2f8a9]607// CPPUNIT_ASSERT_EQUAL( expected, remaining );
608 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]609 // also slightly perturbed
610 const double amplitude = 0.05;
611 perturbPolygon(polygon, amplitude);
612 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]613 }
614
615
616 // test with three points, full rotation
617 {
618 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]619 SphericalPointDistribution::WeightedPolygon_t polygon;
620 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
621 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
622 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, -sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
[6aa6b7]623 SphericalPointDistribution::Polygon_t newpolygon =
624 SPD.get<3>();
625 SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
626 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]627 SPD.getRemainingPoints(polygon, 3);
[a2f8a9]628// CPPUNIT_ASSERT_EQUAL( expected, remaining );
629 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]630 // also slightly perturbed
631 const double amplitude = 0.05;
632 perturbPolygon(polygon, amplitude);
633 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]634 }
[d734ff]635}
636
[e6ca85]637/** UnitTest for getRemainingPoints() with four points
[d734ff]638 */
[e6ca85]639void SphericalPointDistributionTest::getRemainingPointsTest_4()
[d734ff]640{
641 SphericalPointDistribution SPD(1.);
642
643 // test with one point, matching trivially
644 {
[260540]645 SphericalPointDistribution::WeightedPolygon_t polygon;
646 polygon += std::make_pair( Vector(1.,0.,0.), 1);
[e6ca85]647 SphericalPointDistribution::Polygon_t expected =
[d734ff]648 SPD.get<4>();
649 expected.pop_front(); // remove first point
650 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]651 SPD.getRemainingPoints(polygon, 4);
[a2f8a9]652 // CPPUNIT_ASSERT_EQUAL( expected, remaining );
653 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]654 }
655
656 // test with one point, just a flip of axis
657 {
[260540]658 SphericalPointDistribution::WeightedPolygon_t polygon;
659 polygon += std::make_pair( Vector(0.,1.,0.), 1);
[e6ca85]660 SphericalPointDistribution::Polygon_t expected =
[d734ff]661 SPD.get<4>();
662 expected.pop_front(); // remove first point
[0ae114]663 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
664 iter != expected.end(); ++iter) {
665 std::swap((*iter)[0], (*iter)[1]);
666 (*iter)[0] *= -1.;
667 }
[d734ff]668 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]669 SPD.getRemainingPoints(polygon, 4);
[a2f8a9]670// CPPUNIT_ASSERT_EQUAL( expected, remaining );
671 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]672 }
[6aa6b7]673
674 // test with two points, matching trivially
675 {
[260540]676 SphericalPointDistribution::WeightedPolygon_t polygon;
677 polygon += std::make_pair( Vector(1.,0.,0.), 1);
678 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
[e6ca85]679 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]680 SPD.get<4>();
681 expected.pop_front(); // remove first point
682 expected.pop_front(); // remove second point
683 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]684 SPD.getRemainingPoints(polygon, 4);
[a2f8a9]685// CPPUNIT_ASSERT_EQUAL( expected, remaining );
686 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]687 // also slightly perturbed
688 const double amplitude = 0.05;
689 perturbPolygon(polygon, amplitude);
690 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
691 }
692
693 // test with two points, matching trivially, also with slightly perturbed
694 {
[260540]695 SphericalPointDistribution::WeightedPolygon_t polygon;
696 polygon += std::make_pair( Vector(1.,0.,0.), 1);
697 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
[e6ca85]698 SphericalPointDistribution::Polygon_t expected =
[3da643]699 SPD.get<4>();
700 expected.pop_front(); // remove first point
701 expected.pop_front(); // remove second point
702 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]703 SPD.getRemainingPoints(polygon, 4);
[a2f8a9]704// CPPUNIT_ASSERT_EQUAL( expected, remaining );
705 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]706 // also slightly perturbed
707 const double amplitude = 0.05;
708 perturbPolygon(polygon, amplitude);
709 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]710 }
711
712 // test with two points, full rotation
713 {
714 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]715 SphericalPointDistribution::WeightedPolygon_t polygon;
716 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
717 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
[e6ca85]718 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]719 SPD.get<4>();
720 expected.pop_front(); // remove first point
721 expected.pop_front(); // remove second point
722 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
723 iter != expected.end(); ++iter)
724 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
725 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]726 SPD.getRemainingPoints(polygon, 4);
[a2f8a9]727// CPPUNIT_ASSERT_EQUAL( expected, remaining );
728 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]729 // also slightly perturbed
730 const double amplitude = 0.05;
731 perturbPolygon(polygon, amplitude);
732 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]733 }
734
735 // test with three points, matching trivially
736 {
[260540]737 SphericalPointDistribution::WeightedPolygon_t polygon;
738 polygon += std::make_pair( Vector(1.,0.,0.), 1);
739 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
740 polygon += std::make_pair( Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 1);
[e6ca85]741 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]742 SPD.get<4>();
743 expected.pop_front(); // remove first point
744 expected.pop_front(); // remove second point
745 expected.pop_front(); // remove third point
746 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]747 SPD.getRemainingPoints(polygon, 4);
[a2f8a9]748// CPPUNIT_ASSERT_EQUAL( expected, remaining );
749 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]750 // also slightly perturbed
751 const double amplitude = 0.05;
752 perturbPolygon(polygon, amplitude);
753 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]754 }
755
756 // test with three points, full rotation
757 {
758 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]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 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 47.6/180*M_PI), 1);
[e6ca85]763 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]764 SPD.get<4>();
765 expected.pop_front(); // remove first point
766 expected.pop_front(); // remove second point
767 expected.pop_front(); // remove third point
768 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
769 iter != expected.end(); ++iter)
770 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
771 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]772 SPD.getRemainingPoints(polygon, 4);
[a2f8a9]773// CPPUNIT_ASSERT_EQUAL( expected, remaining );
774 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]775 // also slightly perturbed
776 const double amplitude = 0.05;
777 perturbPolygon(polygon, amplitude);
778 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]779 }
[d734ff]780}
781
[e6ca85]782/** UnitTest for getRemainingPoints() with four points and weights
[23c605]783 * not all equal to one.
784 */
[e6ca85]785void SphericalPointDistributionTest::getRemainingPointsTest_multiple()
[23c605]786{
787 SphericalPointDistribution SPD(1.);
788
789 // test with four points: one point having weight of two
790 {
791 SphericalPointDistribution::WeightedPolygon_t polygon;
792 polygon += std::make_pair( Vector(1.,0.,0.), 2);
793 SphericalPointDistribution::Polygon_t newpolygon =
794 SPD.get<4>();
795 SphericalPointDistribution::Polygon_t expected;
796 expected += Vector(-0.5773502691896,-5.551115123126e-17,0.8164965809277);
797 expected += Vector(-0.5773502691896,-5.551115123126e-17,-0.8164965809277);
798 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]799 SPD.getRemainingPoints(polygon, 4);
[23c605]800// std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
[a2f8a9]801// CPPUNIT_ASSERT_EQUAL( expected, remaining );
802 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[23c605]803 }
804
805 // test with five points: one point having weight of two
806 {
807 SphericalPointDistribution::WeightedPolygon_t polygon;
808 polygon += std::make_pair( Vector(1.,0.,0.), 2);
809 SphericalPointDistribution::Polygon_t newpolygon =
810 SPD.get<5>();
811 SphericalPointDistribution::Polygon_t expected;
812 expected += Vector(-0.7071067811865,0.7071067811865,0);
813 expected += Vector(-0.3535533905933,-0.3535533905933,0.8660254037844);
814 expected += Vector(-0.3535533905933,-0.3535533905933,-0.8660254037844);
815 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]816 SPD.getRemainingPoints(polygon, 5);
817 std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
[a2f8a9]818// CPPUNIT_ASSERT_EQUAL( expected, remaining );
819 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[23c605]820 }
821
822
823 // test with five points: one point having weight of two, one weight of one
824 {
825 SphericalPointDistribution::WeightedPolygon_t polygon;
826 polygon += std::make_pair( Vector(M_SQRT1_2,M_SQRT1_2,0.), 2);
827 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
828 SphericalPointDistribution::Polygon_t newpolygon =
829 SPD.get<5>();
830 SphericalPointDistribution::Polygon_t expected;
831 expected += Vector(0.3535533786708,-0.3535533955317,-0.8660254066357);
832 expected += Vector(0.3535534025157,-0.3535533856548,0.8660254009332);
833 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]834 SPD.getRemainingPoints(polygon, 5);
[23c605]835// std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
[a2f8a9]836// CPPUNIT_ASSERT_EQUAL( expected, remaining );
837 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[23c605]838 }
839
840 // test with six points: two points each having weight of two
841 {
842 SphericalPointDistribution::WeightedPolygon_t polygon;
843 polygon += std::make_pair( Vector(M_SQRT1_2,-M_SQRT1_2,0.), 2);
844 polygon += std::make_pair( Vector(-M_SQRT1_2,M_SQRT1_2,0.), 2);
845 SphericalPointDistribution::Polygon_t newpolygon =
846 SPD.get<6>();
847 SphericalPointDistribution::Polygon_t expected;
848 expected += Vector(0.,0.,1.);
[e6ca85]849 expected += Vector(0.,0.,-1.);
[23c605]850 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]851 SPD.getRemainingPoints(polygon, 6);
[23c605]852// std::cout << std::setprecision(13) << "Matched polygon is " << remaining << std::endl;
[a2f8a9]853// CPPUNIT_ASSERT_EQUAL( expected, remaining );
854 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[23c605]855 }
856}
857
[e6ca85]858/** UnitTest for getRemainingPoints() with five points
[d734ff]859 */
[e6ca85]860void SphericalPointDistributionTest::getRemainingPointsTest_5()
[d734ff]861{
862 SphericalPointDistribution SPD(1.);
863
864 // test with one point, matching trivially
865 {
[260540]866 SphericalPointDistribution::WeightedPolygon_t polygon;
867 polygon += std::make_pair( Vector(1.,0.,0.), 1);
[e6ca85]868 SphericalPointDistribution::Polygon_t expected =
[d734ff]869 SPD.get<5>();
870 expected.pop_front(); // remove first point
871 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]872 SPD.getRemainingPoints(polygon, 5);
[a2f8a9]873// CPPUNIT_ASSERT_EQUAL( expected, remaining );
874 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]875 }
876
877 // test with one point, just a flip of axis
878 {
[260540]879 SphericalPointDistribution::WeightedPolygon_t polygon;
880 polygon += std::make_pair( Vector(0.,1.,0.), 1);
[e6ca85]881 SphericalPointDistribution::Polygon_t expected =
[d734ff]882 SPD.get<5>();
883 expected.pop_front(); // remove first point
[0ae114]884 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
885 iter != expected.end(); ++iter) {
886 std::swap((*iter)[0], (*iter)[1]);
887 (*iter)[0] *= -1.;
888 }
[d734ff]889 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]890 SPD.getRemainingPoints(polygon, 5);
[a2f8a9]891// CPPUNIT_ASSERT_EQUAL( expected, remaining );
892 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]893 }
[6aa6b7]894
895 // test with two points, matching trivially
896 {
[260540]897 SphericalPointDistribution::WeightedPolygon_t polygon;
898 polygon += std::make_pair( Vector(1.,0.,0.), 1);
899 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
[e6ca85]900 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]901 SPD.get<5>();
902 expected.pop_front(); // remove first point
903 expected.pop_front(); // remove second point
904 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]905 SPD.getRemainingPoints(polygon, 5);
[a2f8a9]906// CPPUNIT_ASSERT_EQUAL( expected, remaining );
907 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]908 // also slightly perturbed
909 const double amplitude = 0.05;
910 perturbPolygon(polygon, amplitude);
911 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]912 }
913
914 // test with two points, full rotation
915 {
916 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]917 SphericalPointDistribution::WeightedPolygon_t polygon;
918 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180.*M_PI), 1);
919 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180.*M_PI), 1);
[e6ca85]920 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]921 SPD.get<5>();
922 expected.pop_front(); // remove first point
923 expected.pop_front(); // remove second point
924 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
925 iter != expected.end(); ++iter)
926 *iter = RotationAxis.rotateVector(*iter, 47.6/180.*M_PI);
927 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]928 SPD.getRemainingPoints(polygon, 5);
[6aa6b7]929 // the three remaining points sit on a plane that may be rotated arbitrarily
930 // so we cannot simply check for equality between expected and remaining
931 // hence, we just check that they are orthogonal to the first two points
932 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
[260540]933 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
[6aa6b7]934 fixiter != polygon.end(); ++fixiter) {
935 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
936 iter != remaining.end(); ++iter) {
[260540]937 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
[6aa6b7]938 }
939 }
940 }
941
942 // test with three points, matching trivially
943 {
[260540]944 SphericalPointDistribution::WeightedPolygon_t polygon;
945 polygon += std::make_pair( Vector(1.,0.,0.), 1);
946 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
947 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
[e6ca85]948 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]949 SPD.get<5>();
950 expected.pop_front(); // remove first point
951 expected.pop_front(); // remove second point
952 expected.pop_front(); // remove third point
953 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]954 SPD.getRemainingPoints(polygon, 5);
[a2f8a9]955// CPPUNIT_ASSERT_EQUAL( expected, remaining );
956 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]957 // also slightly perturbed
958 const double amplitude = 0.05;
959 perturbPolygon(polygon, amplitude);
960 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]961 }
962
963 // test with three points, full rotation
964 {
965 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]966 SphericalPointDistribution::WeightedPolygon_t polygon;
967 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
968 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
969 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
[e6ca85]970 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]971 SPD.get<5>();
972 expected.pop_front(); // remove first point
973 expected.pop_front(); // remove second point
974 expected.pop_front(); // remove third point
975 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
976 iter != expected.end(); ++iter)
977 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
978 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]979 SPD.getRemainingPoints(polygon, 5);
[a2f8a9]980// CPPUNIT_ASSERT_EQUAL( expected, remaining );
981 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]982 // also slightly perturbed
983 const double amplitude = 0.05;
984 perturbPolygon(polygon, amplitude);
985 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]986 }
[d734ff]987}
988
[e6ca85]989/** UnitTest for getRemainingPoints() with six points
[d734ff]990 */
[e6ca85]991void SphericalPointDistributionTest::getRemainingPointsTest_6()
[d734ff]992{
993 SphericalPointDistribution SPD(1.);
994
995 // test with one point, matching trivially
996 {
[260540]997 SphericalPointDistribution::WeightedPolygon_t polygon;
998 polygon += std::make_pair( Vector(1.,0.,0.), 1);
[e6ca85]999 SphericalPointDistribution::Polygon_t expected =
[d734ff]1000 SPD.get<6>();
1001 expected.pop_front(); // remove first point
1002 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1003 SPD.getRemainingPoints(polygon, 6);
[a2f8a9]1004// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1005 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]1006 }
1007
1008 // test with one point, just a flip of axis
1009 {
[260540]1010 SphericalPointDistribution::WeightedPolygon_t polygon;
1011 polygon += std::make_pair( Vector(0.,1.,0.), 1);
[e6ca85]1012 SphericalPointDistribution::Polygon_t expected =
[d734ff]1013 SPD.get<6>();
1014 expected.pop_front(); // remove first point
[0ae114]1015 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1016 iter != expected.end(); ++iter) {
1017 std::swap((*iter)[0], (*iter)[1]);
1018 (*iter)[0] *= -1.;
1019 }
[d734ff]1020 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1021 SPD.getRemainingPoints(polygon, 6);
[a2f8a9]1022// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1023 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]1024 }
[6aa6b7]1025
1026 // test with two points, matching trivially
1027 {
[260540]1028 SphericalPointDistribution::WeightedPolygon_t polygon;
1029 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1030 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
[e6ca85]1031 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1032 SPD.get<6>();
1033 expected.pop_front(); // remove first point
1034 expected.pop_front(); // remove second spoint
1035 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1036 SPD.getRemainingPoints(polygon, 6);
[a2f8a9]1037// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1038 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1039 // also slightly perturbed
1040 const double amplitude = 0.05;
1041 perturbPolygon(polygon, amplitude);
1042 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1043 }
1044
1045 // test with two points, full rotation
1046 {
1047 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]1048 SphericalPointDistribution::WeightedPolygon_t polygon;
1049 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1050 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
[e6ca85]1051 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1052 SPD.get<6>();
1053 expected.pop_front(); // remove first point
1054 expected.pop_front(); // remove second spoint
1055 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1056 iter != expected.end(); ++iter)
1057 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1058 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1059 SPD.getRemainingPoints(polygon, 6);
[6aa6b7]1060 // the four remaining points sit on a plane that may have been rotated arbitrarily
1061 // so we cannot simply check for equality between expected and remaining
1062 // hence, we just check that they are orthogonal to the first two points
1063 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
[260540]1064 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
[6aa6b7]1065 fixiter != polygon.end(); ++fixiter) {
1066 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
1067 iter != remaining.end(); ++iter) {
[260540]1068 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
[6aa6b7]1069 }
1070 }
1071 }
1072
1073 // test with three points, matching trivially
1074 {
[260540]1075 SphericalPointDistribution::WeightedPolygon_t polygon;
1076 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1077 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
1078 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
[e6ca85]1079 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1080 SPD.get<6>();
1081 expected.pop_front(); // remove first point
1082 expected.pop_front(); // remove second point
1083 expected.pop_front(); // remove third point
1084 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1085 SPD.getRemainingPoints(polygon, 6);
[a2f8a9]1086// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1087 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1088 // also slightly perturbed
1089 const double amplitude = 0.05;
1090 perturbPolygon(polygon, amplitude);
1091 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1092 }
1093
1094 // test with three points, full rotation
1095 {
1096 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]1097 SphericalPointDistribution::WeightedPolygon_t polygon;
1098 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1099 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
1100 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
[e6ca85]1101 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1102 SPD.get<6>();
1103 expected.pop_front(); // remove first point
1104 expected.pop_front(); // remove second point
1105 expected.pop_front(); // remove third point
1106 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1107 iter != expected.end(); ++iter)
1108 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1109 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1110 SPD.getRemainingPoints(polygon, 6);
[a2f8a9]1111// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1112 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1113 // also slightly perturbed
1114 const double amplitude = 0.05;
1115 perturbPolygon(polygon, amplitude);
1116 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1117 }
[d734ff]1118}
1119
[e6ca85]1120/** UnitTest for getRemainingPoints() with seven points
[d734ff]1121 */
[e6ca85]1122void SphericalPointDistributionTest::getRemainingPointsTest_7()
[d734ff]1123{
1124 SphericalPointDistribution SPD(1.);
1125
1126 // test with one point, matching trivially
1127 {
[260540]1128 SphericalPointDistribution::WeightedPolygon_t polygon;
1129 polygon += std::make_pair( Vector(1.,0.,0.), 1);
[e6ca85]1130 SphericalPointDistribution::Polygon_t expected =
[d734ff]1131 SPD.get<7>();
1132 expected.pop_front(); // remove first point
1133 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1134 SPD.getRemainingPoints(polygon, 7);
[a2f8a9]1135// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1136 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]1137 }
1138
1139 // test with one point, just a flip of axis
1140 {
[260540]1141 SphericalPointDistribution::WeightedPolygon_t polygon;
1142 polygon += std::make_pair( Vector(0.,1.,0.), 1);
[e6ca85]1143 SphericalPointDistribution::Polygon_t expected =
[d734ff]1144 SPD.get<7>();
1145 expected.pop_front(); // remove first point
[0ae114]1146 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1147 iter != expected.end(); ++iter) {
1148 std::swap((*iter)[0], (*iter)[1]);
1149 (*iter)[0] *= -1.;
1150 }
[d734ff]1151 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1152 SPD.getRemainingPoints(polygon, 7);
[a2f8a9]1153// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1154 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]1155 }
[6aa6b7]1156
1157 // test with two points, matching trivially
1158 {
[260540]1159 SphericalPointDistribution::WeightedPolygon_t polygon;
1160 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1161 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
[e6ca85]1162 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1163 SPD.get<7>();
1164 expected.pop_front(); // remove first point
1165 expected.pop_front(); // remove second point
1166 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1167 SPD.getRemainingPoints(polygon, 7);
[a2f8a9]1168// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1169 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1170 // also slightly perturbed
1171 const double amplitude = 0.05;
1172 perturbPolygon(polygon, amplitude);
1173 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1174 }
1175
1176 // test with two points, full rotation
1177 {
1178 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]1179 SphericalPointDistribution::WeightedPolygon_t polygon;
1180 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1181 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
[e6ca85]1182 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1183 SPD.get<7>();
1184 expected.pop_front(); // remove first point
1185 expected.pop_front(); // remove second point
1186 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1187 iter != expected.end(); ++iter)
1188 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1189 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1190 SPD.getRemainingPoints(polygon, 7);
[6aa6b7]1191 // the five remaining points sit on a plane that may have been rotated arbitrarily
1192 // so we cannot simply check for equality between expected and remaining
1193 // hence, we just check that they are orthogonal to the first two points
1194 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
[260540]1195 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
[6aa6b7]1196 fixiter != polygon.end(); ++fixiter) {
1197 for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
1198 iter != remaining.end(); ++iter) {
[260540]1199 CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
[6aa6b7]1200 }
1201 }
1202 }
1203
1204 // test with three points, matching trivially
1205 {
[260540]1206 SphericalPointDistribution::WeightedPolygon_t polygon;
1207 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1208 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
1209 polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
[e6ca85]1210 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1211 SPD.get<7>();
1212 expected.pop_front(); // remove first point
1213 expected.pop_front(); // remove second point
1214 expected.pop_front(); // remove third point
1215 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1216 SPD.getRemainingPoints(polygon, 7);
[a2f8a9]1217// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1218 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1219 // also slightly perturbed
1220 const double amplitude = 0.05;
1221 perturbPolygon(polygon, amplitude);
1222 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1223 }
1224
1225 // test with three points, full rotation
1226 {
1227 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]1228 SphericalPointDistribution::WeightedPolygon_t polygon;
1229 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1230 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
1231 polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
[e6ca85]1232 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1233 SPD.get<7>();
1234 expected.pop_front(); // remove first point
1235 expected.pop_front(); // remove second point
1236 expected.pop_front(); // remove third point
1237 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1238 iter != expected.end(); ++iter)
1239 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1240 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1241 SPD.getRemainingPoints(polygon, 7);
[a2f8a9]1242// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1243 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1244 // also slightly perturbed
1245 const double amplitude = 0.05;
1246 perturbPolygon(polygon, amplitude);
1247 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1248 }
[d734ff]1249}
1250
[e6ca85]1251/** UnitTest for getRemainingPoints() with eight points
[d734ff]1252 */
[e6ca85]1253void SphericalPointDistributionTest::getRemainingPointsTest_8()
[d734ff]1254{
1255 SphericalPointDistribution SPD(1.);
1256
1257 // test with one point, matching trivially
1258 {
[260540]1259 SphericalPointDistribution::WeightedPolygon_t polygon;
1260 polygon += std::make_pair( Vector(1.,0.,0.), 1);
[e6ca85]1261 SphericalPointDistribution::Polygon_t expected =
[d734ff]1262 SPD.get<8>();
1263 expected.pop_front(); // remove first point
1264 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1265 SPD.getRemainingPoints(polygon, 8);
[a2f8a9]1266// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1267 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]1268 }
1269
1270 // test with one point, just a flip of axis
1271 {
[260540]1272 SphericalPointDistribution::WeightedPolygon_t polygon;
1273 polygon += std::make_pair( Vector(0.,1.,0.), 1);
[e6ca85]1274 SphericalPointDistribution::Polygon_t expected =
[d734ff]1275 SPD.get<8>();
1276 expected.pop_front(); // remove first point
[0ae114]1277 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1278 iter != expected.end(); ++iter) {
1279 std::swap((*iter)[0], (*iter)[1]);
1280 (*iter)[0] *= -1.;
1281 }
[e6ca85]1282 SphericalPointDistribution::Polygon_t remaining =
1283 SPD.getRemainingPoints(polygon, 8);
[a2f8a9]1284// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1285 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[d734ff]1286 }
[6aa6b7]1287
1288 // test with two points, matching trivially
1289 {
[260540]1290 SphericalPointDistribution::WeightedPolygon_t polygon;
1291 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1292 polygon += std::make_pair( Vector(-1.,0.,0.), 1);
[e6ca85]1293 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1294 SPD.get<8>();
1295 expected.pop_front(); // remove first point
1296 expected.pop_front(); // remove second point
1297 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1298 SPD.getRemainingPoints(polygon, 8);
[a2f8a9]1299// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1300 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1301 // also slightly perturbed
1302 const double amplitude = 0.05;
1303 perturbPolygon(polygon, amplitude);
1304 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1305 }
1306
1307 // test with two points, full rotation
1308 {
1309 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]1310 SphericalPointDistribution::WeightedPolygon_t polygon;
1311 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1312 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
[e6ca85]1313 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1314 SPD.get<8>();
1315 expected.pop_front(); // remove first point
1316 expected.pop_front(); // remove second point
1317 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1318 iter != expected.end(); ++iter)
1319 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1320 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1321 SPD.getRemainingPoints(polygon, 8);
[6aa6b7]1322 // the six remaining points sit on two planes that may have been rotated arbitrarily
1323 // so we cannot simply check for equality between expected and remaining
1324 // hence, we just check that they are orthogonal to the first two points
1325 CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
[260540]1326 for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
[6aa6b7]1327 fixiter != polygon.end(); ++fixiter) {
1328 SphericalPointDistribution::Polygon_t::const_iterator expectiter = expected.begin();
1329 SphericalPointDistribution::Polygon_t::const_iterator remainiter = remaining.begin();
1330 for (;remainiter != remaining.end(); ++expectiter, ++remainiter) {
1331 // check that points in expected/remaining have same angle to the given ones
1332// CPPUNIT_ASSERT_EQUAL( (*expectiter).Angle(*fixiter), (*remainiter).Angle(*fixiter) );
[260540]1333 CPPUNIT_ASSERT( fabs( (*expectiter).Angle(fixiter->first) - (*remainiter).Angle(fixiter->first) )
[6aa6b7]1334 < std::numeric_limits<double>::epsilon()*1e4 );
1335 }
1336 }
1337 }
1338
1339 // test with three points, matching trivially
1340 {
[260540]1341 SphericalPointDistribution::WeightedPolygon_t polygon;
1342 polygon += std::make_pair( Vector(1.,0.,0.), 1);
1343 polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
1344 polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 1);
[e6ca85]1345 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1346 SPD.get<8>();
1347 expected.pop_front(); // remove first point
1348 expected.pop_front(); // remove second point
1349 expected.pop_front(); // remove third point
1350 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1351 SPD.getRemainingPoints(polygon, 8);
[a2f8a9]1352// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1353 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1354 // also slightly perturbed
1355 const double amplitude = 0.05;
1356 perturbPolygon(polygon, amplitude);
1357 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1358 }
1359
1360 // test with three points, full rotation
1361 {
1362 Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
[260540]1363 SphericalPointDistribution::WeightedPolygon_t polygon;
1364 polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
1365 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
1366 polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 47.6/180*M_PI), 1);
[e6ca85]1367 SphericalPointDistribution::Polygon_t expected =
[6aa6b7]1368 SPD.get<8>();
1369 expected.pop_front(); // remove first point
1370 expected.pop_front(); // remove second point
1371 expected.pop_front(); // remove third point
1372 for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
1373 iter != expected.end(); ++iter)
1374 *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
1375 SphericalPointDistribution::Polygon_t remaining =
[e6ca85]1376 SPD.getRemainingPoints(polygon, 8);
[a2f8a9]1377// CPPUNIT_ASSERT_EQUAL( expected, remaining );
1378 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
[3da643]1379 // also slightly perturbed
1380 const double amplitude = 0.05;
1381 perturbPolygon(polygon, amplitude);
1382 CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
[6aa6b7]1383 }
[11cc05]1384}
Note: See TracBrowser for help on using the repository browser.