Changes in / [014475:8f822c]


Ignore:
Location:
src
Files:
11 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/Line.cpp

    r014475 r8f822c  
    215215}
    216216
     217std::vector<Vector> Line::getSphereIntersections() const{
     218  std::vector<Vector> res;
     219
     220  // line is kept in normalized form, so we can skip a lot of calculations
     221  double discriminant = 1-origin->NormSquared();
     222  // we might have 2, 1 or 0 solutions, depending on discriminant
     223  if(discriminant>=0){
     224    if(discriminant==0){
     225      res.push_back(*origin);
     226    }
     227    else{
     228      Vector helper = sqrt(discriminant)*(*direction);
     229      res.push_back(*origin+helper);
     230      res.push_back(*origin-helper);
     231    }
     232  }
     233  return res;
     234}
     235
    217236Line makeLineThrough(const Vector &x1, const Vector &x2){
    218237  if(x1==x2){
  • src/Line.hpp

    r014475 r8f822c  
    3838  Plane getOrthogonalPlane(const Vector &origin) const;
    3939
     40  std::vector<Vector> getSphereIntersections() const;
     41
    4042private:
    4143  std::auto_ptr<Vector> origin;
  • src/Makefile.am

    r014475 r8f822c  
    122122  Patterns/Observer.hpp \
    123123  Patterns/Singleton.hpp
     124 
     125SHAPESOURCE = \
     126  Shapes/BaseShapes.cpp \
     127  Shapes/Shape.cpp \
     128  Shapes/ShapeOps.cpp
     129SHAPEHEADER = \
     130  Shapes/BaseShapes.hpp \
     131  Shapes/Shape.hpp \
     132  Shapes/ShapeOps.hpp
     133 
    124134
    125135DESCRIPTORSOURCE = Descriptors/AtomDescriptor.cpp \
     
    147157  ${PATTERNSOURCE} \
    148158  ${PARSERSOURCE} \
     159  ${SHAPESOURCE} \
    149160  ${DESCRIPTORSOURCE} \
    150161  ${HELPERSOURCE} \
     
    194205  ${PARSERHEADER} \
    195206  ${PATTERNHEADER} \
     207  ${SHAPEHEADER} \
    196208  ${DESCRIPTORHEADER} \
    197209  bond.hpp \
  • src/unittests/LineUnittest.cpp

    r014475 r8f822c  
    353353  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    354354}
     355
     356void LineUnittest::sphereIntersectionTest(){
     357  {
     358    std::vector<Vector> res = la1->getSphereIntersections();
     359    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     360    CPPUNIT_ASSERT(testDirection(res[0],e1));
     361    CPPUNIT_ASSERT(testDirection(res[1],e1));
     362    CPPUNIT_ASSERT(res[0]!=res[1]);
     363  }
     364
     365  {
     366    std::vector<Vector> res = la2->getSphereIntersections();
     367    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     368    CPPUNIT_ASSERT(testDirection(res[0],e2));
     369    CPPUNIT_ASSERT(testDirection(res[1],e2));
     370    CPPUNIT_ASSERT(res[0]!=res[1]);
     371  }
     372
     373  {
     374    std::vector<Vector> res = la3->getSphereIntersections();
     375    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     376    CPPUNIT_ASSERT(testDirection(res[0],e3));
     377    CPPUNIT_ASSERT(testDirection(res[1],e3));
     378    CPPUNIT_ASSERT(res[0]!=res[1]);
     379  }
     380
     381  {
     382    std::vector<Vector> res = lp1->getSphereIntersections();
     383    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     384    CPPUNIT_ASSERT((res[0]==e1) || (res[0]==e2));
     385    CPPUNIT_ASSERT((res[1]==e1) || (res[1]==e2));
     386    CPPUNIT_ASSERT(res[0]!=res[1]);
     387  }
     388
     389  {
     390    std::vector<Vector> res = lp2->getSphereIntersections();
     391    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     392    CPPUNIT_ASSERT((res[0]==e2) || (res[0]==e3));
     393    CPPUNIT_ASSERT((res[1]==e2) || (res[1]==e3));
     394    CPPUNIT_ASSERT(res[0]!=res[1]);
     395  }
     396
     397  {
     398    std::vector<Vector> res = lp3->getSphereIntersections();
     399    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     400    CPPUNIT_ASSERT((res[0]==e3) || (res[0]==e1));
     401    CPPUNIT_ASSERT((res[1]==e3) || (res[1]==e1));
     402    CPPUNIT_ASSERT(res[0]!=res[1]);
     403  }
     404}
  • src/unittests/LineUnittest.hpp

    r014475 r8f822c  
    2222  CPPUNIT_TEST ( intersectionTest );
    2323  CPPUNIT_TEST ( rotationTest );
     24  CPPUNIT_TEST ( sphereIntersectionTest );
    2425  CPPUNIT_TEST_SUITE_END();
    2526
     
    3334  void intersectionTest();
    3435  void rotationTest();
     36  void sphereIntersectionTest();
    3537
    3638private:
  • src/unittests/Makefile.am

    r014475 r8f822c  
    3838  periodentafelTest \
    3939  PlaneUnittest \
     40  ShapeUnittest \
    4041  SingletonTest \
    4142  StackClassUnitTest \
     
    8384  periodentafelTest.cpp \
    8485  PlaneUnittest.cpp \
     86  ShapeUnittest.cpp \
    8587  SingletonTest.cpp \
    8688  stackclassunittest.cpp \
     
    210212PlaneUnittest_LDADD = ${ALLLIBS}
    211213
     214ShapeUnittest_SOURCES = UnitTestMain.cpp ShapeUnittest.cpp ShapeUnittest.hpp
     215ShapeUnittest_LDADD = ${ALLLIBS}
     216
    212217SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp
    213218SingletonTest_LDADD = ${ALLLIBS} $(BOOST_LIB) ${BOOST_THREAD_LIB}
Note: See TracChangeset for help on using the changeset viewer.