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: testG4Box.cc,v 1.9 2006/06/29 18:45:53 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ |
---|
29 | // |
---|
30 | |
---|
31 | // testG4Box |
---|
32 | // Ensure asserts are compiled in |
---|
33 | |
---|
34 | #include <assert.h> |
---|
35 | #include <cmath> |
---|
36 | |
---|
37 | #include "globals.hh" |
---|
38 | #include "geomdefs.hh" |
---|
39 | |
---|
40 | #include "ApproxEqual.hh" |
---|
41 | |
---|
42 | #include "G4ThreeVector.hh" |
---|
43 | #include "G4Box.hh" |
---|
44 | #include "G4RotationMatrix.hh" |
---|
45 | #include "G4AffineTransform.hh" |
---|
46 | #include "G4VoxelLimits.hh" |
---|
47 | |
---|
48 | G4bool testG4Box() |
---|
49 | { |
---|
50 | G4ThreeVector pzero(0,0,0); |
---|
51 | G4ThreeVector ponxside(20,0,0),ponyside(0,30,0),ponzside(0,0,40); |
---|
52 | G4ThreeVector ponmxside(-20,0,0),ponmyside(0,-30,0),ponmzside(0,0,-40); |
---|
53 | G4ThreeVector ponzsidey(0,25,40),ponmzsidey(0,25,-40); |
---|
54 | |
---|
55 | G4ThreeVector pbigx(100,0,0),pbigy(0,100,0),pbigz(0,0,100); |
---|
56 | G4ThreeVector pbigmx(-100,0,0),pbigmy(0,-100,0),pbigmz(0,0,-100); |
---|
57 | |
---|
58 | G4ThreeVector vx(1,0,0),vy(0,1,0),vz(0,0,1); |
---|
59 | G4ThreeVector vmx(-1,0,0),vmy(0,-1,0),vmz(0,0,-1); |
---|
60 | G4ThreeVector vxy(1/std::sqrt(2.0),1/std::sqrt(2.0),0); |
---|
61 | G4ThreeVector vmxy(-1/std::sqrt(2.0),1/std::sqrt(2.0),0); |
---|
62 | G4ThreeVector vmxmy(-1/std::sqrt(2.0),-1/std::sqrt(2.0),0); |
---|
63 | G4ThreeVector vxmy(1/std::sqrt(2.0),-1/std::sqrt(2.0),0); |
---|
64 | G4ThreeVector vxmz(1/std::sqrt(2.0),0,-1/std::sqrt(2.0)); |
---|
65 | |
---|
66 | G4double Dist; |
---|
67 | G4ThreeVector *pNorm,norm; |
---|
68 | G4bool *pgoodNorm,goodNorm,calcNorm=true; |
---|
69 | |
---|
70 | pNorm=&norm; |
---|
71 | pgoodNorm=&goodNorm; |
---|
72 | |
---|
73 | G4Box b1("Test Box #1",20,30,40); |
---|
74 | G4Box b2("Test Box #2",10,10,10); |
---|
75 | G4Box box3("BABAR Box",0.14999999999999999, |
---|
76 | 24.707000000000001, |
---|
77 | 22.699999999999999) ; |
---|
78 | |
---|
79 | // Check name |
---|
80 | assert(b1.GetName()=="Test Box #1"); |
---|
81 | |
---|
82 | // Check cubic volume |
---|
83 | |
---|
84 | assert(b2.GetCubicVolume() == 8000); |
---|
85 | assert(b1.GetCubicVolume() == 192000); |
---|
86 | |
---|
87 | // Check Inside |
---|
88 | assert(b1.Inside(pzero)==kInside); |
---|
89 | assert(b1.Inside(pbigz)==kOutside); |
---|
90 | assert(b1.Inside(ponxside)==kSurface); |
---|
91 | assert(b1.Inside(ponyside)==kSurface); |
---|
92 | assert(b1.Inside(ponzside)==kSurface); |
---|
93 | |
---|
94 | // Check Surface Normal |
---|
95 | G4ThreeVector normal; |
---|
96 | |
---|
97 | // Normals on Surface |
---|
98 | normal=b1.SurfaceNormal(ponxside); |
---|
99 | assert(ApproxEqual(normal,G4ThreeVector(1,0,0))); |
---|
100 | normal=b1.SurfaceNormal(ponmxside); |
---|
101 | assert(ApproxEqual(normal,G4ThreeVector(-1,0,0))); |
---|
102 | normal=b1.SurfaceNormal(ponyside); |
---|
103 | assert(ApproxEqual(normal,G4ThreeVector(0,1,0))); |
---|
104 | normal=b1.SurfaceNormal(ponmyside); |
---|
105 | assert(ApproxEqual(normal,G4ThreeVector(0,-1,0))); |
---|
106 | normal=b1.SurfaceNormal(ponzside); |
---|
107 | assert(ApproxEqual(normal,G4ThreeVector(0,0,1))); |
---|
108 | normal=b1.SurfaceNormal(ponmzside); |
---|
109 | assert(ApproxEqual(normal,G4ThreeVector(0,0,-1))); |
---|
110 | normal=b1.SurfaceNormal(ponzsidey); |
---|
111 | assert(ApproxEqual(normal,G4ThreeVector(0,0,1))); |
---|
112 | normal=b1.SurfaceNormal(ponmzsidey); |
---|
113 | assert(ApproxEqual(normal,G4ThreeVector(0,0,-1))); |
---|
114 | |
---|
115 | // Normals on Edges |
---|
116 | G4ThreeVector edgeXY( 20.0, 30., 0.0); |
---|
117 | G4ThreeVector edgemXmY( -20.0, -30., 0.0); |
---|
118 | G4ThreeVector edgeXmY( 20.0, -30., 0.0); |
---|
119 | G4ThreeVector edgemXY( -20.0, 30., 0.0); |
---|
120 | G4ThreeVector edgeXZ( 20.0, 0.0, 40.0); |
---|
121 | G4ThreeVector edgemXmZ( -20.0, 0.0, -40.0); |
---|
122 | G4ThreeVector edgeXmZ( 20.0, 0.0, -40.0); |
---|
123 | G4ThreeVector edgemXZ( -20.0, 0.0, 40.0); |
---|
124 | G4ThreeVector edgeYZ( 0.0, 30.0, 40.0); |
---|
125 | G4ThreeVector edgemYmZ( 0.0, -30.0, -40.0); |
---|
126 | G4ThreeVector edgeYmZ( 0.0, 30.0, -40.0); |
---|
127 | G4ThreeVector edgemYZ( 0.0, -30.0, 40.0); |
---|
128 | |
---|
129 | G4double invSqrt2 = 1.0 / std::sqrt( 2.0); |
---|
130 | G4double invSqrt3 = 1.0 / std::sqrt( 3.0); |
---|
131 | |
---|
132 | normal= b1.SurfaceNormal( edgeXY ); |
---|
133 | assert(ApproxEqual( normal, G4ThreeVector( invSqrt2, invSqrt2, 0.0) )); |
---|
134 | // G4cout << " Normal at " << edgeXY << " is " << normal |
---|
135 | // << " Expected is " << G4ThreeVector( invSqrt2, invSqrt2, 0.0) << G4endl; |
---|
136 | normal= b1.SurfaceNormal( edgemXmY ); |
---|
137 | assert(ApproxEqual( normal, G4ThreeVector( -invSqrt2, -invSqrt2, 0.0) )); |
---|
138 | normal= b1.SurfaceNormal( edgeXmY ); |
---|
139 | assert(ApproxEqual( normal, G4ThreeVector( invSqrt2, -invSqrt2, 0.0) )); |
---|
140 | normal= b1.SurfaceNormal( edgemXY ); |
---|
141 | assert(ApproxEqual( normal, G4ThreeVector( -invSqrt2, invSqrt2, 0.0) )); |
---|
142 | |
---|
143 | normal= b1.SurfaceNormal( edgeXZ ); |
---|
144 | assert(ApproxEqual( normal, G4ThreeVector( invSqrt2, 0.0, invSqrt2) )); |
---|
145 | normal= b1.SurfaceNormal( edgemXmZ ); |
---|
146 | assert(ApproxEqual( normal, G4ThreeVector( -invSqrt2, 0.0, -invSqrt2) )); |
---|
147 | normal= b1.SurfaceNormal( edgeXmZ ); |
---|
148 | assert(ApproxEqual( normal, G4ThreeVector( invSqrt2, 0.0, -invSqrt2) )); |
---|
149 | normal= b1.SurfaceNormal( edgemXZ ); |
---|
150 | assert(ApproxEqual( normal, G4ThreeVector( -invSqrt2, 0.0, invSqrt2) )); |
---|
151 | |
---|
152 | normal= b1.SurfaceNormal( edgeYZ ); |
---|
153 | assert(ApproxEqual( normal, G4ThreeVector( 0.0, invSqrt2, invSqrt2) )); |
---|
154 | normal= b1.SurfaceNormal( edgemYmZ ); |
---|
155 | assert(ApproxEqual( normal, G4ThreeVector( 0.0, -invSqrt2, -invSqrt2) )); |
---|
156 | normal= b1.SurfaceNormal( edgeYmZ ); |
---|
157 | assert(ApproxEqual( normal, G4ThreeVector( 0.0, invSqrt2, -invSqrt2) )); |
---|
158 | normal= b1.SurfaceNormal( edgemYZ ); |
---|
159 | assert(ApproxEqual( normal, G4ThreeVector( 0.0, -invSqrt2, invSqrt2) )); |
---|
160 | |
---|
161 | // Normals on corners |
---|
162 | G4ThreeVector cornerXYZ( 20.0, 30., 40.0); |
---|
163 | G4ThreeVector cornermXYZ( -20.0, 30., 40.0); |
---|
164 | G4ThreeVector cornerXmYZ( 20.0, -30., 40.0); |
---|
165 | G4ThreeVector cornermXmYZ( -20.0, -30., 40.0); |
---|
166 | G4ThreeVector cornerXYmZ( 20.0, 30., -40.0); |
---|
167 | G4ThreeVector cornermXYmZ( -20.0, 30., -40.0); |
---|
168 | G4ThreeVector cornerXmYmZ( 20.0, -30., -40.0); |
---|
169 | G4ThreeVector cornermXmYmZ( -20.0, -30., -40.0); |
---|
170 | |
---|
171 | normal= b1.SurfaceNormal( cornerXYZ ); |
---|
172 | assert(ApproxEqual( normal, G4ThreeVector( invSqrt3, invSqrt3, invSqrt3) )); |
---|
173 | normal= b1.SurfaceNormal( cornermXYZ ); |
---|
174 | assert(ApproxEqual( normal, G4ThreeVector( -invSqrt3, invSqrt3, invSqrt3) )); |
---|
175 | normal= b1.SurfaceNormal( cornerXmYZ ); |
---|
176 | assert(ApproxEqual( normal, G4ThreeVector( invSqrt3, -invSqrt3, invSqrt3) )); |
---|
177 | normal= b1.SurfaceNormal( cornermXmYZ ); |
---|
178 | assert(ApproxEqual( normal, G4ThreeVector( -invSqrt3, -invSqrt3, invSqrt3) )); |
---|
179 | normal= b1.SurfaceNormal( cornerXYmZ ); |
---|
180 | assert(ApproxEqual( normal, G4ThreeVector( invSqrt3, invSqrt3, -invSqrt3) )); |
---|
181 | normal= b1.SurfaceNormal( cornermXYmZ ); |
---|
182 | assert(ApproxEqual( normal, G4ThreeVector( -invSqrt3, invSqrt3, -invSqrt3) )); |
---|
183 | normal= b1.SurfaceNormal( cornerXmYmZ ); |
---|
184 | assert(ApproxEqual( normal, G4ThreeVector( invSqrt3, -invSqrt3, -invSqrt3) )); |
---|
185 | normal= b1.SurfaceNormal( cornermXmYmZ ); |
---|
186 | assert(ApproxEqual( normal, G4ThreeVector( -invSqrt3, -invSqrt3, -invSqrt3) )); |
---|
187 | |
---|
188 | // DistanceToOut(P) |
---|
189 | Dist=b1.DistanceToOut(pzero); |
---|
190 | assert(ApproxEqual(Dist,20)); |
---|
191 | Dist=b1.DistanceToOut(vx); |
---|
192 | assert(ApproxEqual(Dist,19)); |
---|
193 | Dist=b1.DistanceToOut(vy); |
---|
194 | assert(ApproxEqual(Dist,20)); |
---|
195 | Dist=b1.DistanceToOut(vz); |
---|
196 | assert(ApproxEqual(Dist,20)); |
---|
197 | |
---|
198 | // DistanceToOut(P,V) |
---|
199 | Dist=b1.DistanceToOut(pzero,vx,calcNorm,pgoodNorm,pNorm); |
---|
200 | assert(ApproxEqual(Dist,20)&&ApproxEqual(*pNorm,vx)&&*pgoodNorm); |
---|
201 | Dist=b1.DistanceToOut(pzero,vmx,calcNorm,pgoodNorm,pNorm); |
---|
202 | assert(ApproxEqual(Dist,20)&&ApproxEqual(norm,vmx)&&*pgoodNorm); |
---|
203 | Dist=b1.DistanceToOut(pzero,vy,calcNorm,pgoodNorm,pNorm); |
---|
204 | assert(ApproxEqual(Dist,30)&&ApproxEqual(norm,vy)&&*pgoodNorm); |
---|
205 | Dist=b1.DistanceToOut(pzero,vmy,calcNorm,pgoodNorm,pNorm); |
---|
206 | assert(ApproxEqual(Dist,30)&&ApproxEqual(norm,vmy)&&*pgoodNorm); |
---|
207 | Dist=b1.DistanceToOut(pzero,vz,calcNorm,pgoodNorm,pNorm); |
---|
208 | assert(ApproxEqual(Dist,40)&&ApproxEqual(norm,vz)&&*pgoodNorm); |
---|
209 | Dist=b1.DistanceToOut(pzero,vmz,calcNorm,pgoodNorm,pNorm); |
---|
210 | assert(ApproxEqual(Dist,40)&&ApproxEqual(norm,vmz)&&*pgoodNorm); |
---|
211 | Dist=b1.DistanceToOut(pzero,vxy,calcNorm,pgoodNorm,pNorm); |
---|
212 | assert(ApproxEqual(Dist,std::sqrt(800.))&&*pgoodNorm); |
---|
213 | |
---|
214 | Dist=b1.DistanceToOut(ponxside,vx,calcNorm,pgoodNorm,pNorm); |
---|
215 | assert(ApproxEqual(Dist,0)&&ApproxEqual(*pNorm,vx)&&*pgoodNorm); |
---|
216 | Dist=b1.DistanceToOut(ponxside,vmx,calcNorm,pgoodNorm,pNorm); |
---|
217 | assert(ApproxEqual(Dist,40)&&ApproxEqual(*pNorm,vmx)&&*pgoodNorm); |
---|
218 | Dist=b1.DistanceToOut(pbigx,vy,calcNorm,pgoodNorm,pNorm); |
---|
219 | // G4cout<<"b1.DistanceToOut(ponxside,vy) = "<<Dist<<G4endl; |
---|
220 | assert(ApproxEqual(Dist,30)&&ApproxEqual(*pNorm,vy)&&*pgoodNorm); |
---|
221 | Dist=b1.DistanceToOut(ponmxside,vmx,calcNorm,pgoodNorm,pNorm); |
---|
222 | assert(ApproxEqual(Dist,0)&&ApproxEqual(norm,vmx)&&*pgoodNorm); |
---|
223 | Dist=b1.DistanceToOut(ponyside,vy,calcNorm,pgoodNorm,pNorm); |
---|
224 | assert(ApproxEqual(Dist,0)&&ApproxEqual(norm,vy)&&*pgoodNorm); |
---|
225 | Dist=b1.DistanceToOut(ponmyside,vmy,calcNorm,pgoodNorm,pNorm); |
---|
226 | assert(ApproxEqual(Dist,0)&&ApproxEqual(norm,vmy)&&*pgoodNorm); |
---|
227 | Dist=b1.DistanceToOut(ponzside,vz,calcNorm,pgoodNorm,pNorm); |
---|
228 | assert(ApproxEqual(Dist,0)&&ApproxEqual(norm,vz)&&*pgoodNorm); |
---|
229 | Dist=b1.DistanceToOut(ponmzside,vmz,calcNorm,pgoodNorm,pNorm); |
---|
230 | assert(ApproxEqual(Dist,0)&&ApproxEqual(norm,vmz)&&*pgoodNorm); |
---|
231 | |
---|
232 | //DistanceToIn(P) |
---|
233 | Dist=b1.DistanceToIn(pbigx); |
---|
234 | assert(ApproxEqual(Dist,80)); |
---|
235 | Dist=b1.DistanceToIn(pbigmx); |
---|
236 | assert(ApproxEqual(Dist,80)); |
---|
237 | Dist=b1.DistanceToIn(pbigy); |
---|
238 | assert(ApproxEqual(Dist,70)); |
---|
239 | Dist=b1.DistanceToIn(pbigmy); |
---|
240 | assert(ApproxEqual(Dist,70)); |
---|
241 | Dist=b1.DistanceToIn(pbigz); |
---|
242 | assert(ApproxEqual(Dist,60)); |
---|
243 | Dist=b1.DistanceToIn(pbigmz); |
---|
244 | assert(ApproxEqual(Dist,60)); |
---|
245 | |
---|
246 | // DistanceToIn(P,V) |
---|
247 | Dist=b1.DistanceToIn(pbigx,vmx); |
---|
248 | assert(ApproxEqual(Dist,80)); |
---|
249 | Dist=b1.DistanceToIn(pbigmx,vx); |
---|
250 | assert(ApproxEqual(Dist,80)); |
---|
251 | Dist=b1.DistanceToIn(pbigy,vmy); |
---|
252 | assert(ApproxEqual(Dist,70)); |
---|
253 | Dist=b1.DistanceToIn(pbigmy,vy); |
---|
254 | assert(ApproxEqual(Dist,70)); |
---|
255 | Dist=b1.DistanceToIn(pbigz,vmz); |
---|
256 | assert(ApproxEqual(Dist,60)); |
---|
257 | Dist=b1.DistanceToIn(pbigmz,vz); |
---|
258 | assert(ApproxEqual(Dist,60)); |
---|
259 | Dist=b1.DistanceToIn(pbigx,vxy); |
---|
260 | assert(ApproxEqual(Dist,kInfinity)); |
---|
261 | Dist=b1.DistanceToIn(pbigmx,vxy); |
---|
262 | assert(ApproxEqual(Dist,kInfinity)); |
---|
263 | |
---|
264 | G4ThreeVector pJohnXZ(9,0,12); |
---|
265 | Dist = b2.DistanceToIn(pJohnXZ,vxmz) ; |
---|
266 | // G4cout<<"b2.DistanceToIn(pJohnXZ,vxmz) = "<<Dist<<G4endl ; |
---|
267 | assert(ApproxEqual(Dist,kInfinity)); |
---|
268 | |
---|
269 | G4ThreeVector pJohnXY(12,9,0); |
---|
270 | Dist = b2.DistanceToIn(pJohnXY,vmxy) ; |
---|
271 | // G4cout<<"b2.DistanceToIn(pJohnXY,vmxy) = "<<Dist<<G4endl ; |
---|
272 | assert(ApproxEqual(Dist,kInfinity)); |
---|
273 | |
---|
274 | Dist = b2.DistanceToIn(pJohnXY,vmx) ; |
---|
275 | // G4cout<<"b2.DistanceToIn(pJohnXY,vmx) = "<<Dist<<G4endl ; |
---|
276 | assert(ApproxEqual(Dist,2)); |
---|
277 | |
---|
278 | G4ThreeVector pMyXY(32,-11,0); |
---|
279 | Dist = b2.DistanceToIn(pMyXY,vmxy) ; |
---|
280 | // G4cout<<"b2.DistanceToIn(pMyXY,vmxy) = "<<Dist<<G4endl ; |
---|
281 | assert(ApproxEqual(Dist,kInfinity)); |
---|
282 | |
---|
283 | Dist = b1.DistanceToIn(G4ThreeVector(-25,-35,0),vx) ; |
---|
284 | assert(ApproxEqual(Dist,kInfinity)); |
---|
285 | |
---|
286 | Dist = b1.DistanceToIn(G4ThreeVector(-25,-35,0),vy) ; |
---|
287 | assert(ApproxEqual(Dist,kInfinity)); |
---|
288 | |
---|
289 | |
---|
290 | Dist = b2.DistanceToIn(pJohnXY,vmx) ; |
---|
291 | // G4cout<<"b2.DistanceToIn(pJohnXY,vmx) = "<<Dist<<G4endl ; |
---|
292 | assert(ApproxEqual(Dist,2)); |
---|
293 | |
---|
294 | Dist=box3.DistanceToIn(G4ThreeVector( 0.15000000000000185, |
---|
295 | -22.048743592955137, |
---|
296 | 2.4268539333219472), |
---|
297 | G4ThreeVector(-0.76165597579890043, |
---|
298 | 0.64364445891356026, |
---|
299 | -0.074515708658524193)) ; |
---|
300 | assert(ApproxEqual(Dist,0.0)); |
---|
301 | |
---|
302 | // G4cout<<"BABAR box distance = "<<Dist<<G4endl ; |
---|
303 | |
---|
304 | |
---|
305 | |
---|
306 | |
---|
307 | |
---|
308 | // CalculateExtent |
---|
309 | G4VoxelLimits limit; // Unlimited |
---|
310 | G4RotationMatrix noRot; |
---|
311 | G4AffineTransform origin; |
---|
312 | G4double min,max; |
---|
313 | assert(b1.CalculateExtent(kXAxis,limit,origin,min,max)); |
---|
314 | assert(ApproxEqual(min,-20)&&ApproxEqual(max,20)); |
---|
315 | assert(b1.CalculateExtent(kYAxis,limit,origin,min,max)); |
---|
316 | assert(ApproxEqual(min,-30)&&ApproxEqual(max,30)); |
---|
317 | assert(b1.CalculateExtent(kZAxis,limit,origin,min,max)); |
---|
318 | assert(ApproxEqual(min,-40)&&ApproxEqual(max,40)); |
---|
319 | |
---|
320 | G4ThreeVector pmxmymz(-100,-110,-120); |
---|
321 | G4AffineTransform tPosOnly(pmxmymz); |
---|
322 | assert(b1.CalculateExtent(kXAxis,limit,tPosOnly,min,max)); |
---|
323 | assert(ApproxEqual(min,-120)&&ApproxEqual(max,-80)); |
---|
324 | assert(b1.CalculateExtent(kYAxis,limit,tPosOnly,min,max)); |
---|
325 | assert(ApproxEqual(min,-140)&&ApproxEqual(max,-80)); |
---|
326 | assert(b1.CalculateExtent(kZAxis,limit,tPosOnly,min,max)); |
---|
327 | assert(ApproxEqual(min,-160)&&ApproxEqual(max,-80)); |
---|
328 | |
---|
329 | G4RotationMatrix r90Z; |
---|
330 | r90Z.rotateZ(halfpi); |
---|
331 | G4AffineTransform tRotZ(r90Z,pzero); |
---|
332 | assert(b1.CalculateExtent(kXAxis,limit,tRotZ,min,max)); |
---|
333 | assert(ApproxEqual(min,-30)&&ApproxEqual(max,30)); |
---|
334 | assert(b1.CalculateExtent(kYAxis,limit,tRotZ,min,max)); |
---|
335 | assert(ApproxEqual(min,-20)&&ApproxEqual(max,20)); |
---|
336 | assert(b1.CalculateExtent(kZAxis,limit,tRotZ,min,max)); |
---|
337 | assert(ApproxEqual(min,-40)&&ApproxEqual(max,40)); |
---|
338 | |
---|
339 | // Check that clipped away |
---|
340 | G4VoxelLimits xClip; |
---|
341 | xClip.AddLimit(kXAxis,-100,-50); |
---|
342 | assert(!b1.CalculateExtent(kXAxis,xClip,origin,min,max)); |
---|
343 | |
---|
344 | // Assert clipped to volume |
---|
345 | G4VoxelLimits allClip; |
---|
346 | allClip.AddLimit(kXAxis,-5,+5); |
---|
347 | allClip.AddLimit(kYAxis,-5,+5); |
---|
348 | allClip.AddLimit(kZAxis,-5,+5); |
---|
349 | G4RotationMatrix genRot; |
---|
350 | genRot.rotateX(pi/6); |
---|
351 | genRot.rotateY(pi/6); |
---|
352 | genRot.rotateZ(pi/6); |
---|
353 | G4AffineTransform tGen(genRot,vx); |
---|
354 | assert(b1.CalculateExtent(kXAxis,allClip,tGen,min,max)); |
---|
355 | assert(ApproxEqual(min,-5)&&ApproxEqual(max,5)); |
---|
356 | assert(b1.CalculateExtent(kYAxis,allClip,tGen,min,max)); |
---|
357 | assert(ApproxEqual(min,-5)&&ApproxEqual(max,5)); |
---|
358 | assert(b1.CalculateExtent(kZAxis,allClip,tGen,min,max)); |
---|
359 | assert(ApproxEqual(min,-5)&&ApproxEqual(max,5)); |
---|
360 | |
---|
361 | G4VoxelLimits buggyClip2; |
---|
362 | buggyClip2.AddLimit(kXAxis,5,15); |
---|
363 | assert(b1.CalculateExtent(kXAxis,buggyClip2,origin,min,max)); |
---|
364 | assert(ApproxEqual(min,5)&&ApproxEqual(max,15)); |
---|
365 | assert(b1.CalculateExtent(kYAxis,buggyClip2,origin,min,max)); |
---|
366 | assert(ApproxEqual(min,-30)&&ApproxEqual(max,30)); |
---|
367 | assert(b1.CalculateExtent(kZAxis,buggyClip2,origin,min,max)); |
---|
368 | assert(ApproxEqual(min,-40)&&ApproxEqual(max,40)); |
---|
369 | |
---|
370 | buggyClip2.AddLimit(kYAxis,5,15); |
---|
371 | assert(b1.CalculateExtent(kXAxis,buggyClip2,origin,min,max)); |
---|
372 | assert(ApproxEqual(min,5)&&ApproxEqual(max,15)); |
---|
373 | assert(b1.CalculateExtent(kYAxis,buggyClip2,origin,min,max)); |
---|
374 | assert(ApproxEqual(min,5)&&ApproxEqual(max,15)); |
---|
375 | assert(b1.CalculateExtent(kZAxis,buggyClip2,origin,min,max)); |
---|
376 | assert(ApproxEqual(min,-40)&&ApproxEqual(max,40)); |
---|
377 | |
---|
378 | G4VoxelLimits buggyClip1; |
---|
379 | buggyClip1.AddLimit(kXAxis,-5,+5); |
---|
380 | assert(b1.CalculateExtent(kXAxis,buggyClip1,origin,min,max)); |
---|
381 | assert(ApproxEqual(min,-5)&&ApproxEqual(max,5)); |
---|
382 | assert(b1.CalculateExtent(kYAxis,buggyClip1,origin,min,max)); |
---|
383 | assert(ApproxEqual(min,-30)&&ApproxEqual(max,30)); |
---|
384 | assert(b1.CalculateExtent(kZAxis,buggyClip1,origin,min,max)); |
---|
385 | assert(ApproxEqual(min,-40)&&ApproxEqual(max,40)); |
---|
386 | buggyClip1.AddLimit(kYAxis,-5,+5); |
---|
387 | assert(b1.CalculateExtent(kXAxis,buggyClip1,origin,min,max)); |
---|
388 | assert(ApproxEqual(min,-5)&&ApproxEqual(max,5)); |
---|
389 | assert(b1.CalculateExtent(kYAxis,buggyClip1,origin,min,max)); |
---|
390 | assert(ApproxEqual(min,-5)&&ApproxEqual(max,5)); |
---|
391 | assert(b1.CalculateExtent(kZAxis,buggyClip1,origin,min,max)); |
---|
392 | assert(ApproxEqual(min,-40)&&ApproxEqual(max,40)); |
---|
393 | |
---|
394 | /* ********************************************************** |
---|
395 | */ ///////////////////////////////////////////////////// |
---|
396 | |
---|
397 | return true; |
---|
398 | } |
---|
399 | |
---|
400 | int main() |
---|
401 | { |
---|
402 | #ifdef NDEBUG |
---|
403 | G4Exception("FAIL: *** Assertions must be compiled in! ***"); |
---|
404 | #endif |
---|
405 | assert(testG4Box()); |
---|
406 | return 0; |
---|
407 | } |
---|
408 | |
---|