Skip to content

Commit 4a39c4b

Browse files
committedNov 28, 2024
Adding new files
1 parent b8063d3 commit 4a39c4b

File tree

2 files changed

+307
-0
lines changed

2 files changed

+307
-0
lines changed
 

‎test/testEllipse.cxx

+256
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
/*********************************************************************
2+
CombLayer : MCNP(X) Input builder
3+
4+
* File: test/testEllipse.cxx
5+
*
6+
* Copyright (c) 2004-2024 by Stuart Ansell
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
****************************************************************************/
22+
#include <fstream>
23+
#include <iomanip>
24+
#include <iostream>
25+
#include <sstream>
26+
#include <complex>
27+
#include <cmath>
28+
#include <list>
29+
#include <vector>
30+
#include <map>
31+
#include <string>
32+
#include <algorithm>
33+
#include <tuple>
34+
#include <random>
35+
36+
#include "FileReport.h"
37+
#include "NameStack.h"
38+
#include "RegMethod.h"
39+
#include "OutputLog.h"
40+
#include "BaseVisit.h"
41+
#include "BaseModVisit.h"
42+
#include "Vec3D.h"
43+
#include "Line.h"
44+
#include "Intersect.h"
45+
#include "Ellipse.h"
46+
47+
#include "testFunc.h"
48+
#include "testEllipse.h"
49+
50+
using namespace Geometry;
51+
52+
testEllipse::testEllipse()
53+
/*!
54+
Constructor
55+
*/
56+
{}
57+
58+
testEllipse::~testEllipse()
59+
/*!
60+
Destructor
61+
*/
62+
{}
63+
64+
int
65+
testEllipse::applyTest(const int extra)
66+
/*!
67+
Applies all the tests and returns
68+
the error number
69+
\param extra :: index of test
70+
\retval -1 Distance failed
71+
\retval 0 All succeeded
72+
*/
73+
{
74+
ELog::RegMethod RegA("testEllipse","applyTest");
75+
76+
TestFunc::regSector("testEllipse");
77+
typedef int (testEllipse::*testPtr)();
78+
testPtr TPtr[]=
79+
{
80+
&testEllipse::testLineIntercept,
81+
&testEllipse::testScaleFactor
82+
};
83+
const std::string TestName[]=
84+
{
85+
"lineIntercept",
86+
"ScaleFactor"
87+
};
88+
const int TSize(sizeof(TPtr)/sizeof(testPtr));
89+
if (!extra)
90+
{
91+
std::ios::fmtflags flagIO=std::cout.setf(std::ios::left);
92+
for(int i=0;i<TSize;i++)
93+
{
94+
std::cout<<std::setw(30)<<TestName[i]<<"("<<i+1<<")"<<std::endl;
95+
}
96+
std::cout.flags(flagIO);
97+
return 0;
98+
}
99+
for(int i=0;i<TSize;i++)
100+
{
101+
if (extra<0 || extra==i+1)
102+
{
103+
TestFunc::regTest(TestName[i]);
104+
const int retValue= (this->*TPtr[i])();
105+
if (retValue || extra>0)
106+
return retValue;
107+
}
108+
}
109+
return 0;
110+
}
111+
112+
113+
114+
115+
int
116+
testEllipse::testLineIntercept()
117+
/*!
118+
Test the scaleFactor
119+
\retval -1 :: failed build a cone
120+
\retval 0 :: All passed
121+
*/
122+
{
123+
ELog::RegMethod RegA("testEllipse","testLineIntercept");
124+
125+
// ellIndex lineIndex :Result number : Point A / Point B
126+
typedef std::tuple
127+
<size_t,size_t,size_t,Geometry::Vec3D,Geometry::Vec3D> resTYPE;
128+
129+
const std::vector<Geometry::Ellipse> ellTEST({
130+
{Geometry::Vec3D(0,0,0),Geometry::Vec3D(0,1.0,0),
131+
Geometry::Vec3D(0,0.0,1.0)}, // circle
132+
{Geometry::Vec3D(0,0,0),Geometry::Vec3D(0,1.0,0),
133+
Geometry::Vec3D(0,0.0,3.0)}, // orthogonal ellipse
134+
{Geometry::Vec3D(0,0,0),Geometry::Vec3D(0,1.0,2.0),
135+
Geometry::Vec3D(0,-0.5,3.0)} // non-orthogonal ellipse
136+
});
137+
138+
const std::vector<Geometry::Line> lineTEST({
139+
{Geometry::Vec3D(0,0,0),Geometry::Vec3D(0,1.0,0)},
140+
{Geometry::Vec3D(2.0,0,0),Geometry::Vec3D(3.0,1.0,0.0)},
141+
{Geometry::Vec3D(0.0,0.5,0.5),Geometry::Vec3D(0.0,1.0,0.0)}
142+
});
143+
144+
const std::vector<resTYPE> resTEST({
145+
{0,0,2,Geometry::Vec3D(0,-1.0,0),Geometry::Vec3D(0,1.0,0)},
146+
{0,1,2,Geometry::Vec3D(0,-1.0,0),Geometry::Vec3D(0,1.0,0)},
147+
{0,2,2,Geometry::Vec3D(0,-0.866025,0.5),Geometry::Vec3D(0,0.866025,0.5)},
148+
{1,0,2,Geometry::Vec3D(0,-1.0,0),Geometry::Vec3D(0,1.0,0)},
149+
{1,1,2,Geometry::Vec3D(0,-1.0,0),Geometry::Vec3D(0,1.0,0)},
150+
{1,2,2,Geometry::Vec3D(0,-0.866025,0.5),Geometry::Vec3D(0,0.866025,0.5)},
151+
{2,0,2,Geometry::Vec3D(0,-1.0,0),Geometry::Vec3D(0,1.0,0)},
152+
{2,1,2,Geometry::Vec3D(0,-1.0,0),Geometry::Vec3D(0,1.0,0)},
153+
{2,2,2,Geometry::Vec3D(0,-0.866025,0.5),Geometry::Vec3D(0,0.866025,0.5)}
154+
});
155+
156+
157+
int cnt(1);
158+
for(const resTYPE& tc : resTEST)
159+
{
160+
const size_t ellIndex(std::get<0>(tc));
161+
const size_t lineIndex(std::get<1>(tc));
162+
const size_t res(std::get<2>(tc));
163+
const Geometry::Vec3D& rPtA(std::get<3>(tc));
164+
const Geometry::Vec3D& rPtB(std::get<4>(tc));
165+
166+
const Geometry::Ellipse& E(ellTEST[ellIndex]);
167+
const Geometry::Line& L(lineTEST[lineIndex]);
168+
169+
Geometry::Vec3D APt,BPt;
170+
const size_t outIndex=E.lineIntercept(L,APt,BPt);
171+
// side return 0 if point is on side
172+
if (outIndex!=res ||
173+
(res==2 && (E.side(APt) || E.side(BPt))))
174+
{
175+
ELog::EM<<"Ellipse == "<<E<<ELog::endDiag;
176+
ELog::EM<<"Line == "<<L<<ELog::endDiag;
177+
ELog::EM<<"outIndex["<<res<<"] == "<<outIndex<<ELog::endDiag;
178+
if (outIndex>0)
179+
{
180+
ELog::EM<<"APt["<<rPtA<<"] == "<<APt<<ELog::endDiag;
181+
ELog::EM<<"BPt["<<rPtB<<"] == "<<BPt<<ELog::endDiag;
182+
ELog::EM<<"Side = "<<E.side(APt)<<" "<<E.side(BPt)
183+
<<ELog::endDiag;
184+
}
185+
return -1;
186+
}
187+
cnt++;
188+
}
189+
return 0;
190+
}
191+
192+
193+
int
194+
testEllipse::testScaleFactor()
195+
/*!
196+
Test the scaleFactor
197+
\retval -1 :: failed build a cone
198+
\retval 0 :: All passed
199+
*/
200+
{
201+
ELog::RegMethod RegA("testEllipse","testScaleFactor");
202+
203+
// Centre : max axis : min axis :: testPt scalefactor
204+
typedef std::tuple<Geometry::Vec3D,Geometry::Vec3D,Geometry::Vec3D,
205+
Geometry::Vec3D,double> TTYPE;
206+
const std::vector<TTYPE> Tests
207+
({
208+
{ Geometry::Vec3D(0,0,0),
209+
Geometry::Vec3D(0,1.0,0),Geometry::Vec3D(0,0.0,1.0),
210+
Geometry::Vec3D(0.0,1.0,1.0),std::sqrt(2.0)
211+
},
212+
{ Geometry::Vec3D(0,0,0),
213+
Geometry::Vec3D(0,1.0,0),Geometry::Vec3D(0,0.0,1.0),
214+
Geometry::Vec3D(0.0,4.0,0.0),4.0
215+
},
216+
{ Geometry::Vec3D(0,1.0,0),
217+
Geometry::Vec3D(0,1.0,0),Geometry::Vec3D(0,0.0,1.0),
218+
Geometry::Vec3D(0.0,4.0,0.0),3.0
219+
},
220+
{ Geometry::Vec3D(0,0.0,0),
221+
Geometry::Vec3D(0,2.0,0),Geometry::Vec3D(0,0.0,1.0),
222+
Geometry::Vec3D(0.0,4.0,0.0),2.0
223+
},
224+
{ Geometry::Vec3D(0,0.0,0),
225+
Geometry::Vec3D(0,2.0,0),Geometry::Vec3D(0,0.0,1.0),
226+
Geometry::Vec3D(0.0,4.0,3.0),3.60555
227+
}
228+
});
229+
230+
231+
int cnt(1);
232+
for(const TTYPE& tc : Tests)
233+
{
234+
const Geometry::Vec3D cent(std::get<0>(tc));
235+
const Geometry::Vec3D majAxis(std::get<1>(tc));
236+
const Geometry::Vec3D minAxis(std::get<2>(tc));
237+
const Geometry::Vec3D testPt(std::get<3>(tc));
238+
const double res(std::get<4>(tc));
239+
240+
const Geometry::Ellipse CX(cent,majAxis,minAxis);
241+
const double r=CX.scaleFactor(testPt);
242+
Geometry::Ellipse CY(CX);
243+
CY.scale(r);
244+
245+
if (std::abs(r-res)>1e-5 || CY.side(testPt)!=0)
246+
{
247+
ELog::EM<<"Test == "<<cnt<<ELog::endDiag;
248+
ELog::EM<<"CX == "<<CX<<ELog::endDiag;
249+
ELog::EM<<"CY == "<<CY<<ELog::endDiag;
250+
ELog::EM<<"CYside == "<<CY.side(testPt)<<ELog::endDiag;
251+
ELog::EM<<"result["<<res<<"] == "<<r<<ELog::endDiag;
252+
}
253+
cnt++;
254+
}
255+
return 0;
256+
}

‎testInclude/testEllipse.h

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*********************************************************************
2+
CombLayer : MCNP(X) Input builder
3+
4+
* File: testInclude/testEllipse.h
5+
*
6+
* Copyright (c) 2004-2024 by Stuart Ansell
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
****************************************************************************/
22+
#ifndef testEllipse_h
23+
#define testEllipse_h
24+
25+
/*!
26+
\class testEllipse
27+
\brief Tests the class Ellipse class
28+
\author S. Ansell
29+
\date Nov. 2024
30+
\version 1.0
31+
32+
Test the distance of a point to the ellipse
33+
*/
34+
35+
class testEllipse
36+
{
37+
private:
38+
39+
//Tests
40+
int testLineIntercept();
41+
int testScaleFactor();
42+
43+
public:
44+
45+
testEllipse();
46+
~testEllipse();
47+
48+
int applyTest(const int);
49+
};
50+
51+
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.