diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h index e5f8957178be2654255fd5438b3e3c097eab24fa..45952481c5dfb5812c9e878ebec45afb8ad243d4 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Surfaces/Line.h @@ -62,7 +62,7 @@ namespace Mantid Kernel::V3D Direct; ///< Direction of outer surface (Unit Vector) int lambdaPair(const int ix,const std::pair<std::complex<double>, - std::complex<double> >& SQ,std::vector<Kernel::V3D>& PntOut) const; + std::complex<double> >& SQ,std::list<Kernel::V3D>& PntOut) const; public: @@ -86,10 +86,10 @@ namespace Mantid int setLine(const Kernel::V3D&,const Kernel::V3D&); ///< input Origin + direction - int intersect(std::vector<Kernel::V3D>&,const Quadratic&) const; - int intersect(std::vector<Kernel::V3D>&,const Cylinder&) const; - int intersect(std::vector<Kernel::V3D>&,const Plane&) const; - int intersect(std::vector<Kernel::V3D>&,const Sphere&) const; + int intersect(std::list<Kernel::V3D>&,const Quadratic&) const; + int intersect(std::list<Kernel::V3D>&,const Cylinder&) const; + int intersect(std::list<Kernel::V3D>&,const Plane&) const; + int intersect(std::list<Kernel::V3D>&,const Sphere&) const; }; diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Surfaces/LineIntersectVisit.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Surfaces/LineIntersectVisit.h index dba93f49362ab3e7acd7399ca4293d8945dc4ac2..f225702a7c68b28fb720534e728fecc835aa2695 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Surfaces/LineIntersectVisit.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Surfaces/LineIntersectVisit.h @@ -4,7 +4,7 @@ #include "MantidGeometry/Surfaces/BaseVisit.h" #include "MantidGeometry/Surfaces/Line.h" #include "MantidKernel/V3D.h" -#include <vector> +#include <list> namespace Mantid { @@ -56,8 +56,8 @@ namespace Mantid private: Line ATrack; ///< The line - std::vector<Kernel::V3D> PtOut; ///< The intersection point - std::vector<double> DOut; ///< The distance + std::list<Kernel::V3D> PtOut; ///< The intersection point + std::list<double> DOut; ///< The distance void procTrack(); @@ -66,7 +66,7 @@ namespace Mantid LineIntersectVisit(const Kernel::V3D&, const Kernel::V3D&); /// Destructor - virtual ~LineIntersectVisit() {}; + virtual ~LineIntersectVisit() {} void Accept(const Surface&); void Accept(const Quadratic&); @@ -78,10 +78,10 @@ namespace Mantid // Accessor /// Get the distance - const std::vector<double>& getDistance() const + const std::list<double>& getDistance() const { return DOut; } /// Get the intersection points - const std::vector<Kernel::V3D>& getPoints() const + const std::list<Kernel::V3D>& getPoints() const { return PtOut; } /// Get the number of intersection points unsigned long getNPoints() const { return (unsigned long)PtOut.size(); } diff --git a/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp b/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp index 344fc90dd7954366387b63892125f24e96dfb1ed..221750d9bb4f589c80b7292f364c67e1ac5d69a2 100644 --- a/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp +++ b/Code/Mantid/Framework/Geometry/src/Objects/Object.cpp @@ -810,16 +810,18 @@ namespace Mantid { (*vc)->acceptVisitor(LI); } - const std::vector<Kernel::V3D>& IPts(LI.getPoints()); - const std::vector<double>& dPts(LI.getDistance()); + const auto& IPts(LI.getPoints()); + const auto& dPts(LI.getDistance()); - for (unsigned int i = 0; i < IPts.size(); i++) + auto ditr = dPts.begin(); + auto itrEnd = IPts.end(); + for (auto iitr = IPts.begin(); iitr != itrEnd; ++iitr, ++ditr) { - if (dPts[i] > 0.0) // only interested in forward going points + if (*ditr > 0.0) // only interested in forward going points { // Is the point and enterance/exit Point - const int flag = calcValidType(IPts[i], UT.direction()); - UT.addPoint(flag, IPts[i], *this); + const int flag = calcValidType(*iitr, UT.direction()); + UT.addPoint(flag, *iitr, *this); } } UT.buildLink(); diff --git a/Code/Mantid/Framework/Geometry/src/Surfaces/Line.cpp b/Code/Mantid/Framework/Geometry/src/Surfaces/Line.cpp index 69e2dbbc1e1dd17057ff2f9f95b07aaaec8557f8..c4c424e9fb55436078e497b83470407cfda37330 100644 --- a/Code/Mantid/Framework/Geometry/src/Surfaces/Line.cpp +++ b/Code/Mantid/Framework/Geometry/src/Surfaces/Line.cpp @@ -136,9 +136,9 @@ namespace Mantid } int - Line::lambdaPair(const int ix,const std::pair< + Line::lambdaPair(const int ix, const std::pair< std::complex<double>,std::complex<double> >& SQ, - std::vector<Kernel::V3D>& PntOut) const + std::list<Kernel::V3D> &PntOut) const /** Helper function to decide which roots to take. The assumption is that lambda has been solved by quadratic @@ -190,7 +190,7 @@ namespace Mantid } int - Line::intersect(std::vector<Kernel::V3D>& VecOut, + Line::intersect(std::list<Kernel::V3D> &VecOut, const Quadratic& Sur) const /** For the line that intersects the surfaces @@ -220,7 +220,7 @@ namespace Mantid } int - Line::intersect(std::vector<Kernel::V3D>& PntOut ,const Plane& Pln) const + Line::intersect(std::list<Kernel::V3D>& PntOut ,const Plane& Pln) const /** For the line that intersects the cylinder generate add the point to the VecOut, return number of points @@ -244,7 +244,7 @@ namespace Mantid } int - Line::intersect(std::vector<Kernel::V3D>& PntOut ,const Cylinder& Cyl) const + Line::intersect(std::list<Kernel::V3D> &PntOut , const Cylinder& Cyl) const /** For the line that intersects the cylinder generate add the point to the VecOut, return number of points @@ -273,7 +273,7 @@ namespace Mantid } int - Line::intersect(std::vector<Kernel::V3D>& PntOut ,const Sphere& Sph) const + Line::intersect(std::list<Kernel::V3D> &PntOut , const Sphere& Sph) const /** For the line that intersects the cylinder generate add the point to the VecOut, return number of points diff --git a/Code/Mantid/Framework/Geometry/test/LineIntersectVisitTest.h b/Code/Mantid/Framework/Geometry/test/LineIntersectVisitTest.h index 448aafecbc6e82ab5ce61a09f21758ffa04dc657..24765b26c2704c84f3ed00786b567cbe460dfde6 100644 --- a/Code/Mantid/Framework/Geometry/test/LineIntersectVisitTest.h +++ b/Code/Mantid/Framework/Geometry/test/LineIntersectVisitTest.h @@ -20,8 +20,8 @@ public: void testConstructor(){ LineIntersectVisit A(V3D(-1.0,-1.0,-1.0),V3D(1.0,0.0,0.0)); TS_ASSERT_EQUALS(A.getNPoints(),0); - TS_ASSERT_EQUALS(A.getPoints(),std::vector<Kernel::V3D>()); - TS_ASSERT_EQUALS(A.getDistance(),std::vector<double>()); + TS_ASSERT_EQUALS(A.getPoints(),std::list<Kernel::V3D>()); + TS_ASSERT_EQUALS(A.getDistance(),std::list<double>()); } void testAcceptPlane(){ @@ -31,10 +31,10 @@ public: TS_ASSERT_EQUALS(extractString(B),"-1 px 0\n"); A.Accept(B); TS_ASSERT_EQUALS(A.getNPoints(),1); - std::vector<Kernel::V3D> Pnts; + std::list<Kernel::V3D> Pnts; Pnts.push_back(V3D(0.0,-1.0,-1.0)); TS_ASSERT_EQUALS(A.getPoints(),Pnts); - std::vector<double> Dist; + std::list<double> Dist; Dist.push_back(1.0); TS_ASSERT_EQUALS(A.getDistance(),Dist); } @@ -45,14 +45,13 @@ public: Sphere B; B.setSurface("s 0.0 0.0 0.0 2"); A.Accept(B); - std::vector<V3D> pntOut; + std::list<V3D> pntOut; // changed for forward going only intercepts on quadratice surfaces //pntOut.push_back(V3D(-2.0,0.0,0.0)); pntOut.push_back(V3D(2.0,0.0,0.0)); TS_ASSERT_EQUALS(A.getNPoints(),1); TS_ASSERT_EQUALS(A.getPoints(),pntOut); - std::vector<double> Dist; - //Dist.push_back(2.0); + std::list<double> Dist; Dist.push_back(2.0); TS_ASSERT_EQUALS(A.getDistance(),Dist); } @@ -67,19 +66,13 @@ public: A.Accept(B); // change for forward only intercept TS_ASSERT_EQUALS(A.getNPoints(),1); - std::vector<V3D> pntOut; - pntOut=A.getPoints(); - //TS_ASSERT_DELTA(pntOut[0].X(),-1,0.0000001); - //TS_ASSERT_DELTA(pntOut[0].Y(),0.0,0.0000001); - //TS_ASSERT_DELTA(pntOut[0].Z(),0.0,0.0000001); - TS_ASSERT_DELTA(pntOut[0].X(),1,0.0000001); - TS_ASSERT_DELTA(pntOut[0].Y(),0.0,0.0000001); - TS_ASSERT_DELTA(pntOut[0].Z(),0.0,0.0000001); + const auto &pntOut = A.getPoints(); + TS_ASSERT_DELTA(pntOut.front().X(),1,0.0000001); + TS_ASSERT_DELTA(pntOut.front().Y(),0.0,0.0000001); + TS_ASSERT_DELTA(pntOut.front().Z(),0.0,0.0000001); - std::vector<double> Dist; - Dist=A.getDistance(); - TS_ASSERT_DELTA(Dist[0],1.0,0.0000001); - //TS_ASSERT_DELTA(Dist[1],1.0,0.0000001); + const auto &Dist = A.getDistance(); + TS_ASSERT_DELTA(Dist.front(),1.0,0.0000001); } void testAcceptCylinder(){ @@ -92,13 +85,13 @@ public: TS_ASSERT_EQUALS(B.getNormal(),V3D(0,1,0)); A.Accept(B); - std::vector<V3D> pntOut; + std::list<V3D> pntOut; // forward only //pntOut.push_back(V3D(-1.0,0.0,0.0)); pntOut.push_back(V3D(1.0,0.0,0.0)); TS_ASSERT_EQUALS(A.getNPoints(),1); TS_ASSERT_EQUALS(A.getPoints(),pntOut); - std::vector<double> Dist; + std::list<double> Dist; //Dist.push_back(1.0); Dist.push_back(1.0); TS_ASSERT_EQUALS(A.getDistance(),Dist); @@ -106,14 +99,12 @@ public: LineIntersectVisit C(V3D(1.1,0.0,0.0),V3D(-1.0,0.0,0.0)); C.Accept(B); TS_ASSERT_EQUALS(C.getNPoints(),2); - std::vector<V3D> pntOut2; + std::list<V3D> pntOut2; pntOut2.push_back(V3D(-1.0,0.0,0.0)); pntOut2.push_back(V3D(1.0,0.0,0.0)); TS_ASSERT_EQUALS(C.getPoints(),pntOut2); } - void testAcceptGeneral(){ - } private: std::string extractString(const Surface& pv) diff --git a/Code/Mantid/Framework/Geometry/test/LineTest.h b/Code/Mantid/Framework/Geometry/test/LineTest.h index b0a2f59dc0f65faa9c49d77c0826223f6d39c6bd..2b2d4fcf56ba7cf89d7751afbed3022420f72784 100644 --- a/Code/Mantid/Framework/Geometry/test/LineTest.h +++ b/Code/Mantid/Framework/Geometry/test/LineTest.h @@ -142,13 +142,12 @@ public: TS_ASSERT_EQUALS(B.getRadius(),1); TS_ASSERT_EQUALS(B.getNormal(),V3D(0,1,0)); - std::vector<V3D> pntOut; + std::list<V3D> pntOut; A.intersect(pntOut,B); // forward only solution for cylinders - TS_ASSERT_EQUALS(pntOut.size(),1); - //TS_ASSERT_EQUALS(pntOut[0],V3D(-1.0,0.0,0.0)); - TS_ASSERT_EQUALS(pntOut[0],V3D(1.0,0.0,0.0)); + TS_ASSERT_EQUALS(pntOut.size(),1); + TS_ASSERT_EQUALS(pntOut.front(),V3D(1.0,0.0,0.0)); } //A Line with equation equivalent to x axis will cut A Cylinder with 1 radius with center at 0,0,0 y axis normal @@ -164,12 +163,13 @@ public: TS_ASSERT_EQUALS(B.getRadius(),1); TS_ASSERT_EQUALS(B.getNormal(),V3D(0,1,0)); - std::vector<V3D> pntOut; + std::list<V3D> pntOut; A.intersect(pntOut,B); - TS_ASSERT_EQUALS(pntOut.size(),2); - TS_ASSERT_EQUALS(pntOut[0],V3D(1.0,0.0,0.0)); - TS_ASSERT_EQUALS(pntOut[1],V3D(-1.0,0.0,0.0)); + TS_ASSERT_EQUALS(pntOut.size(),2); + auto itr = pntOut.begin(); + TS_ASSERT_EQUALS(*(itr++), V3D(1.0,0.0,0.0)); + TS_ASSERT_EQUALS(*itr,V3D(-1.0,0.0,0.0)); } //A Line with equation equivalent to x axis will cut a plane YZ with equation x=5 will cut at one point 5,0,0 @@ -181,11 +181,11 @@ public: Plane B; TS_ASSERT_EQUALS(B.setSurface("px 5 0 0"),0); - std::vector<V3D> pntOut; + std::list<V3D> pntOut; A.intersect(pntOut,B); - TS_ASSERT_EQUALS(pntOut.size(),1); - TS_ASSERT_EQUALS(pntOut[0],V3D(5.0,0.0,0.0)); + TS_ASSERT_EQUALS(pntOut.size(),1); + TS_ASSERT_EQUALS(pntOut.front(),V3D(5.0,0.0,0.0)); } //A Line with equation equivalent to x axis will cut A sphere with 2 radius with center at 0,0,0 @@ -197,12 +197,11 @@ public: Sphere B; B.setSurface("s 0.0 0.0 0.0 2"); - std::vector<V3D> pntOut; + std::list<V3D> pntOut; A.intersect(pntOut,B); // forward only solutions - TS_ASSERT_EQUALS(pntOut.size(),1); - //TS_ASSERT_EQUALS(pntOut[0],V3D(-2.0,0.0,0.0)); - TS_ASSERT_EQUALS(pntOut[0],V3D(2.0,0.0,0.0)); + TS_ASSERT_EQUALS(pntOut.size(),1); + TS_ASSERT_EQUALS(pntOut.front(),V3D(2.0,0.0,0.0)); } //A Line with equation equivalent to x axis starting at -10 will cut A sphere with 2 radius with center at 0,0,0 @@ -214,11 +213,12 @@ public: Sphere B; B.setSurface("s 0.0 0.0 0.0 2"); - std::vector<V3D> pntOut; + std::list<V3D> pntOut; A.intersect(pntOut,B); - TS_ASSERT_EQUALS(pntOut.size(),2); - TS_ASSERT_EQUALS(pntOut[0],V3D(2.0,0.0,0.0)); - TS_ASSERT_EQUALS(pntOut[1],V3D(-2.0,0.0,0.0)); + TS_ASSERT_EQUALS(pntOut.size(),2); + auto itr = pntOut.begin(); + TS_ASSERT_EQUALS(*(itr++), V3D(2.0,0.0,0.0)); + TS_ASSERT_EQUALS(*itr, V3D(-2.0,0.0,0.0)); } };