| 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: testG4Cons1.cc,v 1.8 2007/04/23 13:58:39 grichine Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-04-ref-00 $
|
|---|
| 29 | //
|
|---|
| 30 |
|
|---|
| 31 | // testG4Cons
|
|---|
| 32 | //
|
|---|
| 33 | // Test file for class G4Cons [NOT thorough]
|
|---|
| 34 | //
|
|---|
| 35 | // Ensure asserts are compiled in
|
|---|
| 36 |
|
|---|
| 37 | #include <assert.h>
|
|---|
| 38 | #include <cmath>
|
|---|
| 39 | #include "G4ios.hh"
|
|---|
| 40 | #include "globals.hh"
|
|---|
| 41 | #include "geomdefs.hh"
|
|---|
| 42 |
|
|---|
| 43 | #include "ApproxEqual.hh"
|
|---|
| 44 |
|
|---|
| 45 | #include "G4ThreeVector.hh"
|
|---|
| 46 | #include "G4Cons.hh"
|
|---|
| 47 | #include "G4RotationMatrix.hh"
|
|---|
| 48 | #include "G4AffineTransform.hh"
|
|---|
| 49 | #include "G4VoxelLimits.hh"
|
|---|
| 50 |
|
|---|
| 51 | G4bool testG4Cons()
|
|---|
| 52 | {
|
|---|
| 53 | G4ThreeVector pzero(0,0,0);
|
|---|
| 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 ponxside(50,0,0);
|
|---|
| 59 |
|
|---|
| 60 | G4ThreeVector vx(1,0,0),vy(0,1,0),vz(0,0,1);
|
|---|
| 61 | G4ThreeVector vmx(-1,0,0),vmy(0,-1,0),vmz(0,0,-1);
|
|---|
| 62 | G4ThreeVector vxy(1/std::sqrt(2.0),1/std::sqrt(2.0),0);
|
|---|
| 63 | G4ThreeVector vmxy(-1/std::sqrt(2.0),1/std::sqrt(2.0),0);
|
|---|
| 64 | G4ThreeVector vmxmy(-1/std::sqrt(2.0),-1/std::sqrt(2.0),0);
|
|---|
| 65 | G4ThreeVector vxmy(1/std::sqrt(2.0),-1/std::sqrt(2.0),0);
|
|---|
| 66 |
|
|---|
| 67 | G4double Dist;
|
|---|
| 68 | G4ThreeVector *pNorm,norm;
|
|---|
| 69 | G4bool *pgoodNorm,goodNorm,calcNorm=true;
|
|---|
| 70 |
|
|---|
| 71 | pNorm=&norm;
|
|---|
| 72 | pgoodNorm=&goodNorm;
|
|---|
| 73 |
|
|---|
| 74 | G4Cons t1("Solid TubeLike #1",0,50,0,50,50,0,360);
|
|---|
| 75 | G4Cons test10("test10",20.0, 80.0, 60.0, 140.0, 100.0,
|
|---|
| 76 | 0.17453292519943, 5.235987755983);
|
|---|
| 77 |
|
|---|
| 78 | G4Cons test10a( "aCone", 2*cm, 6*cm, 8*cm, 14*cm, 10*cm, 10*deg, 300*deg );
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | // Check name
|
|---|
| 83 | assert(t1.GetName()=="Solid TubeLike #1");
|
|---|
| 84 |
|
|---|
| 85 | // Check Inside
|
|---|
| 86 | assert(t1.Inside(pzero)==kInside);
|
|---|
| 87 | assert(t1.Inside(pbigx)==kOutside);
|
|---|
| 88 |
|
|---|
| 89 | // Check Surface Normal
|
|---|
| 90 | G4ThreeVector normal;
|
|---|
| 91 |
|
|---|
| 92 | normal=t1.SurfaceNormal(ponxside);
|
|---|
| 93 | assert(ApproxEqual(normal,vx));
|
|---|
| 94 |
|
|---|
| 95 | // DistanceToOut(P)
|
|---|
| 96 | Dist=t1.DistanceToOut(pzero);
|
|---|
| 97 | assert(ApproxEqual(Dist,50));
|
|---|
| 98 |
|
|---|
| 99 | // DistanceToOut(P,V)
|
|---|
| 100 | Dist=t1.DistanceToOut(pzero,vx,calcNorm,pgoodNorm,pNorm);
|
|---|
| 101 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vx)&&*pgoodNorm);
|
|---|
| 102 | Dist=t1.DistanceToOut(pzero,vmx,calcNorm,pgoodNorm,pNorm);
|
|---|
| 103 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmx)&&*pgoodNorm);
|
|---|
| 104 | Dist=t1.DistanceToOut(pzero,vy,calcNorm,pgoodNorm,pNorm);
|
|---|
| 105 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vy)&&*pgoodNorm);
|
|---|
| 106 | Dist=t1.DistanceToOut(pzero,vmy,calcNorm,pgoodNorm,pNorm);
|
|---|
| 107 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmy)&&*pgoodNorm);
|
|---|
| 108 | Dist=t1.DistanceToOut(pzero,vz,calcNorm,pgoodNorm,pNorm);
|
|---|
| 109 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vz)&&*pgoodNorm);
|
|---|
| 110 | Dist=t1.DistanceToOut(pzero,vmz,calcNorm,pgoodNorm,pNorm);
|
|---|
| 111 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vmz)&&*pgoodNorm);
|
|---|
| 112 | Dist=t1.DistanceToOut(pzero,vxy,calcNorm,pgoodNorm,pNorm);
|
|---|
| 113 | assert(ApproxEqual(Dist,50)&&ApproxEqual(pNorm->unit(),vxy)&&*pgoodNorm);
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | //DistanceToIn(P)
|
|---|
| 117 | Dist=t1.DistanceToIn(pbigx);
|
|---|
| 118 | assert(ApproxEqual(Dist,50));
|
|---|
| 119 | Dist=t1.DistanceToIn(pbigmx);
|
|---|
| 120 | assert(ApproxEqual(Dist,50));
|
|---|
| 121 | Dist=t1.DistanceToIn(pbigy);
|
|---|
| 122 | assert(ApproxEqual(Dist,50));
|
|---|
| 123 | Dist=t1.DistanceToIn(pbigmy);
|
|---|
| 124 | assert(ApproxEqual(Dist,50));
|
|---|
| 125 | Dist=t1.DistanceToIn(pbigz);
|
|---|
| 126 | assert(ApproxEqual(Dist,50));
|
|---|
| 127 | Dist=t1.DistanceToIn(pbigmz);
|
|---|
| 128 | assert(ApproxEqual(Dist,50));
|
|---|
| 129 |
|
|---|
| 130 | // DistanceToIn(P,V)
|
|---|
| 131 | Dist=t1.DistanceToIn(pbigx,vmx);
|
|---|
| 132 | assert(ApproxEqual(Dist,50));
|
|---|
| 133 | Dist=t1.DistanceToIn(pbigmx,vx);
|
|---|
| 134 | assert(ApproxEqual(Dist,50));
|
|---|
| 135 | Dist=t1.DistanceToIn(pbigy,vmy);
|
|---|
| 136 | assert(ApproxEqual(Dist,50));
|
|---|
| 137 | Dist=t1.DistanceToIn(pbigmy,vy);
|
|---|
| 138 | assert(ApproxEqual(Dist,50));
|
|---|
| 139 | Dist=t1.DistanceToIn(pbigz,vmz);
|
|---|
| 140 | assert(ApproxEqual(Dist,50));
|
|---|
| 141 | Dist=t1.DistanceToIn(pbigmz,vz);
|
|---|
| 142 | assert(ApproxEqual(Dist,50));
|
|---|
| 143 | Dist=t1.DistanceToIn(pbigx,vxy);
|
|---|
| 144 | assert(ApproxEqual(Dist,kInfinity));
|
|---|
| 145 |
|
|---|
| 146 | Dist=test10.DistanceToIn(G4ThreeVector(19.218716967888,5.5354239324172,-100.0),
|
|---|
| 147 | G4ThreeVector(-0.25644483536346,-0.073799216676426,0.96373737191901));
|
|---|
| 148 | G4cout<<"test10::DistToIn ="<<Dist<<G4endl;
|
|---|
| 149 | Dist=test10.DistanceToOut(G4ThreeVector(19.218716967888,5.5354239324172,-100.0),
|
|---|
| 150 | G4ThreeVector(-0.25644483536346,-0.073799216676426,0.96373737191901),
|
|---|
| 151 | calcNorm,pgoodNorm,pNorm);
|
|---|
| 152 | G4cout<<"test10::DistToOut ="<<Dist<<G4endl;
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 | // CalculateExtent
|
|---|
| 161 | G4VoxelLimits limit; // Unlimited
|
|---|
| 162 | G4RotationMatrix noRot;
|
|---|
| 163 | G4AffineTransform origin;
|
|---|
| 164 | G4double min,max;
|
|---|
| 165 | assert(t1.CalculateExtent(kXAxis,limit,origin,min,max));
|
|---|
| 166 | assert(min<=-50&&max>=50);
|
|---|
| 167 | assert(t1.CalculateExtent(kYAxis,limit,origin,min,max));
|
|---|
| 168 | assert(min<=-50&&max>=50);
|
|---|
| 169 | assert(t1.CalculateExtent(kZAxis,limit,origin,min,max));
|
|---|
| 170 | assert(min<=-50&&max>=50);
|
|---|
| 171 |
|
|---|
| 172 | G4ThreeVector pmxmymz(-100,-110,-120);
|
|---|
| 173 | G4AffineTransform tPosOnly(pmxmymz);
|
|---|
| 174 | assert(t1.CalculateExtent(kXAxis,limit,tPosOnly,min,max));
|
|---|
| 175 | assert(min<=-150&&max>=-50);
|
|---|
| 176 | assert(t1.CalculateExtent(kYAxis,limit,tPosOnly,min,max));
|
|---|
| 177 | assert(min<=-160&&max>=-60);
|
|---|
| 178 | assert(t1.CalculateExtent(kZAxis,limit,tPosOnly,min,max));
|
|---|
| 179 | assert(min<=-170&&max>=-70);
|
|---|
| 180 |
|
|---|
| 181 | G4RotationMatrix r90Z;
|
|---|
| 182 | r90Z.rotateZ(halfpi);
|
|---|
| 183 | G4AffineTransform tRotZ(r90Z,pzero);
|
|---|
| 184 | assert(t1.CalculateExtent(kXAxis,limit,tRotZ,min,max));
|
|---|
| 185 | assert(min<=-50&&max>=50);
|
|---|
| 186 | assert(t1.CalculateExtent(kYAxis,limit,tRotZ,min,max));
|
|---|
| 187 | assert(min<=-50&&max>=50);
|
|---|
| 188 | assert(t1.CalculateExtent(kZAxis,limit,tRotZ,min,max));
|
|---|
| 189 | assert(min<=-50&&max>=50);
|
|---|
| 190 |
|
|---|
| 191 | // Check that clipped away
|
|---|
| 192 | G4VoxelLimits xClip;
|
|---|
| 193 | xClip.AddLimit(kXAxis,-100,-60);
|
|---|
| 194 | assert(!t1.CalculateExtent(kXAxis,xClip,origin,min,max));
|
|---|
| 195 |
|
|---|
| 196 | // Assert clipped to volume
|
|---|
| 197 | G4VoxelLimits allClip;
|
|---|
| 198 | allClip.AddLimit(kXAxis,-5,+5);
|
|---|
| 199 | allClip.AddLimit(kYAxis,-5,+5);
|
|---|
| 200 | allClip.AddLimit(kZAxis,-5,+5);
|
|---|
| 201 | G4RotationMatrix genRot;
|
|---|
| 202 | genRot.rotateX(pi/6);
|
|---|
| 203 | genRot.rotateY(pi/6);
|
|---|
| 204 | genRot.rotateZ(pi/6);
|
|---|
| 205 | G4AffineTransform tGen(genRot,vx);
|
|---|
| 206 | assert(t1.CalculateExtent(kXAxis,allClip,tGen,min,max));
|
|---|
| 207 | assert(min<=-5&&max>=5);
|
|---|
| 208 | assert(t1.CalculateExtent(kYAxis,allClip,tGen,min,max));
|
|---|
| 209 | assert(min<=-5&&max>=5);
|
|---|
| 210 | assert(t1.CalculateExtent(kZAxis,allClip,tGen,min,max));
|
|---|
| 211 | assert(min<=-5&&max>=5);
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 | // Test z clipping ok
|
|---|
| 215 | for (G4double zTest=-100;zTest<100;zTest+=9)
|
|---|
| 216 | {
|
|---|
| 217 | G4VoxelLimits zTestClip;
|
|---|
| 218 | zTestClip.AddLimit(kZAxis,-kInfinity,zTest);
|
|---|
| 219 | if (zTest<-50)
|
|---|
| 220 | {
|
|---|
| 221 | assert(!t1.CalculateExtent(kZAxis,zTestClip,origin,min,max));
|
|---|
| 222 | }
|
|---|
| 223 | else
|
|---|
| 224 | {
|
|---|
| 225 | assert(t1.CalculateExtent(kZAxis,zTestClip,origin,min,max));
|
|---|
| 226 | G4double testMin=-50;
|
|---|
| 227 | G4double testMax=(zTest<50) ? zTest : 50;
|
|---|
| 228 | assert (ApproxEqual(min,testMin)
|
|---|
| 229 | &&ApproxEqual(max,testMax));
|
|---|
| 230 | }
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | // Test y clipping ok
|
|---|
| 234 | for (G4double xTest=-100;xTest<100;xTest+=9)
|
|---|
| 235 | {
|
|---|
| 236 | G4VoxelLimits xTestClip;
|
|---|
| 237 | xTestClip.AddLimit(kXAxis,-kInfinity,xTest);
|
|---|
| 238 | if (xTest<-50)
|
|---|
| 239 | {
|
|---|
| 240 | assert(!t1.CalculateExtent(kYAxis,xTestClip,origin,min,max));
|
|---|
| 241 | }
|
|---|
| 242 | else
|
|---|
| 243 | {
|
|---|
| 244 | assert(t1.CalculateExtent(kYAxis,xTestClip,origin,min,max));
|
|---|
| 245 | // Calc max y coordinate
|
|---|
| 246 | G4double testMax=(xTest<0) ? std::sqrt(50*50-xTest*xTest) : 50;
|
|---|
| 247 | assert (ApproxEqual(min,-testMax)
|
|---|
| 248 | &&ApproxEqual(max,testMax));
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | // Test x clipping ok
|
|---|
| 253 | for (G4double yTest=-100;yTest<100;yTest+=9)
|
|---|
| 254 | {
|
|---|
| 255 | G4VoxelLimits yTestClip;
|
|---|
| 256 | yTestClip.AddLimit(kYAxis,-kInfinity,yTest);
|
|---|
| 257 | if (yTest<-50)
|
|---|
| 258 | {
|
|---|
| 259 | assert(!t1.CalculateExtent(kXAxis,yTestClip,origin,min,max));
|
|---|
| 260 | }
|
|---|
| 261 | else
|
|---|
| 262 | {
|
|---|
| 263 | assert(t1.CalculateExtent(kXAxis,yTestClip,origin,min,max));
|
|---|
| 264 | // Calc max y coordinate
|
|---|
| 265 | G4double testMax=(yTest<0) ? std::sqrt(50*50-yTest*yTest) : 50;
|
|---|
| 266 | assert (ApproxEqual(min,-testMax)
|
|---|
| 267 | &&ApproxEqual(max,testMax));
|
|---|
| 268 | }
|
|---|
| 269 | }
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 | return true;
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | int main()
|
|---|
| 276 | {
|
|---|
| 277 | #ifdef NDEBUG
|
|---|
| 278 | G4Exception("FAIL: *** Assertions must be compiled in! ***");
|
|---|
| 279 | #endif
|
|---|
| 280 | assert(testG4Cons());
|
|---|
| 281 | G4cout<<"testG4Cons1 was OK"<<G4endl ;
|
|---|
| 282 | return 0;
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|