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 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 | #include <cppunit/CompilerOutputter.h>
|
---|
38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
40 |
|
---|
41 | // include headers that implement a archive in simple text format
|
---|
42 | #include <boost/archive/text_oarchive.hpp>
|
---|
43 | #include <boost/archive/text_iarchive.hpp>
|
---|
44 |
|
---|
45 | #include "SphericalPointDistributionUnitTest.hpp"
|
---|
46 |
|
---|
47 | #include <boost/assign.hpp>
|
---|
48 | #include <boost/math/quaternion.hpp>
|
---|
49 |
|
---|
50 | #include "CodePatterns/Assert.hpp"
|
---|
51 | #include "CodePatterns/Log.hpp"
|
---|
52 |
|
---|
53 | #include "LinearAlgebra/Line.hpp"
|
---|
54 |
|
---|
55 | #include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
|
---|
56 |
|
---|
57 | #include "LinearAlgebra/Line.hpp"
|
---|
58 |
|
---|
59 | #ifdef HAVE_TESTRUNNER
|
---|
60 | #include "UnitTestMain.hpp"
|
---|
61 | #endif /*HAVE_TESTRUNNER*/
|
---|
62 |
|
---|
63 | using namespace boost::assign;
|
---|
64 |
|
---|
65 | /********************************************** Test classes **************************************/
|
---|
66 |
|
---|
67 | // Registers the fixture into the 'registry'
|
---|
68 | CPPUNIT_TEST_SUITE_REGISTRATION( SphericalPointDistributionTest );
|
---|
69 |
|
---|
70 |
|
---|
71 | void SphericalPointDistributionTest::setUp()
|
---|
72 | {
|
---|
73 | // failing asserts should be thrown
|
---|
74 | ASSERT_DO(Assert::Throw);
|
---|
75 |
|
---|
76 | setVerbosity(6);
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | void SphericalPointDistributionTest::tearDown()
|
---|
81 | {
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | /** UnitTest for matchSphericalPointDistributions() with two points
|
---|
86 | */
|
---|
87 | void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_2()
|
---|
88 | {
|
---|
89 | SphericalPointDistribution SPD(1.);
|
---|
90 | // test with one point, matching trivially
|
---|
91 | {
|
---|
92 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
93 | polygon += std::make_pair(Vector(1.,0.,0.), 1);
|
---|
94 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
95 | SPD.get<2>();
|
---|
96 | SphericalPointDistribution::Polygon_t expected;
|
---|
97 | expected += Vector(-1.,0.,0.);
|
---|
98 | SphericalPointDistribution::Polygon_t remaining =
|
---|
99 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
100 | polygon,
|
---|
101 | newpolygon);
|
---|
102 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
103 | }
|
---|
104 |
|
---|
105 | // test with one point, just a flip of axis
|
---|
106 | {
|
---|
107 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
108 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
---|
109 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
110 | SPD.get<2>();
|
---|
111 | SphericalPointDistribution::Polygon_t expected;
|
---|
112 | expected += Vector(0.,-1.,0.);
|
---|
113 | SphericalPointDistribution::Polygon_t remaining =
|
---|
114 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
115 | polygon,
|
---|
116 | newpolygon);
|
---|
117 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
118 | }
|
---|
119 |
|
---|
120 | // test with one point, just a flip to another axis
|
---|
121 | {
|
---|
122 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
123 | polygon += std::make_pair( Vector(0.,0.,-1.), 1);
|
---|
124 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
125 | SPD.get<2>();
|
---|
126 | SphericalPointDistribution::Polygon_t expected;
|
---|
127 | expected += Vector(0.,0.,1.);
|
---|
128 | SphericalPointDistribution::Polygon_t remaining =
|
---|
129 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
130 | polygon,
|
---|
131 | newpolygon);
|
---|
132 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
133 | }
|
---|
134 |
|
---|
135 | // test with one point, full rotation
|
---|
136 | {
|
---|
137 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
138 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
139 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
140 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
141 | SPD.get<2>();
|
---|
142 | SphericalPointDistribution::Polygon_t expected;
|
---|
143 | expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
|
---|
144 | SphericalPointDistribution::Polygon_t remaining =
|
---|
145 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
146 | polygon,
|
---|
147 | newpolygon);
|
---|
148 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | void perturbPolygon(
|
---|
153 | SphericalPointDistribution::WeightedPolygon_t &_polygon,
|
---|
154 | double _amplitude
|
---|
155 | )
|
---|
156 | {
|
---|
157 | for (SphericalPointDistribution::WeightedPolygon_t::iterator iter = _polygon.begin();
|
---|
158 | iter != _polygon.end(); ++iter) {
|
---|
159 | Vector perturber;
|
---|
160 | perturber.GetOneNormalVector(iter->first);
|
---|
161 | perturber.Scale(_amplitude);
|
---|
162 | iter->first = iter->first + perturber;
|
---|
163 | (iter->first).Normalize();
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | static
|
---|
168 | bool areEqualToWithinBounds(
|
---|
169 | const SphericalPointDistribution::Polygon_t &_polygon,
|
---|
170 | const SphericalPointDistribution::Polygon_t &_otherpolygon,
|
---|
171 | double _amplitude
|
---|
172 | )
|
---|
173 | {
|
---|
174 | // same size?
|
---|
175 | if (_polygon.size() != _otherpolygon.size())
|
---|
176 | return false;
|
---|
177 | // same points ? We just check witrh trivial mapping, nothing fancy ...
|
---|
178 | bool status = true;
|
---|
179 | SphericalPointDistribution::Polygon_t::const_iterator iter = _polygon.begin();
|
---|
180 | SphericalPointDistribution::Polygon_t::const_iterator otheriter = _otherpolygon.begin();
|
---|
181 | for (; iter != _polygon.end(); ++iter, ++otheriter) {
|
---|
182 | status &= (*iter - *otheriter).Norm() < _amplitude;
|
---|
183 | }
|
---|
184 | return status;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /** UnitTest for areEqualToWithinBounds()
|
---|
188 | */
|
---|
189 | void SphericalPointDistributionTest::areEqualToWithinBoundsTest()
|
---|
190 | {
|
---|
191 | // test with no points
|
---|
192 | {
|
---|
193 | SphericalPointDistribution::Polygon_t polygon;
|
---|
194 | SphericalPointDistribution::Polygon_t expected = polygon;
|
---|
195 | CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
|
---|
196 | }
|
---|
197 | // test with one point
|
---|
198 | {
|
---|
199 | SphericalPointDistribution::Polygon_t polygon;
|
---|
200 | polygon += Vector(1.,0.,0.);
|
---|
201 | SphericalPointDistribution::Polygon_t expected = polygon;
|
---|
202 | CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
|
---|
203 | }
|
---|
204 | // test with two points
|
---|
205 | {
|
---|
206 | SphericalPointDistribution::Polygon_t polygon;
|
---|
207 | polygon += Vector(1.,0.,0.);
|
---|
208 | polygon += Vector(0.,1.,0.);
|
---|
209 | SphericalPointDistribution::Polygon_t expected = polygon;
|
---|
210 | CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
|
---|
211 | }
|
---|
212 |
|
---|
213 | // test with two points in different order: THIS GOES WRONG: We only check trivially
|
---|
214 | {
|
---|
215 | SphericalPointDistribution::Polygon_t polygon;
|
---|
216 | polygon += Vector(1.,0.,0.);
|
---|
217 | polygon += Vector(0.,1.,0.);
|
---|
218 | SphericalPointDistribution::Polygon_t expected;
|
---|
219 | expected += Vector(0.,1.,0.);
|
---|
220 | expected += Vector(1.,0.,0.);
|
---|
221 | CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, std::numeric_limits<double>::epsilon()*1e2) );
|
---|
222 | }
|
---|
223 |
|
---|
224 | // test with two different points
|
---|
225 | {
|
---|
226 | SphericalPointDistribution::Polygon_t polygon;
|
---|
227 | polygon += Vector(1.,0.,0.);
|
---|
228 | polygon += Vector(0.,1.,0.);
|
---|
229 | SphericalPointDistribution::Polygon_t expected;
|
---|
230 | expected += Vector(1.01,0.,0.);
|
---|
231 | expected += Vector(0.,1.,0.);
|
---|
232 | CPPUNIT_ASSERT( areEqualToWithinBounds(polygon, expected, 0.05) );
|
---|
233 | CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.005) );
|
---|
234 | }
|
---|
235 |
|
---|
236 | // test with different number of points
|
---|
237 | {
|
---|
238 | SphericalPointDistribution::Polygon_t polygon;
|
---|
239 | polygon += Vector(1.,0.,0.);
|
---|
240 | polygon += Vector(0.,1.,0.);
|
---|
241 | SphericalPointDistribution::Polygon_t expected;
|
---|
242 | expected += Vector(0.,1.,0.);
|
---|
243 | CPPUNIT_ASSERT( !areEqualToWithinBounds(polygon, expected, 0.05) );
|
---|
244 | }
|
---|
245 | }
|
---|
246 |
|
---|
247 | /** UnitTest for joinPoints()
|
---|
248 | */
|
---|
249 | void SphericalPointDistributionTest::joinPointsTest()
|
---|
250 | {
|
---|
251 | // test with simple configuration of three points
|
---|
252 | {
|
---|
253 | SphericalPointDistribution::Polygon_t newpolygon;
|
---|
254 | newpolygon += Vector(1.,0.,0.);
|
---|
255 | newpolygon += Vector(0.,1.,0.);
|
---|
256 | newpolygon += Vector(0.,0.,1.);
|
---|
257 | SphericalPointDistribution::Polygon_t expectedpolygon = newpolygon;
|
---|
258 | SphericalPointDistribution::IndexTupleList_t matching;
|
---|
259 | matching += SphericalPointDistribution::IndexList_t(1,0);
|
---|
260 | matching += SphericalPointDistribution::IndexList_t(1,1);
|
---|
261 | matching += SphericalPointDistribution::IndexList_t(1,2);
|
---|
262 | SphericalPointDistribution::IndexList_t IndexList =
|
---|
263 | SphericalPointDistribution::joinPoints(
|
---|
264 | newpolygon,
|
---|
265 | SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
|
---|
266 | matching);
|
---|
267 | SphericalPointDistribution::IndexList_t expected;
|
---|
268 | expected += 0,1,2;
|
---|
269 | CPPUNIT_ASSERT_EQUAL( expected, IndexList );
|
---|
270 | CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
|
---|
271 | }
|
---|
272 |
|
---|
273 | // test with simple configuration of three points, only two are picked
|
---|
274 | {
|
---|
275 | SphericalPointDistribution::Polygon_t newpolygon;
|
---|
276 | newpolygon += Vector(1.,0.,0.);
|
---|
277 | newpolygon += Vector(0.,1.,0.);
|
---|
278 | newpolygon += Vector(0.,0.,1.);
|
---|
279 | SphericalPointDistribution::Polygon_t expectedpolygon = newpolygon;
|
---|
280 | SphericalPointDistribution::IndexTupleList_t matching;
|
---|
281 | matching += SphericalPointDistribution::IndexList_t(1,1);
|
---|
282 | matching += SphericalPointDistribution::IndexList_t(1,2);
|
---|
283 | SphericalPointDistribution::IndexList_t IndexList =
|
---|
284 | SphericalPointDistribution::joinPoints(
|
---|
285 | newpolygon,
|
---|
286 | SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
|
---|
287 | matching);
|
---|
288 | SphericalPointDistribution::IndexList_t expected;
|
---|
289 | expected += 1,2;
|
---|
290 | CPPUNIT_ASSERT_EQUAL( expected, IndexList );
|
---|
291 | CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
|
---|
292 | }
|
---|
293 |
|
---|
294 | // test with simple configuration of three points, two are joined
|
---|
295 | {
|
---|
296 | SphericalPointDistribution::Polygon_t newpolygon;
|
---|
297 | newpolygon += Vector(1.,0.,0.);
|
---|
298 | newpolygon += Vector(0.,1.,0.);
|
---|
299 | newpolygon += Vector(0.,0.,1.);
|
---|
300 | SphericalPointDistribution::Polygon_t expectedpolygon;
|
---|
301 | expectedpolygon += Vector(1.,0.,0.);
|
---|
302 | expectedpolygon += Vector(0.,M_SQRT1_2,M_SQRT1_2);
|
---|
303 | SphericalPointDistribution::IndexTupleList_t matching;
|
---|
304 | SphericalPointDistribution::IndexList_t joined;
|
---|
305 | joined += 1,2;
|
---|
306 | matching += SphericalPointDistribution::IndexList_t(1,0);
|
---|
307 | matching += joined;
|
---|
308 | SphericalPointDistribution::IndexList_t IndexList =
|
---|
309 | SphericalPointDistribution::joinPoints(
|
---|
310 | newpolygon,
|
---|
311 | SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
|
---|
312 | matching);
|
---|
313 | SphericalPointDistribution::IndexList_t expected;
|
---|
314 | expected += 0,1;
|
---|
315 | CPPUNIT_ASSERT_EQUAL( expected, IndexList );
|
---|
316 | CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
|
---|
317 | }
|
---|
318 |
|
---|
319 | // test with simple configuration of six points, two are joined, jumbled indices
|
---|
320 | {
|
---|
321 | SphericalPointDistribution::Polygon_t newpolygon;
|
---|
322 | newpolygon += Vector(1.,0.,1.);
|
---|
323 | newpolygon += Vector(1.,0.,0.);
|
---|
324 | newpolygon += Vector(1.,1.,0.);
|
---|
325 | newpolygon += Vector(0.,1.,0.);
|
---|
326 | newpolygon += Vector(0.,0.,1.);
|
---|
327 | newpolygon += Vector(1.,0.,1.);
|
---|
328 | SphericalPointDistribution::Polygon_t expectedpolygon;
|
---|
329 | expectedpolygon += Vector(1.,0.,1.);
|
---|
330 | expectedpolygon += Vector(1.,0.,0.);
|
---|
331 | expectedpolygon += Vector(1.,1.,0.);
|
---|
332 | expectedpolygon += Vector(1.,0.,1.);
|
---|
333 | expectedpolygon += Vector(0.,M_SQRT1_2,M_SQRT1_2); // new centers go last
|
---|
334 | SphericalPointDistribution::IndexTupleList_t matching;
|
---|
335 | SphericalPointDistribution::IndexList_t joined;
|
---|
336 | joined += 3,4;
|
---|
337 | matching += SphericalPointDistribution::IndexList_t(1,1);
|
---|
338 | matching += joined;
|
---|
339 | SphericalPointDistribution::IndexList_t IndexList =
|
---|
340 | SphericalPointDistribution::joinPoints(
|
---|
341 | newpolygon,
|
---|
342 | SphericalPointDistribution::VectorArray_t(newpolygon.begin(), newpolygon.end()),
|
---|
343 | matching);
|
---|
344 | SphericalPointDistribution::IndexList_t expected;
|
---|
345 | expected += 1,4;
|
---|
346 | CPPUNIT_ASSERT_EQUAL( expected, IndexList );
|
---|
347 | CPPUNIT_ASSERT_EQUAL( expectedpolygon, newpolygon );
|
---|
348 | }
|
---|
349 | }
|
---|
350 |
|
---|
351 | /** UnitTest for matchSphericalPointDistributions() with three points
|
---|
352 | */
|
---|
353 | void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_3()
|
---|
354 | {
|
---|
355 | SphericalPointDistribution SPD(1.);
|
---|
356 |
|
---|
357 | // test with one point, matching trivially
|
---|
358 | {
|
---|
359 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
360 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
361 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
362 | SPD.get<3>();
|
---|
363 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
364 | expected.pop_front(); // remove first point
|
---|
365 | SphericalPointDistribution::Polygon_t remaining =
|
---|
366 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
367 | polygon,
|
---|
368 | newpolygon);
|
---|
369 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
370 | }
|
---|
371 |
|
---|
372 | // test with one point, just a flip of x and y axis
|
---|
373 | {
|
---|
374 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
375 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
---|
376 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
377 | SPD.get<3>();
|
---|
378 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
379 | expected.pop_front(); // remove first point
|
---|
380 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
381 | iter != expected.end(); ++iter) {
|
---|
382 | std::swap((*iter)[0], (*iter)[1]);
|
---|
383 | (*iter)[0] *= -1.;
|
---|
384 | }
|
---|
385 | SphericalPointDistribution::Polygon_t remaining =
|
---|
386 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
387 | polygon,
|
---|
388 | newpolygon);
|
---|
389 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
390 | }
|
---|
391 |
|
---|
392 | // test with two points, matching trivially
|
---|
393 | {
|
---|
394 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
395 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
396 | polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
|
---|
397 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
398 | SPD.get<3>();
|
---|
399 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
400 | expected.pop_front(); // remove first point
|
---|
401 | expected.pop_front(); // remove second point
|
---|
402 | SphericalPointDistribution::Polygon_t remaining =
|
---|
403 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
404 | polygon,
|
---|
405 | newpolygon);
|
---|
406 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
407 | // also slightly perturbed
|
---|
408 | const double amplitude = 0.05;
|
---|
409 | perturbPolygon(polygon, amplitude);
|
---|
410 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
411 | }
|
---|
412 |
|
---|
413 | // test with two points, full rotation
|
---|
414 | {
|
---|
415 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
416 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
417 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
418 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
|
---|
419 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
420 | SPD.get<3>();
|
---|
421 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
422 | expected.pop_front(); // remove first point
|
---|
423 | expected.pop_front(); // remove second point
|
---|
424 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
425 | iter != expected.end(); ++iter)
|
---|
426 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
427 | SphericalPointDistribution::Polygon_t remaining =
|
---|
428 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
429 | polygon,
|
---|
430 | newpolygon);
|
---|
431 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
432 | // also slightly perturbed
|
---|
433 | const double amplitude = 0.05;
|
---|
434 | perturbPolygon(polygon, amplitude);
|
---|
435 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
436 | }
|
---|
437 |
|
---|
438 | // test with three points, matching trivially
|
---|
439 | {
|
---|
440 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
441 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
442 | polygon += std::make_pair( Vector(-0.5, sqrt(3)*0.5,0.), 1);
|
---|
443 | polygon += std::make_pair( Vector(-0.5, -sqrt(3)*0.5,0.), 1);
|
---|
444 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
445 | SPD.get<3>();
|
---|
446 | SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
|
---|
447 | SphericalPointDistribution::Polygon_t remaining =
|
---|
448 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
449 | polygon,
|
---|
450 | newpolygon);
|
---|
451 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
452 | // also slightly perturbed
|
---|
453 | const double amplitude = 0.05;
|
---|
454 | perturbPolygon(polygon, amplitude);
|
---|
455 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
456 | }
|
---|
457 |
|
---|
458 |
|
---|
459 | // test with three points, full rotation
|
---|
460 | {
|
---|
461 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
462 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
463 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
464 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
|
---|
465 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-0.5, -sqrt(3)*0.5,0.), 47.6/180*M_PI), 1);
|
---|
466 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
467 | SPD.get<3>();
|
---|
468 | SphericalPointDistribution::Polygon_t expected; // empty cause none are vacant
|
---|
469 | SphericalPointDistribution::Polygon_t remaining =
|
---|
470 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
471 | polygon,
|
---|
472 | newpolygon);
|
---|
473 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
474 | // also slightly perturbed
|
---|
475 | const double amplitude = 0.05;
|
---|
476 | perturbPolygon(polygon, amplitude);
|
---|
477 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
478 | }
|
---|
479 | }
|
---|
480 |
|
---|
481 | /** UnitTest for matchSphericalPointDistributions() with four points
|
---|
482 | */
|
---|
483 | void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_4()
|
---|
484 | {
|
---|
485 | SphericalPointDistribution SPD(1.);
|
---|
486 |
|
---|
487 | // test with one point, matching trivially
|
---|
488 | {
|
---|
489 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
490 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
491 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
492 | SPD.get<4>();
|
---|
493 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
494 | expected.pop_front(); // remove first point
|
---|
495 | SphericalPointDistribution::Polygon_t remaining =
|
---|
496 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
497 | polygon,
|
---|
498 | newpolygon);
|
---|
499 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
500 | }
|
---|
501 |
|
---|
502 | // test with one point, just a flip of axis
|
---|
503 | {
|
---|
504 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
505 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
---|
506 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
507 | SPD.get<4>();
|
---|
508 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
509 | expected.pop_front(); // remove first point
|
---|
510 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
511 | iter != expected.end(); ++iter) {
|
---|
512 | std::swap((*iter)[0], (*iter)[1]);
|
---|
513 | (*iter)[0] *= -1.;
|
---|
514 | }
|
---|
515 | SphericalPointDistribution::Polygon_t remaining =
|
---|
516 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
517 | polygon,
|
---|
518 | newpolygon);
|
---|
519 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
520 | }
|
---|
521 |
|
---|
522 | // test with two points, matching trivially
|
---|
523 | {
|
---|
524 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
525 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
526 | polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
|
---|
527 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
528 | SPD.get<4>();
|
---|
529 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
530 | expected.pop_front(); // remove first point
|
---|
531 | expected.pop_front(); // remove second point
|
---|
532 | SphericalPointDistribution::Polygon_t remaining =
|
---|
533 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
534 | polygon,
|
---|
535 | newpolygon);
|
---|
536 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
537 | // also slightly perturbed
|
---|
538 | const double amplitude = 0.05;
|
---|
539 | perturbPolygon(polygon, amplitude);
|
---|
540 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
541 | }
|
---|
542 |
|
---|
543 | // test with two points, matching trivially, also with slightly perturbed
|
---|
544 | {
|
---|
545 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
546 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
547 | polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
|
---|
548 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
549 | SPD.get<4>();
|
---|
550 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
551 | expected.pop_front(); // remove first point
|
---|
552 | expected.pop_front(); // remove second point
|
---|
553 | SphericalPointDistribution::Polygon_t remaining =
|
---|
554 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
555 | polygon,
|
---|
556 | newpolygon);
|
---|
557 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
558 | // also slightly perturbed
|
---|
559 | const double amplitude = 0.05;
|
---|
560 | perturbPolygon(polygon, amplitude);
|
---|
561 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
562 | }
|
---|
563 |
|
---|
564 | // test with two points, full rotation
|
---|
565 | {
|
---|
566 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
567 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
568 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
569 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
|
---|
570 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
571 | SPD.get<4>();
|
---|
572 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
573 | expected.pop_front(); // remove first point
|
---|
574 | expected.pop_front(); // remove second point
|
---|
575 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
576 | iter != expected.end(); ++iter)
|
---|
577 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
578 | SphericalPointDistribution::Polygon_t remaining =
|
---|
579 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
580 | polygon,
|
---|
581 | newpolygon);
|
---|
582 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
583 | // also slightly perturbed
|
---|
584 | const double amplitude = 0.05;
|
---|
585 | perturbPolygon(polygon, amplitude);
|
---|
586 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
587 | }
|
---|
588 |
|
---|
589 | // test with three points, matching trivially
|
---|
590 | {
|
---|
591 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
592 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
593 | polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 1);
|
---|
594 | polygon += std::make_pair( Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 1);
|
---|
595 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
596 | SPD.get<4>();
|
---|
597 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
598 | expected.pop_front(); // remove first point
|
---|
599 | expected.pop_front(); // remove second point
|
---|
600 | expected.pop_front(); // remove third point
|
---|
601 | SphericalPointDistribution::Polygon_t remaining =
|
---|
602 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
603 | polygon,
|
---|
604 | newpolygon);
|
---|
605 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
606 | // also slightly perturbed
|
---|
607 | const double amplitude = 0.05;
|
---|
608 | perturbPolygon(polygon, amplitude);
|
---|
609 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
610 | }
|
---|
611 |
|
---|
612 | // test with three points, full rotation
|
---|
613 | {
|
---|
614 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
615 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
616 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
617 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0,0.), 47.6/180*M_PI), 1);
|
---|
618 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, -M_SQRT2/3.0, M_SQRT2/sqrt(3)), 47.6/180*M_PI), 1);
|
---|
619 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
620 | SPD.get<4>();
|
---|
621 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
622 | expected.pop_front(); // remove first point
|
---|
623 | expected.pop_front(); // remove second point
|
---|
624 | expected.pop_front(); // remove third point
|
---|
625 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
626 | iter != expected.end(); ++iter)
|
---|
627 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
628 | SphericalPointDistribution::Polygon_t remaining =
|
---|
629 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
630 | polygon,
|
---|
631 | newpolygon);
|
---|
632 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
633 | // also slightly perturbed
|
---|
634 | const double amplitude = 0.05;
|
---|
635 | perturbPolygon(polygon, amplitude);
|
---|
636 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
637 | }
|
---|
638 | }
|
---|
639 |
|
---|
640 | /** UnitTest for matchSphericalPointDistributions() with five points
|
---|
641 | */
|
---|
642 | void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_5()
|
---|
643 | {
|
---|
644 | SphericalPointDistribution SPD(1.);
|
---|
645 |
|
---|
646 | // test with one point, matching trivially
|
---|
647 | {
|
---|
648 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
649 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
650 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
651 | SPD.get<5>();
|
---|
652 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
653 | expected.pop_front(); // remove first point
|
---|
654 | SphericalPointDistribution::Polygon_t remaining =
|
---|
655 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
656 | polygon,
|
---|
657 | newpolygon);
|
---|
658 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
659 | }
|
---|
660 |
|
---|
661 | // test with one point, just a flip of axis
|
---|
662 | {
|
---|
663 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
664 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
---|
665 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
666 | SPD.get<5>();
|
---|
667 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
668 | expected.pop_front(); // remove first point
|
---|
669 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
670 | iter != expected.end(); ++iter) {
|
---|
671 | std::swap((*iter)[0], (*iter)[1]);
|
---|
672 | (*iter)[0] *= -1.;
|
---|
673 | }
|
---|
674 | SphericalPointDistribution::Polygon_t remaining =
|
---|
675 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
676 | polygon,
|
---|
677 | newpolygon);
|
---|
678 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
679 | }
|
---|
680 |
|
---|
681 | // test with two points, matching trivially
|
---|
682 | {
|
---|
683 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
684 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
685 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
---|
686 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
687 | SPD.get<5>();
|
---|
688 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
689 | expected.pop_front(); // remove first point
|
---|
690 | expected.pop_front(); // remove second point
|
---|
691 | SphericalPointDistribution::Polygon_t remaining =
|
---|
692 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
693 | polygon,
|
---|
694 | newpolygon);
|
---|
695 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
696 | // also slightly perturbed
|
---|
697 | const double amplitude = 0.05;
|
---|
698 | perturbPolygon(polygon, amplitude);
|
---|
699 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
700 | }
|
---|
701 |
|
---|
702 | // test with two points, full rotation
|
---|
703 | {
|
---|
704 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
705 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
706 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180.*M_PI), 1);
|
---|
707 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180.*M_PI), 1);
|
---|
708 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
709 | SPD.get<5>();
|
---|
710 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
711 | expected.pop_front(); // remove first point
|
---|
712 | expected.pop_front(); // remove second point
|
---|
713 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
714 | iter != expected.end(); ++iter)
|
---|
715 | *iter = RotationAxis.rotateVector(*iter, 47.6/180.*M_PI);
|
---|
716 | SphericalPointDistribution::Polygon_t remaining =
|
---|
717 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
718 | polygon,
|
---|
719 | newpolygon);
|
---|
720 | // the three remaining points sit on a plane that may be rotated arbitrarily
|
---|
721 | // so we cannot simply check for equality between expected and remaining
|
---|
722 | // hence, we just check that they are orthogonal to the first two points
|
---|
723 | CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
|
---|
724 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
---|
725 | fixiter != polygon.end(); ++fixiter) {
|
---|
726 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
---|
727 | iter != remaining.end(); ++iter) {
|
---|
728 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
---|
729 | }
|
---|
730 | }
|
---|
731 | }
|
---|
732 |
|
---|
733 | // test with three points, matching trivially
|
---|
734 | {
|
---|
735 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
736 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
737 | polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
|
---|
738 | polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
|
---|
739 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
740 | SPD.get<5>();
|
---|
741 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
742 | expected.pop_front(); // remove first point
|
---|
743 | expected.pop_front(); // remove second point
|
---|
744 | expected.pop_front(); // remove third point
|
---|
745 | SphericalPointDistribution::Polygon_t remaining =
|
---|
746 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
747 | polygon,
|
---|
748 | newpolygon);
|
---|
749 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
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 three 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., 0.0, 0.0), 47.6/180*M_PI), 1);
|
---|
762 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
|
---|
763 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
764 | SPD.get<5>();
|
---|
765 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
766 | expected.pop_front(); // remove first point
|
---|
767 | expected.pop_front(); // remove second point
|
---|
768 | expected.pop_front(); // remove third point
|
---|
769 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
770 | iter != expected.end(); ++iter)
|
---|
771 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
772 | SphericalPointDistribution::Polygon_t remaining =
|
---|
773 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
774 | polygon,
|
---|
775 | newpolygon);
|
---|
776 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
777 | // also slightly perturbed
|
---|
778 | const double amplitude = 0.05;
|
---|
779 | perturbPolygon(polygon, amplitude);
|
---|
780 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
781 | }
|
---|
782 | }
|
---|
783 |
|
---|
784 | /** UnitTest for matchSphericalPointDistributions() with six points
|
---|
785 | */
|
---|
786 | void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_6()
|
---|
787 | {
|
---|
788 | SphericalPointDistribution SPD(1.);
|
---|
789 |
|
---|
790 | // test with one point, matching trivially
|
---|
791 | {
|
---|
792 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
793 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
794 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
795 | SPD.get<6>();
|
---|
796 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
797 | expected.pop_front(); // remove first point
|
---|
798 | SphericalPointDistribution::Polygon_t remaining =
|
---|
799 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
800 | polygon,
|
---|
801 | newpolygon);
|
---|
802 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
803 | }
|
---|
804 |
|
---|
805 | // test with one point, just a flip of axis
|
---|
806 | {
|
---|
807 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
808 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
---|
809 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
810 | SPD.get<6>();
|
---|
811 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
812 | expected.pop_front(); // remove first point
|
---|
813 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
814 | iter != expected.end(); ++iter) {
|
---|
815 | std::swap((*iter)[0], (*iter)[1]);
|
---|
816 | (*iter)[0] *= -1.;
|
---|
817 | }
|
---|
818 | SphericalPointDistribution::Polygon_t remaining =
|
---|
819 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
820 | polygon,
|
---|
821 | newpolygon);
|
---|
822 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
823 | }
|
---|
824 |
|
---|
825 | // test with two points, matching trivially
|
---|
826 | {
|
---|
827 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
828 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
829 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
---|
830 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
831 | SPD.get<6>();
|
---|
832 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
833 | expected.pop_front(); // remove first point
|
---|
834 | expected.pop_front(); // remove second spoint
|
---|
835 | SphericalPointDistribution::Polygon_t remaining =
|
---|
836 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
837 | polygon,
|
---|
838 | newpolygon);
|
---|
839 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
840 | // also slightly perturbed
|
---|
841 | const double amplitude = 0.05;
|
---|
842 | perturbPolygon(polygon, amplitude);
|
---|
843 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
844 | }
|
---|
845 |
|
---|
846 | // test with two points, full rotation
|
---|
847 | {
|
---|
848 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
849 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
850 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
851 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
852 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
853 | SPD.get<6>();
|
---|
854 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
855 | expected.pop_front(); // remove first point
|
---|
856 | expected.pop_front(); // remove second spoint
|
---|
857 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
858 | iter != expected.end(); ++iter)
|
---|
859 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
860 | SphericalPointDistribution::Polygon_t remaining =
|
---|
861 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
862 | polygon,
|
---|
863 | newpolygon);
|
---|
864 | // the four remaining points sit on a plane that may have been rotated arbitrarily
|
---|
865 | // so we cannot simply check for equality between expected and remaining
|
---|
866 | // hence, we just check that they are orthogonal to the first two points
|
---|
867 | CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
|
---|
868 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
---|
869 | fixiter != polygon.end(); ++fixiter) {
|
---|
870 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
---|
871 | iter != remaining.end(); ++iter) {
|
---|
872 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
---|
873 | }
|
---|
874 | }
|
---|
875 | }
|
---|
876 |
|
---|
877 | // test with three points, matching trivially
|
---|
878 | {
|
---|
879 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
880 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
881 | polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
|
---|
882 | polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
|
---|
883 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
884 | SPD.get<6>();
|
---|
885 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
886 | expected.pop_front(); // remove first point
|
---|
887 | expected.pop_front(); // remove second point
|
---|
888 | expected.pop_front(); // remove third point
|
---|
889 | SphericalPointDistribution::Polygon_t remaining =
|
---|
890 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
891 | polygon,
|
---|
892 | newpolygon);
|
---|
893 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
894 | // also slightly perturbed
|
---|
895 | const double amplitude = 0.05;
|
---|
896 | perturbPolygon(polygon, amplitude);
|
---|
897 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
898 | }
|
---|
899 |
|
---|
900 | // test with three points, full rotation
|
---|
901 | {
|
---|
902 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
903 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
904 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
905 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
|
---|
906 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
|
---|
907 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
908 | SPD.get<6>();
|
---|
909 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
910 | expected.pop_front(); // remove first point
|
---|
911 | expected.pop_front(); // remove second point
|
---|
912 | expected.pop_front(); // remove third point
|
---|
913 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
914 | iter != expected.end(); ++iter)
|
---|
915 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
916 | SphericalPointDistribution::Polygon_t remaining =
|
---|
917 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
918 | polygon,
|
---|
919 | newpolygon);
|
---|
920 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
921 | // also slightly perturbed
|
---|
922 | const double amplitude = 0.05;
|
---|
923 | perturbPolygon(polygon, amplitude);
|
---|
924 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
925 | }
|
---|
926 | }
|
---|
927 |
|
---|
928 | /** UnitTest for matchSphericalPointDistributions() with seven points
|
---|
929 | */
|
---|
930 | void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_7()
|
---|
931 | {
|
---|
932 | SphericalPointDistribution SPD(1.);
|
---|
933 |
|
---|
934 | // test with one point, matching trivially
|
---|
935 | {
|
---|
936 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
937 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
938 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
939 | SPD.get<7>();
|
---|
940 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
941 | expected.pop_front(); // remove first point
|
---|
942 | SphericalPointDistribution::Polygon_t remaining =
|
---|
943 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
944 | polygon,
|
---|
945 | newpolygon);
|
---|
946 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
947 | }
|
---|
948 |
|
---|
949 | // test with one point, just a flip of axis
|
---|
950 | {
|
---|
951 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
952 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
---|
953 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
954 | SPD.get<7>();
|
---|
955 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
956 | expected.pop_front(); // remove first point
|
---|
957 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
958 | iter != expected.end(); ++iter) {
|
---|
959 | std::swap((*iter)[0], (*iter)[1]);
|
---|
960 | (*iter)[0] *= -1.;
|
---|
961 | }
|
---|
962 | SphericalPointDistribution::Polygon_t remaining =
|
---|
963 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
964 | polygon,
|
---|
965 | newpolygon);
|
---|
966 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
967 | }
|
---|
968 |
|
---|
969 | // test with two points, matching trivially
|
---|
970 | {
|
---|
971 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
972 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
973 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
---|
974 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
975 | SPD.get<7>();
|
---|
976 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
977 | expected.pop_front(); // remove first point
|
---|
978 | expected.pop_front(); // remove second point
|
---|
979 | SphericalPointDistribution::Polygon_t remaining =
|
---|
980 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
981 | polygon,
|
---|
982 | newpolygon);
|
---|
983 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
984 | // also slightly perturbed
|
---|
985 | const double amplitude = 0.05;
|
---|
986 | perturbPolygon(polygon, amplitude);
|
---|
987 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
988 | }
|
---|
989 |
|
---|
990 | // test with two points, full rotation
|
---|
991 | {
|
---|
992 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
993 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
994 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
995 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
996 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
997 | SPD.get<7>();
|
---|
998 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
999 | expected.pop_front(); // remove first point
|
---|
1000 | expected.pop_front(); // remove second point
|
---|
1001 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
1002 | iter != expected.end(); ++iter)
|
---|
1003 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
1004 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1005 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1006 | polygon,
|
---|
1007 | newpolygon);
|
---|
1008 | // the five remaining points sit on a plane that may have been rotated arbitrarily
|
---|
1009 | // so we cannot simply check for equality between expected and remaining
|
---|
1010 | // hence, we just check that they are orthogonal to the first two points
|
---|
1011 | CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
|
---|
1012 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
---|
1013 | fixiter != polygon.end(); ++fixiter) {
|
---|
1014 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
---|
1015 | iter != remaining.end(); ++iter) {
|
---|
1016 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | // test with three points, matching trivially
|
---|
1022 | {
|
---|
1023 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
1024 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
1025 | polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
|
---|
1026 | polygon += std::make_pair( Vector(0.0, 1., 0.0), 1);
|
---|
1027 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
1028 | SPD.get<7>();
|
---|
1029 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
1030 | expected.pop_front(); // remove first point
|
---|
1031 | expected.pop_front(); // remove second point
|
---|
1032 | expected.pop_front(); // remove third point
|
---|
1033 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1034 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1035 | polygon,
|
---|
1036 | newpolygon);
|
---|
1037 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
1038 | // also slightly perturbed
|
---|
1039 | const double amplitude = 0.05;
|
---|
1040 | perturbPolygon(polygon, amplitude);
|
---|
1041 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | // test with three points, full rotation
|
---|
1045 | {
|
---|
1046 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
1047 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
1048 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
1049 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
|
---|
1050 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(0.0, 1., 0.0), 47.6/180*M_PI), 1);
|
---|
1051 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
1052 | SPD.get<7>();
|
---|
1053 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
1054 | expected.pop_front(); // remove first point
|
---|
1055 | expected.pop_front(); // remove second point
|
---|
1056 | expected.pop_front(); // remove third point
|
---|
1057 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
1058 | iter != expected.end(); ++iter)
|
---|
1059 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
1060 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1061 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1062 | polygon,
|
---|
1063 | newpolygon);
|
---|
1064 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
1065 | // also slightly perturbed
|
---|
1066 | const double amplitude = 0.05;
|
---|
1067 | perturbPolygon(polygon, amplitude);
|
---|
1068 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
1069 | }
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | /** UnitTest for matchSphericalPointDistributions() with eight points
|
---|
1073 | */
|
---|
1074 | void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_8()
|
---|
1075 | {
|
---|
1076 | SphericalPointDistribution SPD(1.);
|
---|
1077 |
|
---|
1078 | // test with one point, matching trivially
|
---|
1079 | {
|
---|
1080 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
1081 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
1082 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
1083 | SPD.get<8>();
|
---|
1084 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
1085 | expected.pop_front(); // remove first point
|
---|
1086 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1087 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1088 | polygon,
|
---|
1089 | newpolygon);
|
---|
1090 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | // test with one point, just a flip of axis
|
---|
1094 | {
|
---|
1095 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
1096 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
---|
1097 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
1098 | SPD.get<8>();
|
---|
1099 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
1100 | expected.pop_front(); // remove first point
|
---|
1101 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
1102 | iter != expected.end(); ++iter) {
|
---|
1103 | std::swap((*iter)[0], (*iter)[1]);
|
---|
1104 | (*iter)[0] *= -1.;
|
---|
1105 | }
|
---|
1106 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1107 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1108 | polygon,
|
---|
1109 | newpolygon);
|
---|
1110 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | // test with two points, matching trivially
|
---|
1114 | {
|
---|
1115 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
1116 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
1117 | polygon += std::make_pair( Vector(-1.,0.,0.), 1);
|
---|
1118 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
1119 | SPD.get<8>();
|
---|
1120 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
1121 | expected.pop_front(); // remove first point
|
---|
1122 | expected.pop_front(); // remove second point
|
---|
1123 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1124 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1125 | polygon,
|
---|
1126 | newpolygon);
|
---|
1127 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
1128 | // also slightly perturbed
|
---|
1129 | const double amplitude = 0.05;
|
---|
1130 | perturbPolygon(polygon, amplitude);
|
---|
1131 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | // test with two points, full rotation
|
---|
1135 | {
|
---|
1136 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
1137 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
1138 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
1139 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
1140 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
1141 | SPD.get<8>();
|
---|
1142 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
1143 | expected.pop_front(); // remove first point
|
---|
1144 | expected.pop_front(); // remove second point
|
---|
1145 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
1146 | iter != expected.end(); ++iter)
|
---|
1147 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
1148 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1149 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1150 | polygon,
|
---|
1151 | newpolygon);
|
---|
1152 | // the six remaining points sit on two planes that may have been rotated arbitrarily
|
---|
1153 | // so we cannot simply check for equality between expected and remaining
|
---|
1154 | // hence, we just check that they are orthogonal to the first two points
|
---|
1155 | CPPUNIT_ASSERT_EQUAL( expected.size(), remaining.size() );
|
---|
1156 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
---|
1157 | fixiter != polygon.end(); ++fixiter) {
|
---|
1158 | SphericalPointDistribution::Polygon_t::const_iterator expectiter = expected.begin();
|
---|
1159 | SphericalPointDistribution::Polygon_t::const_iterator remainiter = remaining.begin();
|
---|
1160 | for (;remainiter != remaining.end(); ++expectiter, ++remainiter) {
|
---|
1161 | // check that points in expected/remaining have same angle to the given ones
|
---|
1162 | // CPPUNIT_ASSERT_EQUAL( (*expectiter).Angle(*fixiter), (*remainiter).Angle(*fixiter) );
|
---|
1163 | CPPUNIT_ASSERT( fabs( (*expectiter).Angle(fixiter->first) - (*remainiter).Angle(fixiter->first) )
|
---|
1164 | < std::numeric_limits<double>::epsilon()*1e4 );
|
---|
1165 | }
|
---|
1166 | }
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | // test with three points, matching trivially
|
---|
1170 | {
|
---|
1171 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
1172 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
---|
1173 | polygon += std::make_pair( Vector(-1., 0.0, 0.0), 1);
|
---|
1174 | polygon += std::make_pair( Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 1);
|
---|
1175 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
1176 | SPD.get<8>();
|
---|
1177 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
1178 | expected.pop_front(); // remove first point
|
---|
1179 | expected.pop_front(); // remove second point
|
---|
1180 | expected.pop_front(); // remove third point
|
---|
1181 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1182 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1183 | polygon,
|
---|
1184 | newpolygon);
|
---|
1185 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
1186 | // also slightly perturbed
|
---|
1187 | const double amplitude = 0.05;
|
---|
1188 | perturbPolygon(polygon, amplitude);
|
---|
1189 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
1190 | }
|
---|
1191 |
|
---|
1192 | // test with three points, full rotation
|
---|
1193 | {
|
---|
1194 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
---|
1195 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
---|
1196 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
---|
1197 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1., 0.0, 0.0), 47.6/180*M_PI), 1);
|
---|
1198 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(-1./3.0, 2.0*M_SQRT2/3.0, 0.0), 47.6/180*M_PI), 1);
|
---|
1199 | SphericalPointDistribution::Polygon_t newpolygon =
|
---|
1200 | SPD.get<8>();
|
---|
1201 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
---|
1202 | expected.pop_front(); // remove first point
|
---|
1203 | expected.pop_front(); // remove second point
|
---|
1204 | expected.pop_front(); // remove third point
|
---|
1205 | for (SphericalPointDistribution::Polygon_t::iterator iter = expected.begin();
|
---|
1206 | iter != expected.end(); ++iter)
|
---|
1207 | *iter = RotationAxis.rotateVector(*iter, 47.6/180*M_PI);
|
---|
1208 | SphericalPointDistribution::Polygon_t remaining =
|
---|
1209 | SphericalPointDistribution::matchSphericalPointDistributions(
|
---|
1210 | polygon,
|
---|
1211 | newpolygon);
|
---|
1212 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
---|
1213 | // also slightly perturbed
|
---|
1214 | const double amplitude = 0.05;
|
---|
1215 | perturbPolygon(polygon, amplitude);
|
---|
1216 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
---|
1217 | }
|
---|
1218 | }
|
---|