Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/ShapeUnittest.cpp

    r997784 r6d750f  
    1717
    1818#include "Shapes/Shape.hpp"
     19#include "Shapes/BaseShapes.hpp"
    1920#include "vector.cpp"
    2021
     
    2425void ShapeUnittest::setUp()
    2526{
    26   v000 =  0*e1+0*e2+0*e3;
    27   v100 =  1*e1+0*e2+0*e3;
    28   v200 = -1*e1+0*e2+0*e3;
    29   v010 =  0*e1+1*e2+0*e3;
    30   v110 =  1*e1+1*e2+0*e3;
    31   v210 = -1*e1+1*e2+0*e3;
    32   v020 =  0*e1-1*e2+0*e3;
    33   v120 =  1*e1-1*e2+0*e3;
    34   v220 = -1*e1-1*e2+0*e3;
    35   v001 =  0*e1+0*e2+1*e3;
    36   v101 =  1*e1+0*e2+1*e3;
    37   v201 = -1*e1+0*e2+1*e3;
    38   v011 =  0*e1+1*e2+1*e3;
    39   v111 =  1*e1+1*e2+1*e3;
    40   v211 = -1*e1+1*e2+1*e3;
    41   v021 =  0*e1-1*e2+1*e3;
    42   v121 =  1*e1-1*e2+1*e3;
    43   v221 = -1*e1-1*e2+1*e3;
    44   v002 =  0*e1+0*e2-1*e3;
    45   v102 =  1*e1+0*e2-1*e3;
    46   v202 = -1*e1+0*e2-1*e3;
    47   v012 =  0*e1+1*e2-1*e3;
    48   v112 =  1*e1+1*e2-1*e3;
    49   v212 = -1*e1+1*e2-1*e3;
    50   v022 =  0*e1-1*e2-1*e3;
    51   v122 =  1*e1-1*e2-1*e3;
    52   v222 = -1*e1-1*e2-1*e3;
     27  v000 =  0*unitVec[0]+0*unitVec[1]+0*unitVec[2];
     28  v100 =  1*unitVec[0]+0*unitVec[1]+0*unitVec[2];
     29  v200 = -1*unitVec[0]+0*unitVec[1]+0*unitVec[2];
     30  v010 =  0*unitVec[0]+1*unitVec[1]+0*unitVec[2];
     31  v110 =  1*unitVec[0]+1*unitVec[1]+0*unitVec[2];
     32  v210 = -1*unitVec[0]+1*unitVec[1]+0*unitVec[2];
     33  v020 =  0*unitVec[0]-1*unitVec[1]+0*unitVec[2];
     34  v120 =  1*unitVec[0]-1*unitVec[1]+0*unitVec[2];
     35  v220 = -1*unitVec[0]-1*unitVec[1]+0*unitVec[2];
     36  v001 =  0*unitVec[0]+0*unitVec[1]+1*unitVec[2];
     37  v101 =  1*unitVec[0]+0*unitVec[1]+1*unitVec[2];
     38  v201 = -1*unitVec[0]+0*unitVec[1]+1*unitVec[2];
     39  v011 =  0*unitVec[0]+1*unitVec[1]+1*unitVec[2];
     40  v111 =  1*unitVec[0]+1*unitVec[1]+1*unitVec[2];
     41  v211 = -1*unitVec[0]+1*unitVec[1]+1*unitVec[2];
     42  v021 =  0*unitVec[0]-1*unitVec[1]+1*unitVec[2];
     43  v121 =  1*unitVec[0]-1*unitVec[1]+1*unitVec[2];
     44  v221 = -1*unitVec[0]-1*unitVec[1]+1*unitVec[2];
     45  v002 =  0*unitVec[0]+0*unitVec[1]-1*unitVec[2];
     46  v102 =  1*unitVec[0]+0*unitVec[1]-1*unitVec[2];
     47  v202 = -1*unitVec[0]+0*unitVec[1]-1*unitVec[2];
     48  v012 =  0*unitVec[0]+1*unitVec[1]-1*unitVec[2];
     49  v112 =  1*unitVec[0]+1*unitVec[1]-1*unitVec[2];
     50  v212 = -1*unitVec[0]+1*unitVec[1]-1*unitVec[2];
     51  v022 =  0*unitVec[0]-1*unitVec[1]-1*unitVec[2];
     52  v122 =  1*unitVec[0]-1*unitVec[1]-1*unitVec[2];
     53  v222 = -1*unitVec[0]-1*unitVec[1]-1*unitVec[2];
    5354}
    5455
     
    113114  CPPUNIT_ASSERT(Everywhere().isInside(v122));
    114115  CPPUNIT_ASSERT(Everywhere().isInside(v222));
     116
     117  CPPUNIT_ASSERT(Cuboid().isInside(v000));
     118  CPPUNIT_ASSERT(Cuboid().isInside(v100));
     119  CPPUNIT_ASSERT(Cuboid().isInside(v200));
     120  CPPUNIT_ASSERT(Cuboid().isInside(v010));
     121  CPPUNIT_ASSERT(Cuboid().isInside(v110));
     122  CPPUNIT_ASSERT(Cuboid().isInside(v210));
     123  CPPUNIT_ASSERT(Cuboid().isInside(v020));
     124  CPPUNIT_ASSERT(Cuboid().isInside(v120));
     125  CPPUNIT_ASSERT(Cuboid().isInside(v220));
     126  CPPUNIT_ASSERT(Cuboid().isInside(v001));
     127  CPPUNIT_ASSERT(Cuboid().isInside(v101));
     128  CPPUNIT_ASSERT(Cuboid().isInside(v201));
     129  CPPUNIT_ASSERT(Cuboid().isInside(v011));
     130  CPPUNIT_ASSERT(Cuboid().isInside(v111));
     131  CPPUNIT_ASSERT(Cuboid().isInside(v211));
     132  CPPUNIT_ASSERT(Cuboid().isInside(v021));
     133  CPPUNIT_ASSERT(Cuboid().isInside(v121));
     134  CPPUNIT_ASSERT(Cuboid().isInside(v221));
     135  CPPUNIT_ASSERT(Cuboid().isInside(v002));
     136  CPPUNIT_ASSERT(Cuboid().isInside(v102));
     137  CPPUNIT_ASSERT(Cuboid().isInside(v202));
     138  CPPUNIT_ASSERT(Cuboid().isInside(v012));
     139  CPPUNIT_ASSERT(Cuboid().isInside(v112));
     140  CPPUNIT_ASSERT(Cuboid().isInside(v212));
     141  CPPUNIT_ASSERT(Cuboid().isInside(v022));
     142  CPPUNIT_ASSERT(Cuboid().isInside(v122));
     143  CPPUNIT_ASSERT(Cuboid().isInside(v222));
     144
     145  CPPUNIT_ASSERT(Sphere().isInside(v000));
     146  CPPUNIT_ASSERT(Sphere().isInside(v100));
     147  CPPUNIT_ASSERT(Sphere().isInside(v200));
     148  CPPUNIT_ASSERT(Sphere().isInside(v010));
     149  CPPUNIT_ASSERT(!Sphere().isInside(v110));
     150  CPPUNIT_ASSERT(!Sphere().isInside(v210));
     151  CPPUNIT_ASSERT(Sphere().isInside(v020));
     152  CPPUNIT_ASSERT(!Sphere().isInside(v120));
     153  CPPUNIT_ASSERT(!Sphere().isInside(v220));
     154  CPPUNIT_ASSERT(Sphere().isInside(v001));
     155  CPPUNIT_ASSERT(!Sphere().isInside(v101));
     156  CPPUNIT_ASSERT(!Sphere().isInside(v201));
     157  CPPUNIT_ASSERT(!Sphere().isInside(v011));
     158  CPPUNIT_ASSERT(!Sphere().isInside(v111));
     159  CPPUNIT_ASSERT(!Sphere().isInside(v211));
     160  CPPUNIT_ASSERT(!Sphere().isInside(v021));
     161  CPPUNIT_ASSERT(!Sphere().isInside(v121));
     162  CPPUNIT_ASSERT(!Sphere().isInside(v221));
     163  CPPUNIT_ASSERT(Sphere().isInside(v002));
     164  CPPUNIT_ASSERT(!Sphere().isInside(v102));
     165  CPPUNIT_ASSERT(!Sphere().isInside(v202));
     166  CPPUNIT_ASSERT(!Sphere().isInside(v012));
     167  CPPUNIT_ASSERT(!Sphere().isInside(v112));
     168  CPPUNIT_ASSERT(!Sphere().isInside(v212));
     169  CPPUNIT_ASSERT(!Sphere().isInside(v022));
     170  CPPUNIT_ASSERT(!Sphere().isInside(v122));
     171  CPPUNIT_ASSERT(!Sphere().isInside(v222));
     172}
     173
     174void ShapeUnittest::surfaceTest(){
     175  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v000));
     176  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v100));
     177  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v200));
     178  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v010));
     179  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v110));
     180  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v210));
     181  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v020));
     182  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v120));
     183  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v220));
     184  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v001));
     185  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v101));
     186  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v201));
     187  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v011));
     188  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v111));
     189  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v211));
     190  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v021));
     191  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v121));
     192  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v221));
     193  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v002));
     194  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v102));
     195  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v202));
     196  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v012));
     197  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v112));
     198  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v212));
     199  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v022));
     200  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v122));
     201  CPPUNIT_ASSERT(!Nowhere().isOnSurface(v222));
     202
     203  CPPUNIT_ASSERT(!Cuboid().isOnSurface(v000));
     204  CPPUNIT_ASSERT(Cuboid().isOnSurface(v100));
     205  CPPUNIT_ASSERT(Cuboid().isOnSurface(v200));
     206  CPPUNIT_ASSERT(Cuboid().isOnSurface(v010));
     207  CPPUNIT_ASSERT(Cuboid().isOnSurface(v110));
     208  CPPUNIT_ASSERT(Cuboid().isOnSurface(v210));
     209  CPPUNIT_ASSERT(Cuboid().isOnSurface(v020));
     210  CPPUNIT_ASSERT(Cuboid().isOnSurface(v120));
     211  CPPUNIT_ASSERT(Cuboid().isOnSurface(v220));
     212  CPPUNIT_ASSERT(Cuboid().isOnSurface(v001));
     213  CPPUNIT_ASSERT(Cuboid().isOnSurface(v101));
     214  CPPUNIT_ASSERT(Cuboid().isOnSurface(v201));
     215  CPPUNIT_ASSERT(Cuboid().isOnSurface(v011));
     216  CPPUNIT_ASSERT(Cuboid().isOnSurface(v111));
     217  CPPUNIT_ASSERT(Cuboid().isOnSurface(v211));
     218  CPPUNIT_ASSERT(Cuboid().isOnSurface(v021));
     219  CPPUNIT_ASSERT(Cuboid().isOnSurface(v121));
     220  CPPUNIT_ASSERT(Cuboid().isOnSurface(v221));
     221  CPPUNIT_ASSERT(Cuboid().isOnSurface(v002));
     222  CPPUNIT_ASSERT(Cuboid().isOnSurface(v102));
     223  CPPUNIT_ASSERT(Cuboid().isOnSurface(v202));
     224  CPPUNIT_ASSERT(Cuboid().isOnSurface(v012));
     225  CPPUNIT_ASSERT(Cuboid().isOnSurface(v112));
     226  CPPUNIT_ASSERT(Cuboid().isOnSurface(v212));
     227  CPPUNIT_ASSERT(Cuboid().isOnSurface(v022));
     228  CPPUNIT_ASSERT(Cuboid().isOnSurface(v122));
     229  CPPUNIT_ASSERT(Cuboid().isOnSurface(v222));
     230
     231  CPPUNIT_ASSERT(!Sphere().isOnSurface(v000));
     232  CPPUNIT_ASSERT(Sphere().isOnSurface(v100));
     233  CPPUNIT_ASSERT(Sphere().isOnSurface(v200));
     234  CPPUNIT_ASSERT(Sphere().isOnSurface(v010));
     235  CPPUNIT_ASSERT(!Sphere().isOnSurface(v110));
     236  CPPUNIT_ASSERT(!Sphere().isOnSurface(v210));
     237  CPPUNIT_ASSERT(Sphere().isOnSurface(v020));
     238  CPPUNIT_ASSERT(!Sphere().isOnSurface(v120));
     239  CPPUNIT_ASSERT(!Sphere().isOnSurface(v220));
     240  CPPUNIT_ASSERT(Sphere().isOnSurface(v001));
     241  CPPUNIT_ASSERT(!Sphere().isOnSurface(v101));
     242  CPPUNIT_ASSERT(!Sphere().isOnSurface(v201));
     243  CPPUNIT_ASSERT(!Sphere().isOnSurface(v011));
     244  CPPUNIT_ASSERT(!Sphere().isOnSurface(v111));
     245  CPPUNIT_ASSERT(!Sphere().isOnSurface(v211));
     246  CPPUNIT_ASSERT(!Sphere().isOnSurface(v021));
     247  CPPUNIT_ASSERT(!Sphere().isOnSurface(v121));
     248  CPPUNIT_ASSERT(!Sphere().isOnSurface(v221));
     249  CPPUNIT_ASSERT(Sphere().isOnSurface(v002));
     250  CPPUNIT_ASSERT(!Sphere().isOnSurface(v102));
     251  CPPUNIT_ASSERT(!Sphere().isOnSurface(v202));
     252  CPPUNIT_ASSERT(!Sphere().isOnSurface(v012));
     253  CPPUNIT_ASSERT(!Sphere().isOnSurface(v112));
     254  CPPUNIT_ASSERT(!Sphere().isOnSurface(v212));
     255  CPPUNIT_ASSERT(!Sphere().isOnSurface(v022));
     256  CPPUNIT_ASSERT(!Sphere().isOnSurface(v122));
     257  CPPUNIT_ASSERT(!Sphere().isOnSurface(v222));
    115258}
    116259
     
    360503  }
    361504
     505  {
     506    Shape s1 = Sphere() && Cuboid(); // should be the same as Sphere
     507
     508    CPPUNIT_ASSERT(s1.isInside(v000));
     509    CPPUNIT_ASSERT(s1.isInside(v100));
     510    CPPUNIT_ASSERT(s1.isInside(v200));
     511    CPPUNIT_ASSERT(s1.isInside(v010));
     512    CPPUNIT_ASSERT(!s1.isInside(v110));
     513    CPPUNIT_ASSERT(!s1.isInside(v210));
     514    CPPUNIT_ASSERT(s1.isInside(v020));
     515    CPPUNIT_ASSERT(!s1.isInside(v120));
     516    CPPUNIT_ASSERT(!s1.isInside(v220));
     517    CPPUNIT_ASSERT(s1.isInside(v001));
     518    CPPUNIT_ASSERT(!s1.isInside(v101));
     519    CPPUNIT_ASSERT(!s1.isInside(v201));
     520    CPPUNIT_ASSERT(!s1.isInside(v011));
     521    CPPUNIT_ASSERT(!s1.isInside(v111));
     522    CPPUNIT_ASSERT(!s1.isInside(v211));
     523    CPPUNIT_ASSERT(!s1.isInside(v021));
     524    CPPUNIT_ASSERT(!s1.isInside(v121));
     525    CPPUNIT_ASSERT(!s1.isInside(v221));
     526    CPPUNIT_ASSERT(s1.isInside(v002));
     527    CPPUNIT_ASSERT(!s1.isInside(v102));
     528    CPPUNIT_ASSERT(!s1.isInside(v202));
     529    CPPUNIT_ASSERT(!s1.isInside(v012));
     530    CPPUNIT_ASSERT(!s1.isInside(v112));
     531    CPPUNIT_ASSERT(!s1.isInside(v212));
     532    CPPUNIT_ASSERT(!s1.isInside(v022));
     533    CPPUNIT_ASSERT(!s1.isInside(v122));
     534    CPPUNIT_ASSERT(!s1.isInside(v222));
     535
     536    CPPUNIT_ASSERT(!s1.isOnSurface(v000));
     537    CPPUNIT_ASSERT(s1.isOnSurface(v100));
     538    CPPUNIT_ASSERT(s1.isOnSurface(v200));
     539    CPPUNIT_ASSERT(s1.isOnSurface(v010));
     540    CPPUNIT_ASSERT(!s1.isOnSurface(v110));
     541    CPPUNIT_ASSERT(!s1.isOnSurface(v210));
     542    CPPUNIT_ASSERT(s1.isOnSurface(v020));
     543    CPPUNIT_ASSERT(!s1.isOnSurface(v120));
     544    CPPUNIT_ASSERT(!s1.isOnSurface(v220));
     545    CPPUNIT_ASSERT(s1.isOnSurface(v001));
     546    CPPUNIT_ASSERT(!s1.isOnSurface(v101));
     547    CPPUNIT_ASSERT(!s1.isOnSurface(v201));
     548    CPPUNIT_ASSERT(!s1.isOnSurface(v011));
     549    CPPUNIT_ASSERT(!s1.isOnSurface(v111));
     550    CPPUNIT_ASSERT(!s1.isOnSurface(v211));
     551    CPPUNIT_ASSERT(!s1.isOnSurface(v021));
     552    CPPUNIT_ASSERT(!s1.isOnSurface(v121));
     553    CPPUNIT_ASSERT(!s1.isOnSurface(v221));
     554    CPPUNIT_ASSERT(s1.isOnSurface(v002));
     555    CPPUNIT_ASSERT(!s1.isOnSurface(v102));
     556    CPPUNIT_ASSERT(!s1.isOnSurface(v202));
     557    CPPUNIT_ASSERT(!s1.isOnSurface(v012));
     558    CPPUNIT_ASSERT(!s1.isOnSurface(v112));
     559    CPPUNIT_ASSERT(!s1.isOnSurface(v212));
     560    CPPUNIT_ASSERT(!s1.isOnSurface(v022));
     561    CPPUNIT_ASSERT(!s1.isOnSurface(v122));
     562    CPPUNIT_ASSERT(!s1.isOnSurface(v222));
     563
     564
     565    Shape s2 = Sphere() || Cuboid(); // Should be same as Cuboid
     566
     567    CPPUNIT_ASSERT(s2.isInside(v000));
     568    CPPUNIT_ASSERT(s2.isInside(v100));
     569    CPPUNIT_ASSERT(s2.isInside(v200));
     570    CPPUNIT_ASSERT(s2.isInside(v010));
     571    CPPUNIT_ASSERT(s2.isInside(v110));
     572    CPPUNIT_ASSERT(s2.isInside(v210));
     573    CPPUNIT_ASSERT(s2.isInside(v020));
     574    CPPUNIT_ASSERT(s2.isInside(v120));
     575    CPPUNIT_ASSERT(s2.isInside(v220));
     576    CPPUNIT_ASSERT(s2.isInside(v001));
     577    CPPUNIT_ASSERT(s2.isInside(v101));
     578    CPPUNIT_ASSERT(s2.isInside(v201));
     579    CPPUNIT_ASSERT(s2.isInside(v011));
     580    CPPUNIT_ASSERT(s2.isInside(v111));
     581    CPPUNIT_ASSERT(s2.isInside(v211));
     582    CPPUNIT_ASSERT(s2.isInside(v021));
     583    CPPUNIT_ASSERT(s2.isInside(v121));
     584    CPPUNIT_ASSERT(s2.isInside(v221));
     585    CPPUNIT_ASSERT(s2.isInside(v002));
     586    CPPUNIT_ASSERT(s2.isInside(v102));
     587    CPPUNIT_ASSERT(s2.isInside(v202));
     588    CPPUNIT_ASSERT(s2.isInside(v012));
     589    CPPUNIT_ASSERT(s2.isInside(v112));
     590    CPPUNIT_ASSERT(s2.isInside(v212));
     591    CPPUNIT_ASSERT(s2.isInside(v022));
     592    CPPUNIT_ASSERT(s2.isInside(v122));
     593    CPPUNIT_ASSERT(s2.isInside(v222));
     594
     595    CPPUNIT_ASSERT(!s2.isOnSurface(v000));
     596    CPPUNIT_ASSERT(s2.isOnSurface(v100));
     597    CPPUNIT_ASSERT(s2.isOnSurface(v200));
     598    CPPUNIT_ASSERT(s2.isOnSurface(v010));
     599    CPPUNIT_ASSERT(s2.isOnSurface(v110));
     600    CPPUNIT_ASSERT(s2.isOnSurface(v210));
     601    CPPUNIT_ASSERT(s2.isOnSurface(v020));
     602    CPPUNIT_ASSERT(s2.isOnSurface(v120));
     603    CPPUNIT_ASSERT(s2.isOnSurface(v220));
     604    CPPUNIT_ASSERT(s2.isOnSurface(v001));
     605    CPPUNIT_ASSERT(s2.isOnSurface(v101));
     606    CPPUNIT_ASSERT(s2.isOnSurface(v201));
     607    CPPUNIT_ASSERT(s2.isOnSurface(v011));
     608    CPPUNIT_ASSERT(s2.isOnSurface(v111));
     609    CPPUNIT_ASSERT(s2.isOnSurface(v211));
     610    CPPUNIT_ASSERT(s2.isOnSurface(v021));
     611    CPPUNIT_ASSERT(s2.isOnSurface(v121));
     612    CPPUNIT_ASSERT(s2.isOnSurface(v221));
     613    CPPUNIT_ASSERT(s2.isOnSurface(v002));
     614    CPPUNIT_ASSERT(s2.isOnSurface(v102));
     615    CPPUNIT_ASSERT(s2.isOnSurface(v202));
     616    CPPUNIT_ASSERT(s2.isOnSurface(v012));
     617    CPPUNIT_ASSERT(s2.isOnSurface(v112));
     618    CPPUNIT_ASSERT(s2.isOnSurface(v212));
     619    CPPUNIT_ASSERT(s2.isOnSurface(v022));
     620    CPPUNIT_ASSERT(s2.isOnSurface(v122));
     621    CPPUNIT_ASSERT(s2.isOnSurface(v222));
     622  }
     623
    362624}
Note: See TracChangeset for help on using the changeset viewer.