source: trunk/source/geometry/solids/specific/test/testG4GenericTrap.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: 43.8 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//
28//
29// testG4GenericTrap
30//
31// Test file for class G4GenericTrap, derived from testG4ExtrudedSolid
32// In the functions createSolidN(...), there are defined several
33// test cases of arbitrary trapezoid solid. These functions also fill in
34// the vectors with explicitely defined points inside, on the surface
35// and outside the solid.
36// All the test results for the definesd solids and
37// points can be printed via PrintResults() function.
38// The tests are then defined in testXYZ() functions
39// using assert() on the comparison with the expected*
40// result value.
41//
42// The functions DistanceToIn, DistanceToOut on surface
43// point do not give always expected values, that's why
44// they are not yet included in the tests with assert.
45// To be added tests for SurfaceNormal(p) function.
46// Ensure asserts are compileed in.
47//
48// Author:
49//   Ivana Hrivnacova, IPN Orsay*
50//
51// Adapted for G4GenericTrap by  Tatiana Nikitina
52
53#include <assert.h>
54#include <cmath>
55#include <vector>
56#include <iomanip>
57
58#include "globals.hh"
59
60#include "G4TwoVector.hh"
61#include "G4ThreeVector.hh"
62#include "G4GenericTrap.hh"
63#include "G4Box.hh"
64#include "G4UnionSolid.hh"
65#include "G4GeometryTolerance.hh"
66#include "G4Timer.hh"
67
68G4double kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
69
70G4ThreeVector dirx(1,0,0);
71G4ThreeVector diry(0,1,0);
72G4ThreeVector dirz(0,0,1);
73//_____________________________________________________________________________
74G4VSolid* createSolid0(std::vector<G4ThreeVector>& inside_points,
75                       std::vector<G4ThreeVector>& surface_points,
76                       std::vector<G4ThreeVector>& outside_points)
77{
78  // 1 down vertex: 0=1=2=3 
79  inside_points.push_back(G4ThreeVector(  0.0*cm, -45.0*cm, 70.0*cm));
80 
81  surface_points.push_back(G4ThreeVector( 0.0*cm, -45.0*cm,  75.0*cm));
82
83  outside_points.push_back(G4ThreeVector(  0.0*cm, -45.0*cm,  80.0*cm));
84  outside_points.push_back(G4ThreeVector( 50.0*cm, -20.0*cm,  30.0*cm));
85  outside_points.push_back(G4ThreeVector(-40.0*cm, -20.0*cm,  40.0*cm));
86  outside_points.push_back(G4ThreeVector(  0.0*cm,   0.0*cm,  30.0*cm));
87  outside_points.push_back(G4ThreeVector(-80.0*cm,   0.0*cm, -30.0*cm));
88
89  std::vector<G4TwoVector> vertices;
90  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
91  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
92  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
93  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
94  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
95  vertices.push_back(G4TwoVector(  0.*cm, -75.*cm));
96  vertices.push_back(G4TwoVector(-30.*cm, -75.*cm));
97  vertices.push_back(G4TwoVector( 15.*cm, -15.*cm));
98 
99  return new G4GenericTrap("genTrap0", 75.*cm, vertices);
100}                             
101
102//_____________________________________________________________________________
103G4VSolid* createSolid1(std::vector<G4ThreeVector>& inside_points,
104                       std::vector<G4ThreeVector>& surface_points,
105                       std::vector<G4ThreeVector>& outside_points)
106{
107// 2 down vertices: 0=1 2=3
108
109  inside_points.push_back(G4ThreeVector( -15.0*cm, -74.0 *cm, 74.0 *cm));
110  inside_points.push_back(G4ThreeVector(  -5.0*cm, -74.0*cm,  70.0*cm)); 
111 
112  surface_points.push_back(G4ThreeVector(   0.0*cm,  -75*cm,     0.0*cm));
113  surface_points.push_back(G4ThreeVector(  35.0*cm,  -15.0*cm,  75.0*cm));
114  surface_points.push_back(G4ThreeVector( -15.0*cm,  -75.0*cm, -75.0*cm));
115 
116
117  outside_points.push_back(G4ThreeVector(  0.0*cm,  0.0*cm,  0.0*cm));
118  outside_points.push_back(G4ThreeVector(  5.0*cm,  5.0*cm,  40.0*cm));
119  outside_points.push_back(G4ThreeVector( -5.0*cm, -5.0*cm, -40.0*cm));
120  outside_points.push_back(G4ThreeVector(-35.0*cm,  0.0*cm,  10.0*cm));
121  outside_points.push_back(G4ThreeVector(+35.0*cm,  0.0*cm, -10.0*cm));
122  outside_points.push_back(G4ThreeVector( -5.0*cm,-40.0*cm, -20.0*cm));
123  outside_points.push_back(G4ThreeVector(  5.0*cm, 40.0*cm,  10.0*cm));
124
125  std::vector<G4TwoVector> vertices;
126  vertices.push_back(G4TwoVector(   0.*cm, -75.*cm));
127  vertices.push_back(G4TwoVector(   0.*cm, -75.*cm));
128  vertices.push_back(G4TwoVector( -30.*cm, -75.*cm));
129  vertices.push_back(G4TwoVector( -30.*cm, -75.*cm));
130  vertices.push_back(G4TwoVector(  45.*cm, -15.*cm));
131  vertices.push_back(G4TwoVector(   0.*cm, -75.*cm));
132  vertices.push_back(G4TwoVector( -30.*cm, -75.*cm));
133  vertices.push_back(G4TwoVector(  15.*cm, -15.*cm));
134 
135  return new G4GenericTrap("genTrap1", 75.*cm, vertices);
136}                             
137
138//_____________________________________________________________________________
139G4VSolid* createSolid2(std::vector<G4ThreeVector>& inside_points,
140                       std::vector<G4ThreeVector>& surface_points,
141                       std::vector<G4ThreeVector>& outside_points)
142{
143// 1 up vertex: 4=5=6=7
144
145
146   
147    // Add points on surface
148  inside_points.push_back(G4ThreeVector( 30.0*cm, -20.0*cm,   0.0*cm));
149  inside_points.push_back(G4ThreeVector( 10.0*cm, -50.0*cm, -20.0*cm));
150  inside_points.push_back(G4ThreeVector( 44.0*cm, -16.0*cm,  20.0*cm)); 
151 
152  surface_points.push_back(G4ThreeVector( 45.0*cm, -15.0*cm, -25.0*cm));
153  surface_points.push_back(G4ThreeVector( 45.0*cm, -15.0*cm,  75.0*cm));
154  surface_points.push_back(G4ThreeVector(-10.0*cm, -75.0*cm, -75.0*cm));
155 
156
157  outside_points.push_back(G4ThreeVector(  0.0*cm,  0.0*cm,  30.0*cm));
158  outside_points.push_back(G4ThreeVector( 10.0*cm,  5.0*cm, -40.0*cm));
159  outside_points.push_back(G4ThreeVector(  0.0*cm,  0.0*cm,   0.0*cm));
160  outside_points.push_back(G4ThreeVector(-40.0*cm,  0.0*cm,  10.0*cm));
161  outside_points.push_back(G4ThreeVector( 40.0*cm,  0.0*cm, -10.0*cm));
162
163  std::vector<G4TwoVector> vertices;
164  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
165  vertices.push_back(G4TwoVector(  0.*cm, -75.*cm));
166  vertices.push_back(G4TwoVector(-30.*cm, -75.*cm));
167  vertices.push_back(G4TwoVector( 15.*cm, -15.*cm));
168  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
169  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
170  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
171  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
172 
173  return new G4GenericTrap("genTrap2", 75.*cm, vertices);
174}                             
175
176
177//_____________________________________________________________________________
178G4VSolid* createSolid3(std::vector<G4ThreeVector>& inside_points,
179                       std::vector<G4ThreeVector>& surface_points,
180                       std::vector<G4ThreeVector>& outside_points)
181{
182// 2 up vertices: 4=5 6=7
183
184  inside_points.push_back(G4ThreeVector( -10.0*cm,  -50.0*cm, -35.0*cm));
185  inside_points.push_back(G4ThreeVector( -10.0*cm,  -74.0*cm,   0.0*cm));
186  inside_points.push_back(G4ThreeVector( -15.0*cm,  -74.0*cm, -74.0*cm));
187   
188  surface_points.push_back(G4ThreeVector( 0.0*cm,  -75.0*cm,   0.0*cm));
189  surface_points.push_back(G4ThreeVector( 15.0*cm, -75.0*cm,  75.0*cm));
190  surface_points.push_back(G4ThreeVector( -15.0*cm, -75.0*cm,   -75.0*cm));
191
192  outside_points.push_back(G4ThreeVector(-50.0*cm, 10.0*cm, -50.0*cm));
193  outside_points.push_back(G4ThreeVector( 25.0*cm,  0.0*cm,  10.0*cm));
194  outside_points.push_back(G4ThreeVector( -5.0*cm,  5.0*cm,  15.0*cm));
195  outside_points.push_back(G4ThreeVector( 45.0*cm, 40.0*cm,  45.0*cm));
196
197  std::vector<G4TwoVector> vertices;
198  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
199  vertices.push_back(G4TwoVector(  0.*cm, -75.*cm));
200  vertices.push_back(G4TwoVector(-30.*cm, -75.*cm));
201  vertices.push_back(G4TwoVector( 15.*cm, -15.*cm));
202  vertices.push_back(G4TwoVector(  0.*cm, -75.*cm));
203  vertices.push_back(G4TwoVector(  0.*cm, -75.*cm));
204  vertices.push_back(G4TwoVector(-30.*cm, -75.*cm));
205  vertices.push_back(G4TwoVector(-30.*cm, -75.*cm));
206 
207  return new G4GenericTrap("genTrap3", 75.*cm, vertices);
208} 
209 
210
211//_____________________________________________________________________________
212G4VSolid* createSolid4(std::vector<G4ThreeVector>& inside_points,
213                       std::vector<G4ThreeVector>& surface_points,
214                       std::vector<G4ThreeVector>& outside_points)
215{
216// 4 down vertex:
217// 4 up vertices: Box like Solid
218
219  inside_points.push_back(G4ThreeVector(  0.0*cm,  0.0*cm,    0.0*cm));
220  inside_points.push_back(G4ThreeVector(-10.0*cm,  0.0*cm,    5.0*cm));
221  inside_points.push_back(G4ThreeVector( 15.0*cm,-15.0*cm,   74.0*cm));
222   
223  surface_points.push_back(G4ThreeVector( 45.0*cm, 45.0*cm, -75.0*cm));
224  surface_points.push_back(G4ThreeVector( 15.0*cm, 15.0*cm,  75.0*cm));
225  surface_points.push_back(G4ThreeVector(-15.0*cm, -15.0*cm, 75.0*cm));
226
227  outside_points.push_back(G4ThreeVector(  0.0*cm,  0.0*cm, -80.0*cm));
228  outside_points.push_back(G4ThreeVector(  5.0*cm,  0.0*cm,  80.0*cm));
229  outside_points.push_back(G4ThreeVector( 55.0*cm,  0.0*cm,  15.0*cm));
230  outside_points.push_back(G4ThreeVector(  0.0*cm, 55.0*cm, -15.0*cm));
231
232  std::vector<G4TwoVector> vertices;
233  vertices.push_back(G4TwoVector( -45.*cm, -45.*cm));
234  vertices.push_back(G4TwoVector( -45.*cm,  45.*cm));
235  vertices.push_back(G4TwoVector(  45.*cm,  45.*cm));
236  vertices.push_back(G4TwoVector(  45.*cm, -45.*cm));
237  vertices.push_back(G4TwoVector( -45.*cm, -45.*cm));
238  vertices.push_back(G4TwoVector( -45.*cm,  45.*cm));
239  vertices.push_back(G4TwoVector(  45.*cm,  45.*cm));
240  vertices.push_back(G4TwoVector(  45.*cm, -45.*cm));
241 
242  return new G4GenericTrap("genTrap4", 75.*cm, vertices);
243}             
244
245
246//_____________________________________________________________________________
247G4VSolid* createSolid5(std::vector<G4ThreeVector>& inside_points,
248                       std::vector<G4ThreeVector>& surface_points,
249                       std::vector<G4ThreeVector>& outside_points)
250{
251// 4 down vertices: 
252// 4 up vertex: Trap like Solid
253  inside_points.push_back(G4ThreeVector(   0.0*cm,  0.0*cm,   0.0*cm));
254  inside_points.push_back(G4ThreeVector( -10.0*cm,  0.0*cm,   5.0*cm));
255  inside_points.push_back(G4ThreeVector(  15.0*cm,-15.0*cm,  74.0*cm));
256   
257  surface_points.push_back(G4ThreeVector( 35.0*cm, 35.0*cm,   75.0*cm));
258  surface_points.push_back(G4ThreeVector( 35.0*cm,-35.0*cm,  -75.0*cm));
259  surface_points.push_back(G4ThreeVector( 30.0*cm, 30.0*cm,   75.0*cm));
260
261  outside_points.push_back(G4ThreeVector(-50.0*cm, 10.0*cm, -50.0*cm));
262  outside_points.push_back(G4ThreeVector( 55.0*cm,  0.0*cm,  10.0*cm));
263  outside_points.push_back(G4ThreeVector( 0.0*cm,  5.0*cm,  80.0*cm));
264  outside_points.push_back(G4ThreeVector( 5.0*cm, 0.0*cm,  -80.0*cm));
265
266  std::vector<G4TwoVector> vertices;
267  vertices.push_back(G4TwoVector( -45.*cm, -45.*cm));
268  vertices.push_back(G4TwoVector( -45.*cm,  45.*cm));
269  vertices.push_back(G4TwoVector(  45.*cm,  45.*cm));
270  vertices.push_back(G4TwoVector(  45.*cm, -45.*cm));
271  vertices.push_back(G4TwoVector( -35.*cm, -35.*cm));
272  vertices.push_back(G4TwoVector( -35.*cm,  35.*cm));
273  vertices.push_back(G4TwoVector(  35.*cm,  35.*cm));
274  vertices.push_back(G4TwoVector(  35.*cm, -35.*cm));
275 
276 
277  return new G4GenericTrap("arbTrap5", 75.*cm, vertices);
278}             
279
280//_____________________________________________________________________________
281G4VSolid* createSolid6(std::vector<G4ThreeVector>& inside_points,
282                       std::vector<G4ThreeVector>& surface_points,
283                       std::vector<G4ThreeVector>& outside_points)
284{
285  // all up & down vertices different, twisted
286  inside_points.push_back(G4ThreeVector(   0.0*cm,  0.0*cm,   0.0*cm));
287  inside_points.push_back(G4ThreeVector( -10.0*cm,  0.0*cm,   5.0*cm));
288  inside_points.push_back(G4ThreeVector(  15.0*cm, 15.0*cm,  74.0*cm));
289   
290  surface_points.push_back(G4ThreeVector( 35.0*cm, 35.0*cm,   75.0*cm));
291  surface_points.push_back(G4ThreeVector( 35.0*cm,-35.0*cm,  -75.0*cm));
292  surface_points.push_back(G4ThreeVector( 30.0*cm, 30.0*cm,   75.0*cm));
293
294  outside_points.push_back(G4ThreeVector(-50.0*cm, 10.0*cm, -50.0*cm));
295  outside_points.push_back(G4ThreeVector( 55.0*cm,  0.0*cm,  10.0*cm));
296  outside_points.push_back(G4ThreeVector(  0.0*cm,  5.0*cm,  80.0*cm));
297  outside_points.push_back(G4ThreeVector(  5.0*cm, 0.0*cm,  -80.0*cm));
298
299  std::vector<G4TwoVector> vertices;
300  vertices.push_back(G4TwoVector(-45.*cm, -45.*cm));
301  vertices.push_back(G4TwoVector(-45.*cm,  45.*cm));
302  vertices.push_back(G4TwoVector( 45.*cm,  45.*cm));
303  vertices.push_back(G4TwoVector( 45.*cm, -45.*cm));
304  vertices.push_back(G4TwoVector(-35.*cm, -35.*cm));
305  vertices.push_back(G4TwoVector(-35.*cm,  35.*cm));
306  vertices.push_back(G4TwoVector( 35.*cm,  35.*cm));
307  vertices.push_back(G4TwoVector( 35.*cm,  15.*cm));
308 
309  return new G4GenericTrap("genTrap6", 75.*cm, vertices);
310}             
311
312//_____________________________________________________________________________
313G4VSolid* createSolid7(std::vector<G4ThreeVector>& inside_points,
314                       std::vector<G4ThreeVector>& surface_points,
315                       std::vector<G4ThreeVector>& outside_points)
316{
317// 3 up vertices: 7=8 (twisted )
318 
319  inside_points.push_back(G4ThreeVector(   0.0*cm,  0.0*cm,   0.0*cm));
320  inside_points.push_back(G4ThreeVector( -10.0*cm,  0.0*cm,   5.0*cm));
321  inside_points.push_back(G4ThreeVector(  15.0*cm,-15.0*cm,  74.0*cm));
322   
323  surface_points.push_back(G4ThreeVector( 35.0*cm, 35.0*cm,   75.0*cm));
324  surface_points.push_back(G4ThreeVector( 35.0*cm,-35.0*cm,  -75.0*cm));
325  surface_points.push_back(G4ThreeVector( 30.0*cm, 30.0*cm,   75.0*cm));
326
327  outside_points.push_back(G4ThreeVector(-50.0*cm, 10.0*cm, -50.0*cm));
328  outside_points.push_back(G4ThreeVector( 55.0*cm,  0.0*cm,  10.0*cm));
329  outside_points.push_back(G4ThreeVector( 0.0*cm,  5.0*cm,  80.0*cm));
330  outside_points.push_back(G4ThreeVector( 5.0*cm, 0.0*cm,  -80.0*cm));
331
332  std::vector<G4TwoVector> vertices;
333  vertices.push_back(G4TwoVector(-45.*cm, -45.*cm));
334  vertices.push_back(G4TwoVector(-45.*cm,  45.*cm));
335  vertices.push_back(G4TwoVector( 45.*cm,  45.*cm));
336  vertices.push_back(G4TwoVector( 45.*cm, -45.*cm));
337  vertices.push_back(G4TwoVector( 35.*cm, -35.*cm));
338  vertices.push_back(G4TwoVector(-35.*cm, -35.*cm));
339  vertices.push_back(G4TwoVector( 35.*cm,  35.*cm));
340  vertices.push_back(G4TwoVector( 35.*cm,  35.*cm));
341 
342  return new G4GenericTrap("genTrap7", 75.*cm, vertices);
343}             
344
345//_____________________________________________________________________________
346G4VSolid* createSolid8(std::vector<G4ThreeVector>& /*inside_points*/,
347                       std::vector<G4ThreeVector>& /*surface_points*/,
348                       std::vector<G4ThreeVector>& /*outside_points*/)
349{
350// 3 up vertices: 4=5 (twisted )
351
352  std::vector<G4TwoVector> vertices;
353  vertices.push_back(G4TwoVector( 45.*cm, -15.*cm));
354  vertices.push_back(G4TwoVector(  0.*cm, -75.*cm));
355  vertices.push_back(G4TwoVector(-30.*cm, -75.*cm));
356  vertices.push_back(G4TwoVector( 15.*cm, -15.*cm));
357  vertices.push_back(G4TwoVector(  0.*cm, -75.*cm));
358  vertices.push_back(G4TwoVector(  0.*cm, -75.*cm));
359  vertices.push_back(G4TwoVector(-30.*cm, -75.*cm));
360  vertices.push_back(G4TwoVector( 15.*cm, -15.*cm));
361 
362  return new G4GenericTrap("genTrap8", 75.*cm, vertices);
363}             
364
365
366//_____________________________________________________________________________
367G4VSolid* createSolid(G4int testCase,
368                      std::vector<G4ThreeVector>& inside_points,
369                      std::vector<G4ThreeVector>& surface_points,
370                      std::vector<G4ThreeVector>& outside_points)
371{
372// Create selected test solid and fill vectors with points
373
374  switch ( testCase ) {
375    case 0: return createSolid0(inside_points, surface_points, outside_points);                 
376    case 1: return createSolid1(inside_points, surface_points, outside_points);                 
377    case 2: return createSolid2(inside_points, surface_points, outside_points);                 
378    case 3: return createSolid3(inside_points, surface_points, outside_points);                 
379    case 4: return createSolid4(inside_points, surface_points, outside_points);
380    case 5: return createSolid5(inside_points, surface_points, outside_points);                 
381    case 6: return createSolid6(inside_points, surface_points, outside_points);                 
382    case 7: return createSolid7(inside_points, surface_points, outside_points);                 
383    case 8: return createSolid8(inside_points, surface_points, outside_points);                 
384    default: return 0;
385  }
386}                     
387
388//_____________________________________________________________________________
389void printResults(G4int testCase)
390{
391 
392  std::vector<G4ThreeVector> inside_points;
393  std::vector<G4ThreeVector> surface_points;
394  std::vector<G4ThreeVector> outside_points;
395  G4VSolid* solid = createSolid(testCase, inside_points, surface_points, outside_points);
396
397  // Set precision
398  G4cout << std::setprecision(20) << G4endl;
399
400  //
401  // Test Inside
402  //
403
404  for (G4int i=0; i<G4int(inside_points.size()); ++i) { 
405    G4cout << i << "th inside_point Inside(p): " 
406           << solid->Inside(inside_points[i]) << G4endl;
407  } 
408  G4cout << G4endl;
409
410  for (G4int i=0; i<G4int(surface_points.size()); ++i) { 
411    G4cout << i << "th surface_point Inside(p): " 
412           << solid->Inside(surface_points[i]) << G4endl;
413  } 
414  G4cout << G4endl;
415
416  for (G4int i=0; i<G4int(outside_points.size()); ++i) { 
417    G4cout << i << "th outside_point Inside(p): " 
418           << solid->Inside(outside_points[i]) << G4endl;
419  } 
420  G4cout << G4endl;
421
422  //
423  // Test DistanceToIn(p, v)
424  //
425
426  for (G4int i=0; i<G4int(surface_points.size()); ++i) { 
427    G4cout << i << "th surface_point DistanceToIn(p, vx) " 
428           << solid->DistanceToIn(surface_points[i], dirx) << G4endl;
429    G4cout << i << "th surface_point DistanceToIn(p, -vx) " 
430           << solid->DistanceToIn(surface_points[i], -dirx) << G4endl;
431    G4cout << i << "th surface_point DistanceToIn(p, vy) " 
432           << solid->DistanceToIn(surface_points[i], diry) << G4endl;
433    G4cout << i << "th surface_point DistanceToIn(p, -vy) " 
434           << solid->DistanceToIn(surface_points[i], -diry) << G4endl;
435    G4cout << i << "th surface_point DistanceToIn(p, vz) " 
436           << solid->DistanceToIn(surface_points[i], dirz) << G4endl;
437    G4cout << i << "th surface_point DistanceToIn(p, -vz) " 
438           << solid->DistanceToIn(surface_points[i], -dirz) << G4endl;
439  }         
440  G4cout << G4endl;
441  //assert( false );
442
443
444  for (G4int i=0; i<G4int(outside_points.size()); ++i) { 
445    G4cout << i << "th outside_point DistanceToIn(p, vx) " 
446           << solid->DistanceToIn(outside_points[i], dirx) << G4endl;
447    G4cout << i << "th outside_point DistanceToIn(p, -vx) " 
448           << solid->DistanceToIn(outside_points[i], -dirx) << G4endl;
449    G4cout << i << "th outside_point DistanceToIn(p, vy) " 
450           << solid->DistanceToIn(outside_points[i], diry) << G4endl;
451    G4cout << i << "th outside_point DistanceToIn(p, -vy) " 
452           << solid->DistanceToIn(outside_points[i], -diry) << G4endl;
453    G4cout << i << "th outside_point DistanceToIn(p, vz) " 
454           << solid->DistanceToIn(outside_points[i], dirz) << G4endl;
455    G4cout << i << "th outside_point DistanceToIn(p, -vz) " 
456           << solid->DistanceToIn(outside_points[i], -dirz) << G4endl;
457  }         
458  G4cout << G4endl;
459
460  //
461  // Test DistanceToOut(p, v) function.
462  //
463           
464  for (G4int i=0; i<G4int(surface_points.size()); ++i) { 
465    G4cout << i << "th surface_point DistanceToOut(p, vx) " 
466           << solid->DistanceToOut(surface_points[i], dirx, false, 0, 0) << G4endl;
467    G4cout << i << "th surface_point DistanceToOut(p, -vx) " 
468           << solid->DistanceToOut(surface_points[i], -dirx, false, 0, 0) << G4endl;
469    G4cout << i << "th surface_point DistanceToOut(p, vy) " 
470           << solid->DistanceToOut(surface_points[i], diry, false, 0, 0) << G4endl;
471    G4cout << i << "th surface_point DistanceToOut(p, -vy) " 
472           << solid->DistanceToOut(surface_points[i], -diry, false, 0, 0) << G4endl;
473    G4cout << i << "th surface_point DistanceToOut(p, vz) " 
474           << solid->DistanceToOut(surface_points[i], dirz, false, 0, 0) << G4endl;
475    G4cout << i << "th surface_point DistanceToOut(p, -vz) " 
476           << solid->DistanceToOut(surface_points[i], -dirz, false, 0, 0) << G4endl;
477  }         
478  G4cout << G4endl;
479
480  for (G4int i=0; i<G4int(inside_points.size()); ++i) { 
481    G4cout << i << "th inside_point DistanceToOut(p, vx) " 
482           << solid->DistanceToOut(inside_points[i], dirx, false, 0, 0) << G4endl;
483    G4cout << i << "th inside_point DistanceToOut(p, -vx) " 
484           << solid->DistanceToOut(inside_points[i], -dirx, false, 0, 0) << G4endl;
485    G4cout << i << "th inside_point DistanceToOut(p, vy) " 
486           << solid->DistanceToOut(inside_points[i], diry, false, 0, 0) << G4endl;
487    G4cout << i << "th inside_point DistanceToOut(p, -vy) " 
488           << solid->DistanceToOut(inside_points[i], -diry, false, 0, 0) << G4endl;
489    G4cout << i << "th inside_point DistanceToOut(p, vz) " 
490           << solid->DistanceToOut(inside_points[i], dirz, false, 0, 0) << G4endl;
491    G4cout << i << "th inside_point DistanceToOut(p, -vz) " 
492           << solid->DistanceToOut(inside_points[i], -dirz, false, 0, 0) << G4endl;
493  }         
494  G4cout << G4endl;
495  //assert(false);
496  //
497  // Test surface area
498  //
499  G4cout << "Surface: " << solid->GetSurfaceArea() << G4endl;
500  G4cout << G4endl;
501 
502  //
503  // Test volume
504  //
505   G4int ntrial = 10;
506  G4double sum = 0;
507  G4double min = DBL_MAX;
508  G4double max = -DBL_MAX;
509 
510  G4cout << "Evaluating volume ..." << G4endl;
511  G4Timer time;
512  time.Start();
513  for (G4int i=0; i<ntrial; ++i ) {
514    G4VSolid* solid0 = createSolid(testCase, inside_points, surface_points, outside_points);
515    G4double value = solid0->GetCubicVolume();
516    sum += value;
517    if ( value < min ) min = value;
518    if ( value > max ) max = value;
519    delete solid0;
520  }
521  time.Stop();
522  G4cout << "Average volume after " << ntrial << " trials: " << sum/ntrial << G4endl;
523  G4cout << "               in the interval: " << max-min << G4endl;
524  G4cout << "Time taken was: " << time.GetRealElapsed() << " seconds. " << G4endl;
525  G4cout << G4endl;
526 
527
528  delete solid;
529}
530 
531
532//_____________________________________________________________________________
533void testInside(G4int testCase)
534{
535// Test Inside
536
537  std::vector<G4ThreeVector> inside_points;
538  std::vector<G4ThreeVector> surface_points;
539  std::vector<G4ThreeVector> outside_points;
540  G4VSolid* solid = createSolid(testCase, inside_points, surface_points, outside_points);
541 
542  //
543  // Test Inside
544  //
545 
546  for (G4int i=0; i<G4int(inside_points.size()); ++i) { 
547    assert( solid->Inside(inside_points[i]) == kInside );
548  } 
549
550  for (G4int i=0; i<G4int(surface_points.size()); ++i) { 
551   
552    assert( solid->Inside(surface_points[i]) == kSurface );
553  } 
554
555  for (G4int i=0; i<G4int(outside_points.size()); ++i) { 
556   
557    assert( solid->Inside(outside_points[i]) == kOutside );
558  } 
559 
560  delete solid;
561}
562
563//_____________________________________________________________________________
564void testDistanceToInPV(G4int testCase)
565{
566// Test DistanceToIn 
567
568  std::vector<G4ThreeVector> inside_points;
569  std::vector<G4ThreeVector> surface_points;
570  std::vector<G4ThreeVector> outside_points;
571  G4VSolid* solid = createSolid(testCase, inside_points, surface_points, outside_points);
572 
573  if ( testCase == 0 ) {
574    assert( std::fabs(solid->DistanceToIn(outside_points[0], -dirz) - 50.0 )< kCarTolerance );
575 
576    // For points on surface we get testDistanceToIn = 9e+99, is it ok ?
577  } 
578  else if ( testCase == 1 ) {
579    assert( std::fabs(solid->DistanceToIn(outside_points[0], -diry) - 450.0 )< kCarTolerance );
580    assert( std::fabs(solid->DistanceToIn(outside_points[1], -diry) - 340.0 )< kCarTolerance );
581    assert( std::fabs(solid->DistanceToIn(outside_points[2], -diry) - 560.0 )< kCarTolerance );
582    assert( std::fabs(solid->DistanceToIn(outside_points[5], -diry) - 130.0 )< kCarTolerance );
583    assert( std::fabs(solid->DistanceToIn(outside_points[6], -diry) - 810.0)< kCarTolerance );
584 
585    // Add points on surface
586  } 
587  else if ( testCase == 3 ) {
588    assert( std::fabs(solid->DistanceToIn(outside_points[2], -diry) - 560.0 )< kCarTolerance );
589    assert( std::fabs(solid->DistanceToIn(surface_points[1],  diry) -   0.0 )< kCarTolerance );
590   
591   
592    // Add points on surface
593  } 
594  else if ( testCase == 2 ) {
595    assert( std::fabs(solid->DistanceToIn(outside_points[1],  -diry) - 360.0 )< kCarTolerance );
596    assert( std::fabs(solid->DistanceToIn(outside_points[4],  -diry) - 150.0 )< kCarTolerance );
597    assert( std::fabs(solid->DistanceToIn(surface_points[0],  -dirx) -   0.0 )< kCarTolerance );
598    assert( std::fabs(solid->DistanceToIn(surface_points[0],   diry) -   0.0 )< kCarTolerance );
599    assert( std::fabs(solid->DistanceToIn(surface_points[0],  -diry) -   0.0 )< kCarTolerance );
600    assert( std::fabs(solid->DistanceToIn(surface_points[1],  -dirz) -   0.0 )< kCarTolerance );
601    assert( std::fabs(solid->DistanceToIn(surface_points[2],   diry) -   0.0 )< kCarTolerance );
602    assert( std::fabs(solid->DistanceToIn(surface_points[2],   dirz) -   0.0 )< kCarTolerance );
603   
604    // Add points on surface
605  } 
606
607  else if ( testCase == 4 ) {
608    assert( std::fabs(solid->DistanceToIn(outside_points[0],  dirz) -  50.0 )< kCarTolerance );
609    assert( std::fabs(solid->DistanceToIn(outside_points[1], -dirz) -  50.0 )< kCarTolerance );
610    assert( std::fabs(solid->DistanceToIn(outside_points[2], -dirx) - 100.0 )< kCarTolerance );
611    assert( std::fabs(solid->DistanceToIn(outside_points[3], -diry) - 100.0 )< kCarTolerance );
612    assert( std::fabs(solid->DistanceToIn(surface_points[0], -dirx) -   0.0 )< kCarTolerance );
613    assert( std::fabs(solid->DistanceToIn(surface_points[1], -dirz) -   0.0 )< kCarTolerance );
614    assert( std::fabs(solid->DistanceToIn(surface_points[2], -dirz) -   0.0 )< kCarTolerance );
615   
616   
617    // Add points on surface
618  } 
619
620  else if ( testCase == 5 ) {
621    assert( std::fabs(solid->DistanceToIn(outside_points[0],  dirx) - 66.6666666666667 )< kCarTolerance );
622    assert( std::fabs(solid->DistanceToIn(outside_points[1], -dirx) - 156.6666666666667 )< kCarTolerance );
623    assert( std::fabs(solid->DistanceToIn(outside_points[2], -dirz) - 50.0 )< kCarTolerance );
624    assert( std::fabs(solid->DistanceToIn(outside_points[3],  dirz) - 50.0 )< kCarTolerance );
625    assert( std::fabs(solid->DistanceToIn(surface_points[0], -dirx) -  0.0 )< kCarTolerance );
626    assert( std::fabs(solid->DistanceToIn(surface_points[1],  dirz) -  0.0 )< kCarTolerance );
627    assert( std::fabs(solid->DistanceToIn(surface_points[2], -dirz) -  0.0 )< kCarTolerance );
628   
629   
630    // Add points on surface
631  } 
632 
633  else if ( testCase == 6 ) {
634    assert( std::fabs(solid->DistanceToIn(outside_points[0],  dirx) - 66.6666666666667 )< kCarTolerance );
635    assert( std::fabs(solid->DistanceToIn(outside_points[1], -dirx) - 156.6666666666667 )< kCarTolerance );
636    assert( std::fabs(solid->DistanceToIn(outside_points[2], -dirz) - 50.0 )< kCarTolerance );
637    assert( std::fabs(solid->DistanceToIn(outside_points[3],  dirz) - 50.0 )< kCarTolerance );
638    assert( std::fabs(solid->DistanceToIn(surface_points[0], -dirx) -  0.0 )< kCarTolerance );
639    assert( std::fabs(solid->DistanceToIn(surface_points[1],  dirz) -  0.0 )< kCarTolerance );
640    assert( std::fabs(solid->DistanceToIn(surface_points[2], -dirz) -  0.0 )< kCarTolerance );
641   
642   
643    // Add points on surface
644  } 
645
646   else if ( testCase == 7 ) {
647    assert( std::fabs(solid->DistanceToIn(outside_points[0],  dirx) - 100.37037037037037 )< kCarTolerance );
648    assert( std::fabs(solid->DistanceToIn(outside_points[1], -dirx) - 159.94397759103646 )< kCarTolerance );
649    assert( std::fabs(solid->DistanceToIn(outside_points[2], -dirz) - 216.6666666666667 )< kCarTolerance );
650    assert( std::fabs(solid->DistanceToIn(outside_points[3],  dirz) -  50.0 )< kCarTolerance );
651    assert( std::fabs(solid->DistanceToIn(surface_points[0], -dirx) -  0.0 )< kCarTolerance );
652    assert( std::fabs(solid->DistanceToIn(surface_points[1],  dirz) -  0.0 )< kCarTolerance );
653    assert( std::fabs(solid->DistanceToIn(surface_points[2], -dirz) -  0.0 )< kCarTolerance );
654   
655   
656    // Add points on surface
657  } 
658
659  delete solid;
660}
661
662
663//_____________________________________________________________________________
664void testDistanceToOutPV(G4int testCase)
665{
666// Test DistanceToOutPV 
667
668  std::vector<G4ThreeVector> inside_points;
669  std::vector<G4ThreeVector> surface_points;
670  std::vector<G4ThreeVector> outside_points;
671  G4VSolid* solid = createSolid(testCase, inside_points, surface_points, outside_points);
672 
673  if ( testCase == 0 ) {
674    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirz) - 50.0 )< kCarTolerance );
675 
676    // For Add points on surface
677  } 
678  else if ( testCase == 1 ) {
679   
680    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirx) - 157.5 )< kCarTolerance );
681    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirx) - 142.5 )< kCarTolerance );
682    assert( std::fabs(solid->DistanceToOut(inside_points[0],  diry) - 190.0 )< kCarTolerance );
683    assert( std::fabs(solid->DistanceToOut(inside_points[0], -diry) - 10.0 )< kCarTolerance );
684    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirz) - 10.0 )< kCarTolerance );
685    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirz) - 1465.0 )< kCarTolerance );
686    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirx) - 57.5 )< kCarTolerance );
687    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirx) - 242.5 )< kCarTolerance );
688    assert( std::fabs(solid->DistanceToOut(inside_points[1], -diry) - 10.0 )< kCarTolerance );
689    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirz) - 50.0 )< kCarTolerance );
690    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirz) - 1425.0 )< kCarTolerance );
691 
692    // For Add points on surface
693  } 
694  else if ( testCase == 3 ) {
695    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirx) - 287.5 )< kCarTolerance );
696    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirx) - 12.5 )< kCarTolerance );
697    assert( std::fabs(solid->DistanceToOut(inside_points[0],  diry) - 16.666666666667 )< kCarTolerance );
698    assert( std::fabs(solid->DistanceToOut(inside_points[0], -diry) - 250.0 )< kCarTolerance );
699    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirz) - 475.0 )< kCarTolerance );
700    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirz) - 400.0 )< kCarTolerance );
701    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirx) - 107.5 )< kCarTolerance );
702    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirx) - 192.5 )< kCarTolerance );
703    assert( std::fabs(solid->DistanceToOut(inside_points[1],  diry) - 256.66666666667 )< kCarTolerance );
704    assert( std::fabs(solid->DistanceToOut(inside_points[1], -diry) - 10.0 )< kCarTolerance );
705    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirz) - 725.0 )< kCarTolerance );
706    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirz) -  750.0 )< kCarTolerance );
707    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirx) -  157.5 )< kCarTolerance );
708    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirx) -  142.5)< kCarTolerance );
709    assert( std::fabs(solid->DistanceToOut(inside_points[2],  diry) - 190.0 )< kCarTolerance );
710    assert( std::fabs(solid->DistanceToOut(inside_points[2], -diry) -  10.0 )< kCarTolerance );
711    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirz) -  1465.0 )< kCarTolerance );
712    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirz) - 10.0 )< kCarTolerance );
713 
714    // For Add points on surface
715  } 
716  else if ( testCase == 2 ) {
717    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirx) - 112.5 )< kCarTolerance );
718    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirx) - 37.5 )< kCarTolerance );
719    assert( std::fabs(solid->DistanceToOut(inside_points[0],  diry) - 50.0 )< kCarTolerance );
720    assert( std::fabs(solid->DistanceToOut(inside_points[0], -diry) - 150.0 )< kCarTolerance );
721    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirz) - 187.49999999999997158 )< kCarTolerance );
722    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirz) -  750.0 )< kCarTolerance );
723    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirx) -  87.5 )< kCarTolerance );
724    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirx) - 102.5 )< kCarTolerance );
725    assert( std::fabs(solid->DistanceToOut(inside_points[1], -diry) - 30.0 )< kCarTolerance );
726    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirz) - 75.0 )< kCarTolerance );
727    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirz) - 550.0 )< kCarTolerance );
728    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirx) -  2.4999999999999 )< kCarTolerance );
729    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirx) -  107.5 )< kCarTolerance );
730    assert( std::fabs(solid->DistanceToOut(inside_points[2],  diry) - 10.0 )< kCarTolerance );
731    assert( std::fabs(solid->DistanceToOut(inside_points[2], -diry) - 3.3333333333333333 )< kCarTolerance );
732    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirz) - 525.0 )< kCarTolerance );
733    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirz) -  950.0 )< kCarTolerance );
734   
735
736    // For Add points on surface
737  }   else if ( testCase == 4 ) {
738    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirx) - 450.0 )< kCarTolerance );
739    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirx) - 450.0 )< kCarTolerance );
740    assert( std::fabs(solid->DistanceToOut(inside_points[0],  diry) - 450.0 )< kCarTolerance );
741    assert( std::fabs(solid->DistanceToOut(inside_points[0], -diry) - 450.0 )< kCarTolerance );
742    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirz) - 750.0 )< kCarTolerance );
743    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirz) - 750.0 )< kCarTolerance );
744    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirx) - 550.0 )< kCarTolerance );
745    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirx) - 350.0 )< kCarTolerance );
746    assert( std::fabs(solid->DistanceToOut(inside_points[1],  diry) - 450.0 )< kCarTolerance );
747    assert( std::fabs(solid->DistanceToOut(inside_points[1], -diry) - 450.0 )< kCarTolerance );
748    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirz) - 700.0 )< kCarTolerance );
749    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirz) - 800.0 )< kCarTolerance );
750    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirx) - 300.0 )< kCarTolerance );
751    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirx) - 600.0)< kCarTolerance );
752    assert( std::fabs(solid->DistanceToOut(inside_points[2],  diry) - 600.0 )< kCarTolerance );
753    assert( std::fabs(solid->DistanceToOut(inside_points[2], -diry) - 300.0 )< kCarTolerance );
754    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirz) - 10.0 )< kCarTolerance );
755    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirz) - 1490.0 )< kCarTolerance );
756 
757    // For Add points on surface
758  } 
759    else if ( testCase == 5 ) {
760    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirx) - 400.0 )< kCarTolerance );
761    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirx) - 400.0 )< kCarTolerance );
762    assert( std::fabs(solid->DistanceToOut(inside_points[0],  diry) - 400.0 )< kCarTolerance );
763    assert( std::fabs(solid->DistanceToOut(inside_points[0], -diry) - 400.0 )< kCarTolerance );
764    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirz) - 750.0 )< kCarTolerance );
765    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirz) - 750.0 )< kCarTolerance );
766    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirx) - 496.6666666666667 )< kCarTolerance );
767    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirx) - 296.6666666666667 )< kCarTolerance );
768    assert( std::fabs(solid->DistanceToOut(inside_points[1],  diry) - 396.6666666666667 )< kCarTolerance );
769    assert( std::fabs(solid->DistanceToOut(inside_points[1], -diry) - 396.6666666666667 )< kCarTolerance );
770    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirz) - 700.0 )< kCarTolerance );
771    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirz) - 800.0 )< kCarTolerance );
772    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirx) - 200.6666666666667 )< kCarTolerance );
773    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirx) - 500.6666666666667)< kCarTolerance );
774    assert( std::fabs(solid->DistanceToOut(inside_points[2],  diry) - 500.6666666666667 )< kCarTolerance );
775    assert( std::fabs(solid->DistanceToOut(inside_points[2], -diry) - 200.6666666666667 )< kCarTolerance );
776    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirz) - 10.0 )< kCarTolerance );
777    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirz) - 1490.0 )< kCarTolerance );
778 
779    // For Add points on surface
780  } 
781
782   else if ( testCase == 6 ) {
783    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirx) - 400.0 )< kCarTolerance );
784    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirx) - 400.0 )< kCarTolerance );
785    assert( std::fabs(solid->DistanceToOut(inside_points[0],  diry) - 400.0 )< kCarTolerance );
786    assert( std::fabs(solid->DistanceToOut(inside_points[0], -diry) - 275.0 )< kCarTolerance );
787    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirz) - 750.0 )< kCarTolerance );
788    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirz) - 750.0 )< kCarTolerance );
789    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirx) - 496.6666666666667 )< kCarTolerance );
790    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirx) - 296.6666666666667 )< kCarTolerance );
791    assert( std::fabs(solid->DistanceToOut(inside_points[1],  diry) - 396.6666666666667 )< kCarTolerance );
792    assert( std::fabs(solid->DistanceToOut(inside_points[1], -diry) - 296.9467787114846 )< kCarTolerance );
793    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirz) - 700.0 )< kCarTolerance );
794    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirz) - 800.0 )< kCarTolerance );
795    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirx) - 200.6666666666667)< kCarTolerance );
796    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirx) - 500.6666666666667)< kCarTolerance );
797    assert( std::fabs(solid->DistanceToOut(inside_points[2],  diry) - 200.6666666666667 )< kCarTolerance );
798    assert( std::fabs(solid->DistanceToOut(inside_points[2], -diry) - 146.1070975918848 )< kCarTolerance );
799    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirz) - 10.0 )< kCarTolerance );
800    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirz) - 1490.0 )< kCarTolerance );
801 
802    // For Add points on surface
803  } 
804 
805     else if ( testCase == 7 ) {
806    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirx) - 400.0 )< kCarTolerance );
807    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirx) - 361.1111111111111 )< kCarTolerance );
808    assert( std::fabs(solid->DistanceToOut(inside_points[0],  diry) - 225.0 )< kCarTolerance );
809    assert( std::fabs(solid->DistanceToOut(inside_points[0], -diry) - 361.1111111111111 )< kCarTolerance );
810    assert( std::fabs(solid->DistanceToOut(inside_points[0],  dirz) - 750.0 )< kCarTolerance );
811    assert( std::fabs(solid->DistanceToOut(inside_points[0], -dirz) - 750.0 )< kCarTolerance );
812    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirx) - 496.6666666666667 )< kCarTolerance );
813    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirx) - 275.92592592592592 )< kCarTolerance );
814    assert( std::fabs(solid->DistanceToOut(inside_points[1],  diry) - 162.94117647058823 )< kCarTolerance );
815    assert( std::fabs(solid->DistanceToOut(inside_points[1], -diry) - 310.41666666666667 )< kCarTolerance );
816    assert( std::fabs(solid->DistanceToOut(inside_points[1],  dirz) - 437.97272126752415 )< kCarTolerance );
817    assert( std::fabs(solid->DistanceToOut(inside_points[1], -dirz) - 800.0 )< kCarTolerance );
818    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirx) - 196.39821029082771)< kCarTolerance );
819    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirx) - 304.32023010546504)< kCarTolerance );
820    assert( std::fabs(solid->DistanceToOut(inside_points[2],  diry) - 301.71673003802277 )< kCarTolerance );
821    assert( std::fabs(solid->DistanceToOut(inside_points[2], -diry) - 198.98689677213173 )< kCarTolerance );
822    assert( std::fabs(solid->DistanceToOut(inside_points[2],  dirz) -   9.99999999999999 )< kCarTolerance );
823    assert( std::fabs(solid->DistanceToOut(inside_points[2], -dirz) - 1490.0 )< kCarTolerance );
824 
825    // For Add points on surface
826  } 
827  delete solid;
828}
829
830//_____________________________________________________________________________
831void testSurface(G4int testCase) 
832{
833// Test surface
834
835  std::vector<G4ThreeVector> inside_points;
836  std::vector<G4ThreeVector> surface_points;
837  std::vector<G4ThreeVector> outside_points;
838  G4VSolid* solid = createSolid(testCase, inside_points, surface_points, outside_points);
839 
840  if ( testCase == 0 ) {
841    assert( std::fabs(solid->GetSurfaceArea() - 1779486.9168738 ) < 1e-6 );
842  }
843  if ( testCase == 1 ) {
844    assert( std::fabs(solid->GetSurfaceArea() - 2239664.8326421054) < 1e-6 );
845  }
846  if ( testCase == 2 ) {
847    assert( std::fabs(solid->GetSurfaceArea() - 1779486.9168738 ) < 1e-6 );
848  }
849  if ( testCase == 3 ) {
850    assert( std::fabs(solid->GetSurfaceArea() - 2239664.8326421054 ) < 1e-6 );
851  }
852
853   delete solid;
854} 
855   
856//_____________________________________________________________________________
857void testVolume(G4int testCase) 
858{
859// Test volume
860// The volume is evaluated via G4VSolid, that's why the precision is very low
861
862  std::vector<G4ThreeVector> inside_points;
863  std::vector<G4ThreeVector> surface_points;
864  std::vector<G4ThreeVector> outside_points;
865  G4VSolid* solid = createSolid(testCase, inside_points, surface_points, outside_points);
866 
867  if ( testCase == 0 ) {
868    assert( std::fabs(solid->GetCubicVolume() - 33138720.00020987168 ) < 1.0e+6 );
869  }
870  if ( testCase == 1 ) {
871    assert( std::fabs(solid->GetCubicVolume() - 8408880.00005325303 ) < 1.0e+6 );
872  }
873  if ( testCase == 2 ) {
874    assert( std::fabs(solid->GetCubicVolume() - 33191640.00021020696) < 1.0e+6 );
875  }
876 
877  if ( testCase == 3 ) {
878    assert( std::fabs(solid->GetCubicVolume() - 8743680.00005537 ) < 1.0e+6 );
879  }
880
881  delete solid;
882} 
883   
884
885//_____________________________________________________________________________
886int main()
887{
888  // Uncomment this line to print the results for a tested solid case
889  //   printResults(0);
890
891  for  ( G4int testCase = 0; testCase < 8; ++testCase ) { 
892    //G4cout<<"Test ="<<testCase<<G4endl;
893    testInside(testCase);
894    testDistanceToInPV(testCase);
895    testDistanceToOutPV(testCase);
896    testSurface(testCase);
897    testVolume(testCase);
898  }
899 
900  return 0;
901}
Note: See TracBrowser for help on using the repository browser.