| [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 |
|
|---|
| 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>
|
|---|
| [0ae114] | 48 | #include <boost/math/quaternion.hpp>
|
|---|
| [11cc05] | 49 |
|
|---|
| 50 | #include "CodePatterns/Assert.hpp"
|
|---|
| [d734ff] | 51 | #include "CodePatterns/Log.hpp"
|
|---|
| [11cc05] | 52 |
|
|---|
| [0ae114] | 53 | #include "LinearAlgebra/Line.hpp"
|
|---|
| 54 |
|
|---|
| [11cc05] | 55 | #include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
|
|---|
| 56 |
|
|---|
| [a39f66] | 57 | #include "LinearAlgebra/Line.hpp"
|
|---|
| 58 |
|
|---|
| [11cc05] | 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);
|
|---|
| [d734ff] | 75 |
|
|---|
| [6aa6b7] | 76 | setVerbosity(6);
|
|---|
| [11cc05] | 77 | }
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | void SphericalPointDistributionTest::tearDown()
|
|---|
| 81 | {
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| [0ae114] | 84 |
|
|---|
| [11cc05] | 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 | {
|
|---|
| [260540] | 92 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 93 | polygon += std::make_pair(Vector(1.,0.,0.), 1);
|
|---|
| [11cc05] | 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 | {
|
|---|
| [260540] | 107 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 108 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| [11cc05] | 109 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 110 | SPD.get<2>();
|
|---|
| 111 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 122 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 123 | polygon += std::make_pair( Vector(0.,0.,-1.), 1);
|
|---|
| [d734ff] | 124 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 125 | SPD.get<2>();
|
|---|
| 126 | SphericalPointDistribution::Polygon_t expected;
|
|---|
| 127 | expected += Vector(0.,0.,1.);
|
|---|
| [11cc05] | 128 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 129 | SphericalPointDistribution::matchSphericalPointDistributions(
|
|---|
| 130 | polygon,
|
|---|
| 131 | newpolygon);
|
|---|
| 132 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 133 | }
|
|---|
| [0ae114] | 134 |
|
|---|
| 135 | // test with one point, full rotation
|
|---|
| 136 | {
|
|---|
| 137 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 138 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 139 | polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
|
|---|
| [0ae114] | 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 | }
|
|---|
| [11cc05] | 150 | }
|
|---|
| 151 |
|
|---|
| [3da643] | 152 | void perturbPolygon(
|
|---|
| [260540] | 153 | SphericalPointDistribution::WeightedPolygon_t &_polygon,
|
|---|
| [3da643] | 154 | double _amplitude
|
|---|
| 155 | )
|
|---|
| 156 | {
|
|---|
| [260540] | 157 | for (SphericalPointDistribution::WeightedPolygon_t::iterator iter = _polygon.begin();
|
|---|
| [3da643] | 158 | iter != _polygon.end(); ++iter) {
|
|---|
| 159 | Vector perturber;
|
|---|
| [260540] | 160 | perturber.GetOneNormalVector(iter->first);
|
|---|
| [3da643] | 161 | perturber.Scale(_amplitude);
|
|---|
| [260540] | 162 | iter->first = iter->first + perturber;
|
|---|
| 163 | (iter->first).Normalize();
|
|---|
| [3da643] | 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 |
|
|---|
| [1ae9aa] | 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 | }
|
|---|
| [3da643] | 350 |
|
|---|
| [11cc05] | 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 | {
|
|---|
| [260540] | 359 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 360 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| [11cc05] | 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 | }
|
|---|
| [d734ff] | 371 |
|
|---|
| [0ae114] | 372 | // test with one point, just a flip of x and y axis
|
|---|
| [d734ff] | 373 | {
|
|---|
| [260540] | 374 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 375 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| [d734ff] | 376 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 377 | SPD.get<3>();
|
|---|
| 378 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
|---|
| 379 | expected.pop_front(); // remove first point
|
|---|
| [0ae114] | 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 | }
|
|---|
| [d734ff] | 385 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 386 | SphericalPointDistribution::matchSphericalPointDistributions(
|
|---|
| 387 | polygon,
|
|---|
| 388 | newpolygon);
|
|---|
| 389 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 390 | }
|
|---|
| [6aa6b7] | 391 |
|
|---|
| 392 | // test with two points, matching trivially
|
|---|
| 393 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 407 | // also slightly perturbed
|
|---|
| 408 | const double amplitude = 0.05;
|
|---|
| 409 | perturbPolygon(polygon, amplitude);
|
|---|
| 410 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 411 | }
|
|---|
| 412 |
|
|---|
| 413 | // test with two points, full rotation
|
|---|
| 414 | {
|
|---|
| 415 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 432 | // also slightly perturbed
|
|---|
| 433 | const double amplitude = 0.05;
|
|---|
| 434 | perturbPolygon(polygon, amplitude);
|
|---|
| 435 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 436 | }
|
|---|
| 437 |
|
|---|
| 438 | // test with three points, matching trivially
|
|---|
| 439 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 452 | // also slightly perturbed
|
|---|
| 453 | const double amplitude = 0.05;
|
|---|
| 454 | perturbPolygon(polygon, amplitude);
|
|---|
| 455 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 456 | }
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 | // test with three points, full rotation
|
|---|
| 460 | {
|
|---|
| 461 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 474 | // also slightly perturbed
|
|---|
| 475 | const double amplitude = 0.05;
|
|---|
| 476 | perturbPolygon(polygon, amplitude);
|
|---|
| 477 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 478 | }
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 489 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 490 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 504 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 505 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| [d734ff] | 506 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 507 | SPD.get<4>();
|
|---|
| 508 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
|---|
| 509 | expected.pop_front(); // remove first point
|
|---|
| [0ae114] | 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 | }
|
|---|
| [d734ff] | 515 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 516 | SphericalPointDistribution::matchSphericalPointDistributions(
|
|---|
| 517 | polygon,
|
|---|
| 518 | newpolygon);
|
|---|
| 519 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 520 | }
|
|---|
| [6aa6b7] | 521 |
|
|---|
| 522 | // test with two points, matching trivially
|
|---|
| 523 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 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 | {
|
|---|
| [260540] | 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);
|
|---|
| [3da643] | 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) );
|
|---|
| [6aa6b7] | 562 | }
|
|---|
| 563 |
|
|---|
| 564 | // test with two points, full rotation
|
|---|
| 565 | {
|
|---|
| 566 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 583 | // also slightly perturbed
|
|---|
| 584 | const double amplitude = 0.05;
|
|---|
| 585 | perturbPolygon(polygon, amplitude);
|
|---|
| 586 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 587 | }
|
|---|
| 588 |
|
|---|
| 589 | // test with three points, matching trivially
|
|---|
| 590 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 606 | // also slightly perturbed
|
|---|
| 607 | const double amplitude = 0.05;
|
|---|
| 608 | perturbPolygon(polygon, amplitude);
|
|---|
| 609 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 610 | }
|
|---|
| 611 |
|
|---|
| 612 | // test with three points, full rotation
|
|---|
| 613 | {
|
|---|
| 614 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 633 | // also slightly perturbed
|
|---|
| 634 | const double amplitude = 0.05;
|
|---|
| 635 | perturbPolygon(polygon, amplitude);
|
|---|
| 636 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 637 | }
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 648 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 649 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 663 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 664 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| [d734ff] | 665 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 666 | SPD.get<5>();
|
|---|
| 667 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
|---|
| 668 | expected.pop_front(); // remove first point
|
|---|
| [0ae114] | 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 | }
|
|---|
| [d734ff] | 674 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 675 | SphericalPointDistribution::matchSphericalPointDistributions(
|
|---|
| 676 | polygon,
|
|---|
| 677 | newpolygon);
|
|---|
| 678 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 679 | }
|
|---|
| [6aa6b7] | 680 |
|
|---|
| 681 | // test with two points, matching trivially
|
|---|
| 682 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 696 | // also slightly perturbed
|
|---|
| 697 | const double amplitude = 0.05;
|
|---|
| 698 | perturbPolygon(polygon, amplitude);
|
|---|
| 699 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 700 | }
|
|---|
| 701 |
|
|---|
| 702 | // test with two points, full rotation
|
|---|
| 703 | {
|
|---|
| 704 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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() );
|
|---|
| [260540] | 724 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
|---|
| [6aa6b7] | 725 | fixiter != polygon.end(); ++fixiter) {
|
|---|
| 726 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
|---|
| 727 | iter != remaining.end(); ++iter) {
|
|---|
| [260540] | 728 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
|---|
| [6aa6b7] | 729 | }
|
|---|
| 730 | }
|
|---|
| 731 | }
|
|---|
| 732 |
|
|---|
| 733 | // test with three points, matching trivially
|
|---|
| 734 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [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., 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 777 | // also slightly perturbed
|
|---|
| 778 | const double amplitude = 0.05;
|
|---|
| 779 | perturbPolygon(polygon, amplitude);
|
|---|
| 780 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 781 | }
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 792 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 793 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 807 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 808 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| [d734ff] | 809 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 810 | SPD.get<6>();
|
|---|
| 811 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
|---|
| 812 | expected.pop_front(); // remove first point
|
|---|
| [0ae114] | 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 | }
|
|---|
| [d734ff] | 818 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 819 | SphericalPointDistribution::matchSphericalPointDistributions(
|
|---|
| 820 | polygon,
|
|---|
| 821 | newpolygon);
|
|---|
| 822 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 823 | }
|
|---|
| [6aa6b7] | 824 |
|
|---|
| 825 | // test with two points, matching trivially
|
|---|
| 826 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 840 | // also slightly perturbed
|
|---|
| 841 | const double amplitude = 0.05;
|
|---|
| 842 | perturbPolygon(polygon, amplitude);
|
|---|
| 843 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 844 | }
|
|---|
| 845 |
|
|---|
| 846 | // test with two points, full rotation
|
|---|
| 847 | {
|
|---|
| 848 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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() );
|
|---|
| [260540] | 868 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
|---|
| [6aa6b7] | 869 | fixiter != polygon.end(); ++fixiter) {
|
|---|
| 870 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
|---|
| 871 | iter != remaining.end(); ++iter) {
|
|---|
| [260540] | 872 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
|---|
| [6aa6b7] | 873 | }
|
|---|
| 874 | }
|
|---|
| 875 | }
|
|---|
| 876 |
|
|---|
| 877 | // test with three points, matching trivially
|
|---|
| 878 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 894 | // also slightly perturbed
|
|---|
| 895 | const double amplitude = 0.05;
|
|---|
| 896 | perturbPolygon(polygon, amplitude);
|
|---|
| 897 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 898 | }
|
|---|
| 899 |
|
|---|
| 900 | // test with three points, full rotation
|
|---|
| 901 | {
|
|---|
| 902 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 921 | // also slightly perturbed
|
|---|
| 922 | const double amplitude = 0.05;
|
|---|
| 923 | perturbPolygon(polygon, amplitude);
|
|---|
| 924 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 925 | }
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 936 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 937 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 951 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 952 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| [d734ff] | 953 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 954 | SPD.get<7>();
|
|---|
| 955 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
|---|
| 956 | expected.pop_front(); // remove first point
|
|---|
| [0ae114] | 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 | }
|
|---|
| [d734ff] | 962 | SphericalPointDistribution::Polygon_t remaining =
|
|---|
| 963 | SphericalPointDistribution::matchSphericalPointDistributions(
|
|---|
| 964 | polygon,
|
|---|
| 965 | newpolygon);
|
|---|
| 966 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 967 | }
|
|---|
| [6aa6b7] | 968 |
|
|---|
| 969 | // test with two points, matching trivially
|
|---|
| 970 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 984 | // also slightly perturbed
|
|---|
| 985 | const double amplitude = 0.05;
|
|---|
| 986 | perturbPolygon(polygon, amplitude);
|
|---|
| 987 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 988 | }
|
|---|
| 989 |
|
|---|
| 990 | // test with two points, full rotation
|
|---|
| 991 | {
|
|---|
| 992 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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() );
|
|---|
| [260540] | 1012 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
|---|
| [6aa6b7] | 1013 | fixiter != polygon.end(); ++fixiter) {
|
|---|
| 1014 | for (SphericalPointDistribution::Polygon_t::const_iterator iter = remaining.begin();
|
|---|
| 1015 | iter != remaining.end(); ++iter) {
|
|---|
| [260540] | 1016 | CPPUNIT_ASSERT( (fixiter->first).IsNormalTo(*iter) );
|
|---|
| [6aa6b7] | 1017 | }
|
|---|
| 1018 | }
|
|---|
| 1019 | }
|
|---|
| 1020 |
|
|---|
| 1021 | // test with three points, matching trivially
|
|---|
| 1022 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 1038 | // also slightly perturbed
|
|---|
| 1039 | const double amplitude = 0.05;
|
|---|
| 1040 | perturbPolygon(polygon, amplitude);
|
|---|
| 1041 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 1042 | }
|
|---|
| 1043 |
|
|---|
| 1044 | // test with three points, full rotation
|
|---|
| 1045 | {
|
|---|
| 1046 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 1065 | // also slightly perturbed
|
|---|
| 1066 | const double amplitude = 0.05;
|
|---|
| 1067 | perturbPolygon(polygon, amplitude);
|
|---|
| 1068 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 1069 | }
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 1080 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1081 | polygon += std::make_pair( Vector(1.,0.,0.), 1);
|
|---|
| [d734ff] | 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 | {
|
|---|
| [260540] | 1095 | SphericalPointDistribution::WeightedPolygon_t polygon;
|
|---|
| 1096 | polygon += std::make_pair( Vector(0.,1.,0.), 1);
|
|---|
| [d734ff] | 1097 | SphericalPointDistribution::Polygon_t newpolygon =
|
|---|
| 1098 | SPD.get<8>();
|
|---|
| 1099 | SphericalPointDistribution::Polygon_t expected = newpolygon;
|
|---|
| 1100 | expected.pop_front(); // remove first point
|
|---|
| [0ae114] | 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 =
|
|---|
| [d734ff] | 1107 | SphericalPointDistribution::matchSphericalPointDistributions(
|
|---|
| 1108 | polygon,
|
|---|
| 1109 | newpolygon);
|
|---|
| 1110 | CPPUNIT_ASSERT_EQUAL( expected, remaining );
|
|---|
| 1111 | }
|
|---|
| [6aa6b7] | 1112 |
|
|---|
| 1113 | // test with two points, matching trivially
|
|---|
| 1114 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 1128 | // also slightly perturbed
|
|---|
| 1129 | const double amplitude = 0.05;
|
|---|
| 1130 | perturbPolygon(polygon, amplitude);
|
|---|
| 1131 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 1132 | }
|
|---|
| 1133 |
|
|---|
| 1134 | // test with two points, full rotation
|
|---|
| 1135 | {
|
|---|
| 1136 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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() );
|
|---|
| [260540] | 1156 | for (SphericalPointDistribution::WeightedPolygon_t::const_iterator fixiter = polygon.begin();
|
|---|
| [6aa6b7] | 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) );
|
|---|
| [260540] | 1163 | CPPUNIT_ASSERT( fabs( (*expectiter).Angle(fixiter->first) - (*remainiter).Angle(fixiter->first) )
|
|---|
| [6aa6b7] | 1164 | < std::numeric_limits<double>::epsilon()*1e4 );
|
|---|
| 1165 | }
|
|---|
| 1166 | }
|
|---|
| 1167 | }
|
|---|
| 1168 |
|
|---|
| 1169 | // test with three points, matching trivially
|
|---|
| 1170 | {
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 1186 | // also slightly perturbed
|
|---|
| 1187 | const double amplitude = 0.05;
|
|---|
| 1188 | perturbPolygon(polygon, amplitude);
|
|---|
| 1189 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 1190 | }
|
|---|
| 1191 |
|
|---|
| 1192 | // test with three points, full rotation
|
|---|
| 1193 | {
|
|---|
| 1194 | Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
|
|---|
| [260540] | 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);
|
|---|
| [6aa6b7] | 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 );
|
|---|
| [3da643] | 1213 | // also slightly perturbed
|
|---|
| 1214 | const double amplitude = 0.05;
|
|---|
| 1215 | perturbPolygon(polygon, amplitude);
|
|---|
| 1216 | CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, amplitude) );
|
|---|
| [6aa6b7] | 1217 | }
|
|---|
| [11cc05] | 1218 | }
|
|---|