Ignore:
Timestamp:
Aug 20, 2014, 1:04:08 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Children:
23c605
Parents:
260540
git-author:
Frederik Heber <heber@…> (06/29/14 21:20:49)
git-committer:
Frederik Heber <heber@…> (08/20/14 13:04:08)
Message:

Extracted joinPoints() function to make it accessible to tests.

  • added unit test.
  • moved some function definitions around and added documentation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp

    r260540 r1ae9aa  
    245245}
    246246
     247/** UnitTest for joinPoints()
     248 */
     249void 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}
    247350
    248351/** UnitTest for matchSphericalPointDistributions() with three points
Note: See TracChangeset for help on using the changeset viewer.