source: trunk/source/geometry/solids/CSG/test/testG4Para2.cc @ 1316

Last change on this file since 1316 was 1316, checked in by garnier, 14 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 9.9 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: testG4Para2.cc,v 1.6 2006/06/29 18:46:03 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
29//
30// Test of G4Para
31// Includes all/most of the tests Done for a box
32
33#include <assert.h>
34#include <cmath>
35#include "G4ios.hh"
36
37#include "globals.hh"
38#include "geomdefs.hh"
39
40#include "ApproxEqual.hh"
41
42#include "G4ThreeVector.hh"
43#include "G4Para.hh"
44#include "G4RotationMatrix.hh"
45#include "G4AffineTransform.hh"
46#include "G4VoxelLimits.hh"
47
48
49
50//#include "G4ios.hh"
51//#include "globals.hh"
52//#include "G4Para.hh"
53
54#define DELTA 0.0001
55
56// Returns false if actual is within wanted+/- DELTA
57//         true if error
58G4bool OutRange(G4double actual,G4double wanted)
59{
60    G4bool rng=false;
61    if (actual<wanted-DELTA||actual>wanted+DELTA) rng=true;
62    return rng;
63}
64G4bool OutRange(G4ThreeVector actual,G4ThreeVector wanted)
65{
66    G4bool rng=false;
67    if (OutRange(actual.x(),wanted.x())
68        ||OutRange(actual.y(),wanted.y())
69        ||OutRange(actual.z(),wanted.z())  ) rng=true;
70    return rng;
71}
72
73int main(void)
74{
75    G4double Dist;
76    G4ThreeVector pzero(0,0,0),px(10,0,0),py(0,10,0),pz(0,0,10);
77    G4ThreeVector pbigx(100,0,0),pbigy(0,100,0),pbigz(0,0,100);
78    G4ThreeVector pbigmx(-100,0,0),pbigmy(0,-100,0),pbigmz(0,0,-100);
79    G4ThreeVector ponxside(20,0,0),ponyside(0,30,0),ponzside(0,0,40);
80    G4ThreeVector ponmxside(-20,0,0),ponmyside(0,-30,0),ponmzside(0,0,-40);
81    G4ThreeVector ponzsidey(0,25,40),ponmzsidey(0,25,-40);
82    G4RotationMatrix runit;
83    G4RotationMatrix r90X,r90Y,r90Z,r45X,r30Y;
84    G4ThreeVector vx(1,0,0),vy(0,1,0),vz(0,0,1);
85    G4ThreeVector vmx(-1,0,0),vmy(0,-1,0),vmz(0,0,-1);
86    G4ThreeVector vxy(1,1,0);
87    G4ThreeVector *pNorm,norm;
88    G4bool *pgoodNorm,goodNorm,calcNorm=true;
89
90    pNorm=&norm;
91    pgoodNorm=&goodNorm;
92
93    r90X.rotateX(halfpi);
94    r90Y.rotateY(halfpi);
95    r90Z.rotateZ(halfpi);
96    r45X.rotateX(pi/4);
97    r30Y.rotateY(pi/6);
98
99    vxy=vxy.unit();
100
101    G4Para p1("Box",20,30,40,0,0,0),
102        p2("2",50,50,50,pi/6,0,0),
103        p3("3",50,50,50,0,pi/6,0),
104        p4("4",50,50,50,0,0,pi/6),
105        p5("5",50,50,50,0,pi/6,pi/6),   
106        p6("6",50,50,50,pi/6,pi/6,pi/6);       
107
108    G4cout << "Name:"<< p1.GetName()
109         << " ID=" <<G4endl;
110   
111    G4cout << "Checking G4Para::Inside...\n";
112    if (p1.Inside(pzero)!=kInside)
113        G4cout << "Error A" << G4endl;
114    if (p1.Inside(pbigz)!=kOutside)
115        G4cout << "Error B" << G4endl;
116    if (p1.Inside(ponxside)!=kSurface)
117        G4cout << "Error C" << G4endl;
118    if (p1.Inside(ponyside)!=kSurface)
119        G4cout << "Error D" << G4endl;
120    if (p1.Inside(ponzside)!=kSurface)
121        G4cout << "Error E" << G4endl;
122
123
124
125    G4cout << "Checking G4Para::SurfaceNormal...\n";
126    norm=p1.SurfaceNormal(ponxside);
127    if (OutRange(norm,G4ThreeVector(1,0,0)))
128        G4cout << "Error A " << norm << G4endl;
129    norm=p1.SurfaceNormal(ponmxside);
130    if (OutRange(norm,G4ThreeVector(-1,0,0)))
131        G4cout << "Error B " << norm << G4endl;
132    norm=p1.SurfaceNormal(ponyside);
133    if (OutRange(norm,G4ThreeVector(0,1,0)))
134        G4cout << "Error C " << norm << G4endl;
135    norm=p1.SurfaceNormal(ponmyside);
136    if (OutRange(norm,G4ThreeVector(0,-1,0)))
137        G4cout << "Error D " << norm << G4endl;
138    norm=p1.SurfaceNormal(ponzside);
139    if (OutRange(norm,G4ThreeVector(0,0,1)))
140        G4cout << "Error E " << norm << G4endl;
141    norm=p1.SurfaceNormal(ponmzside);
142    if (OutRange(norm,G4ThreeVector(0,0,-1)))
143        G4cout << "Error F " << norm << G4endl;
144    norm=p1.SurfaceNormal(ponzsidey);
145    if (OutRange(norm,G4ThreeVector(0,0,1)))
146        G4cout << "Error G " << norm << G4endl;
147    norm=p1.SurfaceNormal(ponmzsidey);
148    if (OutRange(norm,G4ThreeVector(0,0,-1)))
149        G4cout << "Error H " << norm << G4endl;
150
151
152    G4cout << "Checking G4Para::DistanceToOut(P)...\n";
153    Dist=p1.DistanceToOut(pzero);
154    if (OutRange(Dist,20))
155        G4cout << "Error A1 " << Dist << G4endl;
156    Dist=p2.DistanceToOut(pzero);
157    if (OutRange(Dist,50*std::cos(pi/6)))
158        G4cout << "Error A2 " << Dist << G4endl;
159     Dist=p3.DistanceToOut(pzero);
160    if (OutRange(Dist,50*std::cos(pi/6)))
161        G4cout << "Error A3 " << Dist << G4endl;
162    Dist=p5.DistanceToOut(pzero);
163    if (OutRange(Dist,2*50/std::sqrt(5.)))
164        G4cout << "Error A4 " << Dist << G4endl;
165
166     Dist=p1.DistanceToOut(px);
167    if (OutRange(Dist,10))
168        G4cout << "Error B " << Dist << G4endl;
169    Dist=p1.DistanceToOut(py);
170    if (OutRange(Dist,20))
171        G4cout << "Error C " << Dist << G4endl;
172    Dist=p1.DistanceToOut(pz);
173    if (OutRange(Dist,20))
174        G4cout << "Error D " << Dist << G4endl;
175
176
177
178
179    G4cout << "Checking G4Para::DistanceToOut(P,V)...\n";
180
181    Dist=p1.DistanceToOut(pzero,vx,calcNorm,pgoodNorm,pNorm);
182    if (OutRange(Dist,20)||OutRange(*pNorm,vx)||!*pgoodNorm)
183        G4cout << "Error A " << Dist << G4endl;
184    Dist=p1.DistanceToOut(pzero,vmx,calcNorm,pgoodNorm,pNorm);
185    if (OutRange(Dist,20)||OutRange(norm,vmx)||!*pgoodNorm)
186        G4cout << "Error B " << Dist << G4endl;
187    Dist=p1.DistanceToOut(pzero,vy,calcNorm,pgoodNorm,pNorm);
188    if (OutRange(Dist,30)||OutRange(norm,vy)||!*pgoodNorm)
189        G4cout << "Error C " << Dist << G4endl;
190    Dist=p1.DistanceToOut(pzero,vmy,calcNorm,pgoodNorm,pNorm);
191    if (OutRange(Dist,30)||OutRange(norm,vmy)||!*pgoodNorm)
192        G4cout << "Error D " << Dist << G4endl;
193     Dist=p1.DistanceToOut(pzero,vz,calcNorm,pgoodNorm,pNorm);
194    if (OutRange(Dist,40)||OutRange(norm,vz)||!*pgoodNorm)
195        G4cout << "Error E " << Dist << G4endl;
196     Dist=p1.DistanceToOut(pzero,vmz,calcNorm,pgoodNorm,pNorm);
197    if (OutRange(Dist,40)||OutRange(norm,vmz)||!*pgoodNorm)
198        G4cout << "Error F " << Dist << G4endl;
199    Dist=p1.DistanceToOut(pzero,vxy,calcNorm,pgoodNorm,pNorm);
200    if (OutRange(Dist,std::sqrt(800.))||!*pgoodNorm)
201        G4cout << "Error F " << Dist << G4endl;
202
203    Dist=p1.DistanceToOut(ponxside,vx,calcNorm,pgoodNorm,pNorm);
204    if (OutRange(Dist,0)||OutRange(*pNorm,vx)||!*pgoodNorm)
205        G4cout << "Error A2 " << Dist << G4endl;
206    Dist=p1.DistanceToOut(ponmxside,vmx,calcNorm,pgoodNorm,pNorm);
207    if (OutRange(Dist,0)||OutRange(norm,vmx)||!*pgoodNorm)
208        G4cout << "Error B2 " << Dist << G4endl;
209    Dist=p1.DistanceToOut(ponyside,vy,calcNorm,pgoodNorm,pNorm);
210    if (OutRange(Dist,0)||OutRange(norm,vy)||!*pgoodNorm)
211        G4cout << "Error C2 " << Dist << G4endl;
212    Dist=p1.DistanceToOut(ponmyside,vmy,calcNorm,pgoodNorm,pNorm);
213    if (OutRange(Dist,0)||OutRange(norm,vmy)||!*pgoodNorm)
214        G4cout << "Error D2 " << Dist << G4endl;
215     Dist=p1.DistanceToOut(ponzside,vz,calcNorm,pgoodNorm,pNorm);
216    if (OutRange(Dist,0)||OutRange(norm,vz)||!*pgoodNorm)
217        G4cout << "Error E2 " << Dist << G4endl;
218    Dist=p1.DistanceToOut(ponmzside,vmz,calcNorm,pgoodNorm,pNorm);
219    if (OutRange(Dist,0)||OutRange(norm,vmz)||!*pgoodNorm)
220        G4cout << "Error F2 " << Dist << G4endl;
221 
222    G4cout << "Checking G4Para::DistanceToIn(P)...\n";
223    Dist=p1.DistanceToIn(pbigx);
224    if (OutRange(Dist,80))
225        G4cout << "Error A " << Dist << G4endl;
226    Dist=p1.DistanceToIn(pbigmx);
227    if (OutRange(Dist,80))
228        G4cout << "Error B " << Dist << G4endl;
229    Dist=p1.DistanceToIn(pbigy);
230    if (OutRange(Dist,70))
231        G4cout << "Error C " << Dist << G4endl;
232    Dist=p1.DistanceToIn(pbigmy);
233    if (OutRange(Dist,70))
234        G4cout << "Error D " << Dist << G4endl;
235    Dist=p1.DistanceToIn(pbigz);
236    if (OutRange(Dist,60))
237        G4cout << "Error E " << Dist << G4endl;
238    Dist=p1.DistanceToIn(pbigmz);
239    if (OutRange(Dist,60))
240        G4cout << "Error F " << Dist << G4endl;
241
242    Dist=p3.DistanceToIn(pbigx);
243    if (OutRange(Dist,50*std::cos(pi/6)))
244        G4cout << "Error G1 " << Dist <<G4endl;
245    Dist=p3.DistanceToIn(pbigy);
246    if (OutRange(Dist,50))
247        G4cout << "Error G2 " << Dist <<G4endl;
248
249    G4cout << "Checking G4Para::DistanceToIn(P,V)...\n";
250
251    Dist=p1.DistanceToIn(pbigx,vmx);
252    if (OutRange(Dist,80))
253        G4cout << "Error A " << Dist << G4endl;
254    Dist=p1.DistanceToIn(pbigmx,vx);
255    if (OutRange(Dist,80))
256        G4cout << "Error B " << Dist << G4endl;
257    Dist=p1.DistanceToIn(pbigy,vmy);
258    if (OutRange(Dist,70))
259        G4cout << "Error C " << Dist << G4endl;
260    Dist=p1.DistanceToIn(pbigmy,vy);
261    if (OutRange(Dist,70))
262        G4cout << "Error D " << Dist << G4endl;
263    Dist=p1.DistanceToIn(pbigz,vmz);
264    if (OutRange(Dist,60))
265        G4cout << "Error E " << Dist << G4endl;
266    Dist=p1.DistanceToIn(pbigmz,vz);
267    if (OutRange(Dist,60))
268        G4cout << "Error F " << Dist << G4endl;
269    Dist=p1.DistanceToIn(pbigx,vxy);
270    if (OutRange(Dist,kInfinity))
271        G4cout << "Error G " << Dist << G4endl;
272    Dist=p1.DistanceToIn(pbigmx,vxy);
273    if (OutRange(Dist,kInfinity))
274        G4cout << "Error H " << Dist << G4endl;
275
276    return 0;   
277}
278
279
280
281
Note: See TracBrowser for help on using the repository browser.