Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/geometry/solids/specific/src/G4VTwistSurface.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /geometry/solids/specific/src/G4VTwistSurface.cc (Version 11.3.0) and /geometry/solids/specific/src/G4VTwistSurface.cc (Version 10.3.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4VTwistSurface implementation              << 
 27 //                                                 26 //
 28 // 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepbu <<  27 // $Id: G4VTwistSurface.cc 98326 2016-07-07 07:47:15Z gcosmo $
 29 // 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), <<  28 //
 30 //               from original version in Jupi <<  29 // 
                                                   >>  30 // --------------------------------------------------------------------
                                                   >>  31 // GEANT 4 class source file
                                                   >>  32 //
                                                   >>  33 //
                                                   >>  34 // G4VTwistSurface.cc
                                                   >>  35 //
                                                   >>  36 // Author: 
                                                   >>  37 //   01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp)
                                                   >>  38 //
                                                   >>  39 // History:
                                                   >>  40 //   13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
                                                   >>  41 //                 from original version in Jupiter-2.5.02 application.
 31 // -------------------------------------------     42 // --------------------------------------------------------------------
 32                                                    43 
 33 #include <iomanip>                                 44 #include <iomanip>
 34                                                    45 
 35 #include "G4VTwistSurface.hh"                      46 #include "G4VTwistSurface.hh"
 36 #include "G4GeometryTolerance.hh"                  47 #include "G4GeometryTolerance.hh"
 37                                                    48 
 38 const G4int  G4VTwistSurface::sOutside             49 const G4int  G4VTwistSurface::sOutside        = 0x00000000;
 39 const G4int  G4VTwistSurface::sInside              50 const G4int  G4VTwistSurface::sInside         = 0x10000000;
 40 const G4int  G4VTwistSurface::sBoundary            51 const G4int  G4VTwistSurface::sBoundary       = 0x20000000;
 41 const G4int  G4VTwistSurface::sCorner              52 const G4int  G4VTwistSurface::sCorner         = 0x40000000;
 42 const G4int  G4VTwistSurface::sC0Min1Min           53 const G4int  G4VTwistSurface::sC0Min1Min      = 0x40000101; 
 43 const G4int  G4VTwistSurface::sC0Max1Min           54 const G4int  G4VTwistSurface::sC0Max1Min      = 0x40000201;
 44 const G4int  G4VTwistSurface::sC0Max1Max           55 const G4int  G4VTwistSurface::sC0Max1Max      = 0x40000202; 
 45 const G4int  G4VTwistSurface::sC0Min1Max           56 const G4int  G4VTwistSurface::sC0Min1Max      = 0x40000102; 
 46 const G4int  G4VTwistSurface::sAxisMin             57 const G4int  G4VTwistSurface::sAxisMin        = 0x00000101; 
 47 const G4int  G4VTwistSurface::sAxisMax             58 const G4int  G4VTwistSurface::sAxisMax        = 0x00000202; 
 48 const G4int  G4VTwistSurface::sAxisX               59 const G4int  G4VTwistSurface::sAxisX          = 0x00000404;
 49 const G4int  G4VTwistSurface::sAxisY               60 const G4int  G4VTwistSurface::sAxisY          = 0x00000808;
 50 const G4int  G4VTwistSurface::sAxisZ               61 const G4int  G4VTwistSurface::sAxisZ          = 0x00000C0C;
 51 const G4int  G4VTwistSurface::sAxisRho             62 const G4int  G4VTwistSurface::sAxisRho        = 0x00001010;
 52 const G4int  G4VTwistSurface::sAxisPhi             63 const G4int  G4VTwistSurface::sAxisPhi        = 0x00001414;
 53                                                    64 
 54 // mask                                            65 // mask
 55 const G4int  G4VTwistSurface::sAxis0               66 const G4int  G4VTwistSurface::sAxis0          = 0x0000FF00;
 56 const G4int  G4VTwistSurface::sAxis1               67 const G4int  G4VTwistSurface::sAxis1          = 0x000000FF;
 57 const G4int  G4VTwistSurface::sSizeMask            68 const G4int  G4VTwistSurface::sSizeMask       = 0x00000303;
 58 const G4int  G4VTwistSurface::sAxisMask            69 const G4int  G4VTwistSurface::sAxisMask       = 0x0000FCFC;
 59 const G4int  G4VTwistSurface::sAreaMask            70 const G4int  G4VTwistSurface::sAreaMask       = 0XF0000000;
 60                                                    71 
 61 //============================================     72 //=====================================================================
 62 //* constructors -----------------------------     73 //* constructors ------------------------------------------------------
 63                                                    74 
 64 G4VTwistSurface::G4VTwistSurface(const G4Strin     75 G4VTwistSurface::G4VTwistSurface(const G4String &name)
 65   : fIsValidNorm(false), fName(name)               76   : fIsValidNorm(false), fName(name)
 66 {                                                  77 {
 67                                                    78 
 68    fAxis[0]    = kUndefined;                       79    fAxis[0]    = kUndefined;
 69    fAxis[1]    = kUndefined;                       80    fAxis[1]    = kUndefined;
 70    fAxisMin[0] = kInfinity;                        81    fAxisMin[0] = kInfinity;
 71    fAxisMin[1] = kInfinity;                        82    fAxisMin[1] = kInfinity;
 72    fAxisMax[0] = kInfinity;                        83    fAxisMax[0] = kInfinity;
 73    fAxisMax[1] = kInfinity;                        84    fAxisMax[1] = kInfinity;
 74    fHandedness = 1;                                85    fHandedness = 1;
 75                                                    86 
 76    for (auto i=0; i<4; ++i)                    <<  87    for (G4int i=0; i<4; i++)
 77    {                                               88    {
 78       fCorners[i].set(kInfinity, kInfinity, kI     89       fCorners[i].set(kInfinity, kInfinity, kInfinity);
 79       fNeighbours[i] = nullptr;                <<  90       fNeighbours[i] = 0;
 80    }                                               91    }
 81                                                    92 
 82    fCurrentNormal.p.set(kInfinity, kInfinity,      93    fCurrentNormal.p.set(kInfinity, kInfinity, kInfinity);
 83                                                    94    
 84    fAmIOnLeftSide.me.set(kInfinity, kInfinity,     95    fAmIOnLeftSide.me.set(kInfinity, kInfinity, kInfinity);
 85    fAmIOnLeftSide.vec.set(kInfinity, kInfinity     96    fAmIOnLeftSide.vec.set(kInfinity, kInfinity, kInfinity);
 86    kCarTolerance = G4GeometryTolerance::GetIns     97    kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
 87 }                                                  98 }
 88                                                    99 
 89 G4VTwistSurface::G4VTwistSurface(const G4Strin << 100 G4VTwistSurface::G4VTwistSurface(const G4String         &name,
 90                        const G4RotationMatrix& << 101                        const G4RotationMatrix &rot,
 91                        const G4ThreeVector&    << 102                        const G4ThreeVector    &tlate,
 92                              G4int                103                              G4int             handedness,
 93                        const EAxis                104                        const EAxis             axis0 ,
 94                        const EAxis                105                        const EAxis             axis1 ,
 95                              G4double             106                              G4double          axis0min,
 96                              G4double             107                              G4double          axis1min,
 97                              G4double             108                              G4double          axis0max,
 98                              G4double             109                              G4double          axis1max )
 99    : fIsValidNorm(false), fName(name)             110    : fIsValidNorm(false), fName(name)
100 {                                                 111 {
101    fAxis[0]    = axis0;                           112    fAxis[0]    = axis0;
102    fAxis[1]    = axis1;                           113    fAxis[1]    = axis1;
103    fAxisMin[0] = axis0min;                        114    fAxisMin[0] = axis0min;
104    fAxisMin[1] = axis1min;                        115    fAxisMin[1] = axis1min;
105    fAxisMax[0] = axis0max;                        116    fAxisMax[0] = axis0max;
106    fAxisMax[1] = axis1max;                        117    fAxisMax[1] = axis1max;
107    fHandedness = handedness;                      118    fHandedness = handedness;
108    fRot        = rot;                             119    fRot        = rot;
109    fTrans      = tlate;                           120    fTrans      = tlate;
110                                                   121 
111    for (auto i=0; i<4; ++i)                    << 122    for (G4int i=0; i<4; i++)
112    {                                              123    {
113       fCorners[i].set(kInfinity, kInfinity, kI    124       fCorners[i].set(kInfinity, kInfinity, kInfinity);
114       fNeighbours[i] = nullptr;                << 125       fNeighbours[i] = 0;
115    }                                              126    }
116                                                   127 
117    fCurrentNormal.p.set(kInfinity, kInfinity,     128    fCurrentNormal.p.set(kInfinity, kInfinity, kInfinity);
118                                                   129    
119    fAmIOnLeftSide.me.set(kInfinity, kInfinity,    130    fAmIOnLeftSide.me.set(kInfinity, kInfinity, kInfinity);
120    fAmIOnLeftSide.vec.set(kInfinity, kInfinity    131    fAmIOnLeftSide.vec.set(kInfinity, kInfinity, kInfinity);
121    kCarTolerance = G4GeometryTolerance::GetIns    132    kCarTolerance = G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
122 }                                                 133 }
123                                                   134 
124 //============================================    135 //=====================================================================
125 //* Fake default constructor -----------------    136 //* Fake default constructor ------------------------------------------
126                                                   137 
127 G4VTwistSurface::G4VTwistSurface( __void__& )     138 G4VTwistSurface::G4VTwistSurface( __void__& )
128   : fHandedness(0), fIsValidNorm(false), kCarT    139   : fHandedness(0), fIsValidNorm(false), kCarTolerance(0.),
129     fName("")                                     140     fName("")
130 {                                                 141 {
131    fAxis[0] = fAxis[1] = kXAxis;                  142    fAxis[0] = fAxis[1] = kXAxis;
132    fAxisMin[0] = fAxisMin[1] = 0.;                143    fAxisMin[0] = fAxisMin[1] = 0.;
133    fAxisMax[0] = fAxisMax[1] = 0.;                144    fAxisMax[0] = fAxisMax[1] = 0.;
134    fNeighbours[0] = fNeighbours[1] = fNeighbou << 145    fNeighbours[0] = fNeighbours[1] = fNeighbours[2] = fNeighbours[3] = 0;
                                                   >> 146 }
                                                   >> 147 
                                                   >> 148 //=====================================================================
                                                   >> 149 //* destructor --------------------------------------------------------
                                                   >> 150 
                                                   >> 151 G4VTwistSurface::~G4VTwistSurface()
                                                   >> 152 {
135 }                                                 153 }
136                                                   154 
137 //============================================    155 //=====================================================================
138 //* AmIOnLeftSide ----------------------------    156 //* AmIOnLeftSide -----------------------------------------------------
139                                                   157 
140 G4int G4VTwistSurface::AmIOnLeftSide(const G4T << 158 G4int G4VTwistSurface::AmIOnLeftSide(const G4ThreeVector &me, 
141                                      const G4T << 159                                      const G4ThreeVector &vec,
142                                            G4b << 160                                      G4bool        withtol) 
143 {                                                 161 {
144    // AmIOnLeftSide returns phi-location of "m    162    // AmIOnLeftSide returns phi-location of "me"
145    // (phi relation between me and vec project    163    // (phi relation between me and vec projected on z=0 plane).
146    // If "me" is on -ve-phi-side of "vec", it     164    // If "me" is on -ve-phi-side of "vec", it returns 1.
147    // On the other hand, if "me" is on +ve-phi    165    // On the other hand, if "me" is on +ve-phi-side of "vec",
148    // it returns -1.                              166    // it returns -1.
149    // (The return value represents z-coordinat    167    // (The return value represents z-coordinate of normal vector
150    //  of me.cross(vec).)                         168    //  of me.cross(vec).)
151    // If me is on boundary of vec, return 0.      169    // If me is on boundary of vec, return 0.
152                                                   170 
153    const G4double kAngTolerance                   171    const G4double kAngTolerance
154      = G4GeometryTolerance::GetInstance()->Get    172      = G4GeometryTolerance::GetInstance()->GetAngularTolerance();
155                                                   173 
156    G4RotationMatrix unitrot;                      174    G4RotationMatrix unitrot;
157    const G4RotationMatrix rottol    = unitrot. << 175    static const G4RotationMatrix rottol    = unitrot.rotateZ(0.5*kAngTolerance);
158    const G4RotationMatrix invrottol = unitrot. << 176    static const G4RotationMatrix invrottol = unitrot.rotateZ(-1.*kAngTolerance);
159                                                   177 
160    if (fAmIOnLeftSide.me == me                    178    if (fAmIOnLeftSide.me == me 
161        && fAmIOnLeftSide.vec == vec               179        && fAmIOnLeftSide.vec == vec
162        && fAmIOnLeftSide.withTol == withtol)   << 180        && fAmIOnLeftSide.withTol == withtol) {
163    {                                           << 
164       return fAmIOnLeftSide.amIOnLeftSide;        181       return fAmIOnLeftSide.amIOnLeftSide;
165    }                                              182    }
166                                                   183    
167    fAmIOnLeftSide.me      = me;                   184    fAmIOnLeftSide.me      = me;
168    fAmIOnLeftSide.vec     = vec;                  185    fAmIOnLeftSide.vec     = vec;
169    fAmIOnLeftSide.withTol = withtol;              186    fAmIOnLeftSide.withTol = withtol;
170                                                   187    
171    G4ThreeVector met   = (G4ThreeVector(me.x()    188    G4ThreeVector met   = (G4ThreeVector(me.x(), me.y(), 0.)).unit();
172    G4ThreeVector vect  = (G4ThreeVector(vec.x(    189    G4ThreeVector vect  = (G4ThreeVector(vec.x(), vec.y(), 0.)).unit();
173                                                   190    
174    G4ThreeVector ivect = invrottol * vect;        191    G4ThreeVector ivect = invrottol * vect;
175    G4ThreeVector rvect = rottol * vect;           192    G4ThreeVector rvect = rottol * vect;
176                                                   193 
177    G4double metcrossvect = met.x() * vect.y()     194    G4double metcrossvect = met.x() * vect.y() - met.y() * vect.x();
178                                                   195    
179    if (withtol)                                << 196    if (withtol) {
180    {                                           << 
181       if (met.x() * ivect.y() - met.y() * ivec    197       if (met.x() * ivect.y() - met.y() * ivect.x() > 0 && 
182           metcrossvect >= 0)  {                   198           metcrossvect >= 0)  {
183          fAmIOnLeftSide.amIOnLeftSide = 1;        199          fAmIOnLeftSide.amIOnLeftSide = 1;
184       } else if (met.x() * rvect.y() - met.y()    200       } else if (met.x() * rvect.y() - met.y() * rvect.x() < 0 &&
185                  metcrossvect <= 0)  {            201                  metcrossvect <= 0)  {
186          fAmIOnLeftSide.amIOnLeftSide = -1;       202          fAmIOnLeftSide.amIOnLeftSide = -1;
187       } else {                                    203       } else {
188          fAmIOnLeftSide.amIOnLeftSide = 0;        204          fAmIOnLeftSide.amIOnLeftSide = 0;
189       }                                           205       }
190    }                                           << 206    } else {
191    else                                        << 
192    {                                           << 
193       if (metcrossvect > 0) {                     207       if (metcrossvect > 0) {    
194          fAmIOnLeftSide.amIOnLeftSide = 1;        208          fAmIOnLeftSide.amIOnLeftSide = 1;
195       } else if (metcrossvect < 0 ) {             209       } else if (metcrossvect < 0 ) {
196          fAmIOnLeftSide.amIOnLeftSide = -1;       210          fAmIOnLeftSide.amIOnLeftSide = -1;
197       } else {                                    211       } else {       
198          fAmIOnLeftSide.amIOnLeftSide = 0;        212          fAmIOnLeftSide.amIOnLeftSide = 0;
199       }                                           213       }
200    }                                              214    }
201                                                   215 
202 #ifdef G4TWISTDEBUG                               216 #ifdef G4TWISTDEBUG
203    G4cout << "         === G4VTwistSurface::Am    217    G4cout << "         === G4VTwistSurface::AmIOnLeftSide() =============="
204           << G4endl;                              218           << G4endl;
205    G4cout << "             Name , returncode      219    G4cout << "             Name , returncode  : " << fName << " " 
206                        << fAmIOnLeftSide.amIOn    220                        << fAmIOnLeftSide.amIOnLeftSide <<  G4endl;
207    G4cout << "             me, vec    : " << s    221    G4cout << "             me, vec    : " << std::setprecision(14) << me 
208                                           << "    222                                           << " " << vec  << G4endl;
209    G4cout << "             met, vect  : " << m    223    G4cout << "             met, vect  : " << met << " " << vect  << G4endl;
210    G4cout << "             ivec, rvec : " << i    224    G4cout << "             ivec, rvec : " << ivect << " " << rvect << G4endl;
211    G4cout << "             met x vect : " << m    225    G4cout << "             met x vect : " << metcrossvect << G4endl;
212    G4cout << "             met x ivec : " << m    226    G4cout << "             met x ivec : " << met.cross(ivect) << G4endl;
213    G4cout << "             met x rvec : " << m    227    G4cout << "             met x rvec : " << met.cross(rvect) << G4endl;
214    G4cout << "         =======================    228    G4cout << "         =============================================="
215           << G4endl;                              229           << G4endl;
216 #endif                                            230 #endif
217                                                   231 
218    return fAmIOnLeftSide.amIOnLeftSide;           232    return fAmIOnLeftSide.amIOnLeftSide;
219 }                                                 233 }
220                                                   234 
221 //============================================    235 //=====================================================================
222 //* DistanceToBoundary -----------------------    236 //* DistanceToBoundary ------------------------------------------------
223                                                   237 
224 G4double G4VTwistSurface::DistanceToBoundary(G    238 G4double G4VTwistSurface::DistanceToBoundary(G4int areacode,
225                                              G << 239                                         G4ThreeVector &xx,
226                                        const G << 240                                         const G4ThreeVector &p) 
227 {                                                 241 {
228    // DistanceToBoundary                          242    // DistanceToBoundary 
229    //                                             243    //
230    // return distance to nearest boundary from    244    // return distance to nearest boundary from arbitrary point p 
231    // in local coodinate.                         245    // in local coodinate.
232    // Argument areacode must be one of them:      246    // Argument areacode must be one of them:
233    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,       247    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
234    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.       248    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
235    //                                             249    //
236                                                   250 
237    G4ThreeVector d;    // direction vector of     251    G4ThreeVector d;    // direction vector of the boundary
238    G4ThreeVector x0;   // reference point of t    252    G4ThreeVector x0;   // reference point of the boundary
239    G4double      dist = kInfinity;                253    G4double      dist = kInfinity;
240    G4int         boundarytype;                    254    G4int         boundarytype;
241                                                   255 
242    if (IsAxis0(areacode) && IsAxis1(areacode)) << 256    if (IsAxis0(areacode) && IsAxis1(areacode)) {
243    {                                           << 
244       std::ostringstream message;                 257       std::ostringstream message;
245       message << "Point is in the corner area.    258       message << "Point is in the corner area." << G4endl
246               << "        Point is in the corn    259               << "        Point is in the corner area. This function returns"
247               << G4endl                           260               << G4endl
248               << "        a direction vector o    261               << "        a direction vector of a boundary line." << G4endl
249               << "        areacode = " << area    262               << "        areacode = " << areacode;
250       G4Exception("G4VTwistSurface::DistanceTo    263       G4Exception("G4VTwistSurface::DistanceToBoundary()", "GeomSolids0003",
251                   FatalException, message);       264                   FatalException, message);
252    }                                           << 265    } else if (IsAxis0(areacode) || IsAxis1(areacode)) {
253    else if (IsAxis0(areacode) || IsAxis1(areac << 
254    {                                           << 
255       GetBoundaryParameters(areacode, d, x0, b    266       GetBoundaryParameters(areacode, d, x0, boundarytype);
256       if (boundarytype == sAxisPhi)            << 267       if (boundarytype == sAxisPhi) {
257       {                                        << 
258          G4double t = x0.getRho() / p.getRho()    268          G4double t = x0.getRho() / p.getRho();
259          xx.set(t*p.x(), t*p.y(), x0.z());        269          xx.set(t*p.x(), t*p.y(), x0.z());
260          dist = (xx - p).mag();                   270          dist = (xx - p).mag();
261       }                                        << 271       } else { 
262       else                                     << 
263       {                                        << 
264          // linear boundary                       272          // linear boundary
265          // sAxisX, sAxisY, sAxisZ, sAxisRho      273          // sAxisX, sAxisY, sAxisZ, sAxisRho
266          dist = DistanceToLine(p, x0, d, xx);     274          dist = DistanceToLine(p, x0, d, xx);
267       }                                           275       }
268    }                                           << 276    } else {
269    else                                        << 
270    {                                           << 
271       std::ostringstream message;                 277       std::ostringstream message;
272       message << "Bad areacode of boundary." <    278       message << "Bad areacode of boundary." << G4endl
273               << "        areacode = " << area    279               << "        areacode = " << areacode;
274       G4Exception("G4VTwistSurface::DistanceTo    280       G4Exception("G4VTwistSurface::DistanceToBoundary()", "GeomSolids0003",
275                   FatalException, message);       281                   FatalException, message);
276    }                                              282    }
277    return dist;                                   283    return dist;
278 }                                                 284 }
279                                                   285 
280 //============================================    286 //=====================================================================
281 //* DistanceToIn -----------------------------    287 //* DistanceToIn ------------------------------------------------------
282                                                   288 
283 G4double G4VTwistSurface::DistanceToIn(const G << 289 G4double G4VTwistSurface::DistanceToIn(const G4ThreeVector &gp,
284                                        const G << 290                                   const G4ThreeVector &gv,
285                                              G << 291                                         G4ThreeVector &gxxbest)
286 {                                                 292 {
287 #ifdef G4TWISTDEBUG                               293 #ifdef G4TWISTDEBUG
288    G4cout << " ~~~~ G4VTwistSurface::DistanceT << 294    G4cout << " ~~~~~ G4VTwistSurface::DistanceToIn(p,v) - Start ~~~~~" << G4endl;
289    G4cout << "      Name : " << fName << G4end    295    G4cout << "      Name : " << fName << G4endl;
290    G4cout << "      gp   : " << gp << G4endl;     296    G4cout << "      gp   : " << gp << G4endl;
291    G4cout << "      gv   : " <<  gv << G4endl;    297    G4cout << "      gv   : " <<  gv << G4endl;
292    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    298    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
293 #endif                                            299 #endif
294                                                   300    
295    G4ThreeVector gxx[G4VSURFACENXX];              301    G4ThreeVector gxx[G4VSURFACENXX];
296    G4double      distance[G4VSURFACENXX]  ;       302    G4double      distance[G4VSURFACENXX]  ; 
297    G4int         areacode[G4VSURFACENXX]  ;       303    G4int         areacode[G4VSURFACENXX]  ;
298    G4bool        isvalid[G4VSURFACENXX]   ;       304    G4bool        isvalid[G4VSURFACENXX]   ; 
299                                                   305    
300    for (G4int i = 0 ; i<G4VSURFACENXX ; ++i )  << 306    for (G4int i = 0 ; i<G4VSURFACENXX ; i++ ) {
301    {                                           << 
302      distance[i] = kInfinity ;                    307      distance[i] = kInfinity ;
303      areacode[i] = sOutside ;                     308      areacode[i] = sOutside ;
304      isvalid[i] = false ;                         309      isvalid[i] = false ;
305    }                                              310    }
306                                                   311 
307    G4double      bestdistance   = kInfinity;      312    G4double      bestdistance   = kInfinity;
308 #ifdef G4TWISTDEBUG                               313 #ifdef G4TWISTDEBUG
309    G4int         besti          = -1;             314    G4int         besti          = -1;  
310 #endif                                            315 #endif
311    G4ThreeVector bestgxx(kInfinity, kInfinity,    316    G4ThreeVector bestgxx(kInfinity, kInfinity, kInfinity);
312                                                   317 
313    G4int         nxx = DistanceToSurface(gp, g    318    G4int         nxx = DistanceToSurface(gp, gv, gxx, distance, areacode, 
314                                          isval    319                                          isvalid, kValidateWithTol);
315                                                   320 
316    for (G4int i=0; i<nxx; ++i)                 << 321    for (G4int i=0; i< nxx; i++) {
317    {                                           << 
318                                                   322 
319       // skip this intersection if:               323       // skip this intersection if:
320       //   - invalid intersection                 324       //   - invalid intersection
321       //   - particle goes outword the surface    325       //   - particle goes outword the surface
322                                                   326 
323       if (!isvalid[i])                         << 327       if (!isvalid[i]) {
324       {                                        << 
325          // xx[i] is sOutside or distance[i] <    328          // xx[i] is sOutside or distance[i] < 0
326          continue;                                329          continue;      
327       }                                           330       }
328                                                   331 
329       G4ThreeVector normal = GetNormal(gxx[i],    332       G4ThreeVector normal = GetNormal(gxx[i], true);
330                                                   333 
331       if ((normal * gv) >= 0)                  << 334       if ((normal * gv) >= 0) {
332       {                                        << 
333                                                   335 
334 #ifdef G4TWISTDEBUG                               336 #ifdef G4TWISTDEBUG
335          G4cout << "   G4VTwistSurface::Distan    337          G4cout << "   G4VTwistSurface::DistanceToIn(p,v): "
336                 << "particle goes outword the     338                 << "particle goes outword the surface." << G4endl;
337 #endif                                            339 #endif 
338          continue;                                340          continue; 
339       }                                           341       }
340                                                   342       
341       //                                          343       //
342       // accept this intersection if the inter    344       // accept this intersection if the intersection is inside.
343       //                                          345       //
344                                                   346 
345       if (IsInside(areacode[i]))               << 347       if (IsInside(areacode[i])) {
346       {                                        << 348          if (distance[i] < bestdistance) {
347          if (distance[i] < bestdistance)       << 
348          {                                     << 
349             bestdistance = distance[i];           349             bestdistance = distance[i];
350             bestgxx = gxx[i];                     350             bestgxx = gxx[i];
351 #ifdef G4TWISTDEBUG                               351 #ifdef G4TWISTDEBUG
352             besti   = i;                          352             besti   = i;
353             G4cout << "   G4VTwistSurface::Dis    353             G4cout << "   G4VTwistSurface::DistanceToIn(p,v): "
354                    << " areacode sInside name,    354                    << " areacode sInside name, distance = "
355                    << fName <<  " "<< bestdist    355                    << fName <<  " "<< bestdistance << G4endl;
356 #endif                                            356 #endif 
357          }                                        357          }
358                                                   358 
359       //                                          359       //
360       // else, the intersection is on boundary    360       // else, the intersection is on boundary or corner.
361       //                                          361       //
362                                                   362 
363       }                                        << 363       } else {
364       else                                     << 364 
365       {                                        << 365          G4VTwistSurface *neighbours[2];
366          G4VTwistSurface* neighbours[2];       << 
367          G4bool      isaccepted[2] = {false, f    366          G4bool      isaccepted[2] = {false, false};
368          G4int       nneighbours   = GetNeighb    367          G4int       nneighbours   = GetNeighbours(areacode[i], neighbours);
369                                                   368             
370          for (G4int j=0; j<nneighbours; ++j)   << 369          for (G4int j=0; j< nneighbours; j++) {
371          {                                     << 
372             // if on corner, nneighbours = 2.     370             // if on corner, nneighbours = 2.
373             // if on boundary, nneighbours = 1    371             // if on boundary, nneighbours = 1.
374                                                   372 
375             G4ThreeVector tmpgxx[G4VSURFACENXX    373             G4ThreeVector tmpgxx[G4VSURFACENXX];
376             G4double      tmpdist[G4VSURFACENX    374             G4double      tmpdist[G4VSURFACENXX] ;
377             G4int         tmpareacode[G4VSURFA    375             G4int         tmpareacode[G4VSURFACENXX] ;
378             G4bool        tmpisvalid[G4VSURFAC    376             G4bool        tmpisvalid[G4VSURFACENXX] ;
379                                                   377 
380             for (G4int l = 0 ; l<G4VSURFACENXX << 378             for (G4int l = 0 ; l<G4VSURFACENXX ; l++ ) {
381             {                                  << 
382               tmpdist[l] = kInfinity ;            379               tmpdist[l] = kInfinity ;
383               tmpareacode[l] = sOutside ;         380               tmpareacode[l] = sOutside ;
384               tmpisvalid[l] = false ;             381               tmpisvalid[l] = false ;
385             }                                     382             }
386                                                   383 
387             G4int tmpnxx = neighbours[j]->Dist    384             G4int tmpnxx = neighbours[j]->DistanceToSurface(
388                                           gp,     385                                           gp, gv, tmpgxx, tmpdist,
389                                           tmpa    386                                           tmpareacode, tmpisvalid,
390                                           kVal    387                                           kValidateWithTol);
391             G4ThreeVector neighbournormal;        388             G4ThreeVector neighbournormal;
392                                                   389 
393             for (G4int k=0; k< tmpnxx; ++k)    << 390             for (G4int k=0; k< tmpnxx; k++) {
394             {                                  << 391 
395                //                                 392                //  
396                // if tmpxx[k] is valid && sIns    393                // if tmpxx[k] is valid && sInside, the final winner must
397                // be neighbour surface. return    394                // be neighbour surface. return kInfinity. 
398                // else , choose tmpxx on same     395                // else , choose tmpxx on same boundary of xx, then check normal 
399                //                                 396                //  
400                                                   397 
401                if (IsInside(tmpareacode[k]))   << 398                if (IsInside(tmpareacode[k])) {
402                {                               << 399 
403 #ifdef G4TWISTDEBUG                               400 #ifdef G4TWISTDEBUG
404                   G4cout << "   G4VTwistSurfac    401                   G4cout << "   G4VTwistSurface:DistanceToIn(p,v): "
405                          << " intersection "<<    402                          << " intersection "<< tmpgxx[k] << G4endl
406                          << "   is inside of n    403                          << "   is inside of neighbour surface of " << fName 
407                          << " . returning kInf    404                          << " . returning kInfinity." << G4endl;
408                   G4cout << "~~ G4VTwistSurfac << 405                   G4cout << "~~~~~ G4VTwistSurface::DistanceToIn(p,v) - return ~~~~"
409                          << G4endl;               406                          << G4endl;
410                   G4cout << "      No intersec    407                   G4cout << "      No intersections " << G4endl; 
411                   G4cout << "      Name : " <<    408                   G4cout << "      Name : " << fName << G4endl; 
412                   G4cout << "~~~~~~~~~~~~~~~~~    409                   G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
413                          << G4endl;               410                          << G4endl;
414 #endif                                            411 #endif 
415                   if (tmpisvalid[k])  return k    412                   if (tmpisvalid[k])  return kInfinity;
416                   continue;                       413                   continue;
417                                                   414 
418                //                                 415                //  
419                // if tmpxx[k] is valid && sIns    416                // if tmpxx[k] is valid && sInside, the final winner must
420                // be neighbour surface. return    417                // be neighbour surface. return .  
421                //                                 418                //
422                                                   419 
423                }                               << 420                } else if (IsSameBoundary(this,areacode[i],
424                else if (IsSameBoundary(this,ar << 421                                          neighbours[j], tmpareacode[k])) { 
425                                        neighbo << 
426                {                               << 
427                   // tmpxx[k] is same boundary    422                   // tmpxx[k] is same boundary (or corner) of xx.
428                                                   423                  
429                   neighbournormal = neighbours    424                   neighbournormal = neighbours[j]->GetNormal(tmpgxx[k], true);
430                   if (neighbournormal * gv < 0    425                   if (neighbournormal * gv < 0) isaccepted[j] = true;
431                }                                  426                }
432             }                                     427             } 
433                                                   428 
434             // if nneighbours = 1, chabge isac    429             // if nneighbours = 1, chabge isaccepted[1] before
435             // exiting neighboursurface loop.     430             // exiting neighboursurface loop.  
436                                                   431 
437             if (nneighbours == 1) isaccepted[1    432             if (nneighbours == 1) isaccepted[1] = true;
438                                                   433 
439          } // neighboursurface loop end           434          } // neighboursurface loop end
440                                                   435 
441          // now, we can accept xx intersection    436          // now, we can accept xx intersection
442                                                   437 
443          if (isaccepted[0] && isaccepted[1])   << 438          if (isaccepted[0] == true && isaccepted[1] == true) {
444          {                                     << 439             if (distance[i] < bestdistance) {
445             if (distance[i] < bestdistance)    << 
446             {                                  << 
447                bestdistance = distance[i];        440                bestdistance = distance[i];
448                gxxbest = gxx[i];                  441                gxxbest = gxx[i];
449 #ifdef G4TWISTDEBUG                               442 #ifdef G4TWISTDEBUG
450                besti = i;                      << 443                besti   = i;
451                G4cout << "   G4VTwistSurface::    444                G4cout << "   G4VTwistSurface::DistanceToIn(p,v): "
452                       << " areacode sBoundary     445                       << " areacode sBoundary & sBoundary distance = "
453                       << fName  << " " << dist    446                       << fName  << " " << distance[i] << G4endl;
454 #endif                                            447 #endif 
455             }                                     448             }
456          }                                        449          }
                                                   >> 450 
457       } // else end                               451       } // else end
458    } // intersection loop end                     452    } // intersection loop end
459                                                   453 
460    gxxbest = bestgxx;                             454    gxxbest = bestgxx;
461                                                   455 
462 #ifdef G4TWISTDEBUG                               456 #ifdef G4TWISTDEBUG
463    if (besti < 0)                              << 457    if (besti < 0) {
464    {                                           << 458       G4cout << "~~~~~ G4VTwistSurface::DistanceToIn(p,v) - return ~~~~" << G4endl;
465       G4cout << "~~~ G4VTwistSurface::Distance << 
466       G4cout << "      No intersections " << G    459       G4cout << "      No intersections " << G4endl; 
467       G4cout << "      Name : " << fName << G4    460       G4cout << "      Name : " << fName << G4endl; 
468       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    461       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
469    }                                           << 462    } else {
470    else                                        << 463       G4cout << "~~~~~ G4VTwistSurface::DistanceToIn(p,v) : return ~~~~" << G4endl;
471    {                                           << 
472       G4cout << "~~~ G4VTwistSurface::Distance << 
473       G4cout << "      Name, i  : " << fName <    464       G4cout << "      Name, i  : " << fName << " , " << besti << G4endl; 
474       G4cout << "      gxx[i]   : " << gxxbest    465       G4cout << "      gxx[i]   : " << gxxbest << G4endl; 
475       G4cout << "      bestdist : " << bestdis    466       G4cout << "      bestdist : " << bestdistance << G4endl;
476       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    467       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
477    }                                              468    } 
478                                                   469 
479 #endif                                            470 #endif
480                                                   471 
481    return bestdistance;                           472    return bestdistance;
482 }                                                 473 }
483                                                   474 
484 //============================================    475 //=====================================================================
485 //* DistanceToOut(p, v) ----------------------    476 //* DistanceToOut(p, v) -----------------------------------------------
486                                                   477 
487 G4double G4VTwistSurface::DistanceToOut(const  << 478 G4double G4VTwistSurface::DistanceToOut(const G4ThreeVector &gp,
488                                         const  << 479                                    const G4ThreeVector &gv,
489                                                << 480                                          G4ThreeVector &gxxbest)
490 {                                                 481 {
491 #ifdef G4TWISTDEBUG                               482 #ifdef G4TWISTDEBUG
492    G4cout << "~~~~~ G4VTwistSurface::DistanceT    483    G4cout << "~~~~~ G4VTwistSurface::DistanceToOut(p,v) - Start ~~~~" << G4endl;
493    G4cout << "      Name : " << fName << G4end    484    G4cout << "      Name : " << fName << G4endl;
494    G4cout << "      gp   : " << gp << G4endl;     485    G4cout << "      gp   : " << gp << G4endl;
495    G4cout << "      gv   : " <<  gv << G4endl;    486    G4cout << "      gv   : " <<  gv << G4endl;
496    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    487    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
497 #endif                                            488 #endif
498                                                   489 
499    G4ThreeVector gxx[G4VSURFACENXX];              490    G4ThreeVector gxx[G4VSURFACENXX];
500    G4double      distance[G4VSURFACENXX];      << 491    G4double      distance[G4VSURFACENXX]  ; 
501    G4int         areacode[G4VSURFACENXX];      << 492    G4int         areacode[G4VSURFACENXX]  ;
502    G4bool        isvalid[G4VSURFACENXX];       << 493    G4bool        isvalid[G4VSURFACENXX]   ; 
                                                   >> 494    G4int         i;
503                                                   495    
504    for ( G4int i = 0 ; i<G4VSURFACENXX ; ++i ) << 496    for ( i = 0 ; i<G4VSURFACENXX ; i++ )
505    {                                              497    {
506      distance[i] = kInfinity ;                    498      distance[i] = kInfinity ;
507      areacode[i] = sOutside ;                     499      areacode[i] = sOutside ;
508      isvalid[i] = false ;                         500      isvalid[i] = false ;
509    }                                              501    }
510                                                   502 
511    G4int         nxx;                             503    G4int         nxx;
512    G4double      bestdistance   = kInfinity;      504    G4double      bestdistance   = kInfinity;
513                                                   505 
514    nxx = DistanceToSurface(gp, gv, gxx, distan    506    nxx = DistanceToSurface(gp, gv, gxx, distance, areacode,
515                            isvalid, kValidateW    507                            isvalid, kValidateWithTol);
516                                                   508 
517    for (G4int i=0; i<nxx; ++i)                 << 509    for (i=0; i<nxx; i++) {
518    {                                           << 510       if (!(isvalid[i])) {
519       if (!(isvalid[i]))                       << 
520       {                                        << 
521          continue;                                511          continue;
522       }                                           512       }
523                                                   513 
524       G4ThreeVector normal = GetNormal(gxx[i],    514       G4ThreeVector normal = GetNormal(gxx[i], true);
525       if (normal * gv <= 0)                    << 515       if (normal * gv <= 0) {
526       {                                        << 
527          // particle goes toword inside of sol    516          // particle goes toword inside of solid, return kInfinity
528 #ifdef G4TWISTDEBUG                               517 #ifdef G4TWISTDEBUG
529           G4cout << "   G4VTwistSurface::Dista << 518           G4cout << "   G4VTwistSurface::DistanceToOut(p,v): normal*gv < 0, normal " 
530                  << fName << " " << normal        519                  << fName << " " << normal 
531                  << G4endl;                       520                  << G4endl;
532 #endif                                            521 #endif 
533       }                                        << 522       } else {
534       else                                     << 
535       {                                        << 
536          // gxx[i] is accepted.                   523          // gxx[i] is accepted.
537          if (distance[i] < bestdistance)       << 524          if (distance[i] < bestdistance) {
538          {                                     << 
539             bestdistance = distance[i];           525             bestdistance = distance[i];
540             gxxbest = gxx[i];                     526             gxxbest = gxx[i];
541          }                                        527          }
542       }                                           528       } 
543    }                                              529    }
544                                                   530 
545 #ifdef G4TWISTDEBUG                               531 #ifdef G4TWISTDEBUG
546    if (besti < 0)                              << 532    if (besti < 0) {
547    {                                           << 533       G4cout << "~~~~~ G4VTwistSurface::DistanceToOut(p,v) - return ~~~" << G4endl;
548       G4cout << "~~ G4VTwistSurface::DistanceT << 
549       G4cout << "      No intersections   " <<    534       G4cout << "      No intersections   " << G4endl; 
550       G4cout << "      Name     : " << fName <    535       G4cout << "      Name     : " << fName << G4endl; 
551       G4cout << "      bestdist : " << bestdis    536       G4cout << "      bestdist : " << bestdistance << G4endl;
552       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    537       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
553    }                                           << 538    } else {
554    else                                        << 539       G4cout << "~~~~~ G4VTwistSurface::DistanceToOut(p,v) : return ~~~" << G4endl;
555    {                                           << 
556       G4cout << "~~ G4VTwistSurface::DistanceT << 
557       G4cout << "      Name, i  : " << fName <    540       G4cout << "      Name, i  : " << fName << " , " << i << G4endl; 
558       G4cout << "      gxx[i]   : " << gxxbest    541       G4cout << "      gxx[i]   : " << gxxbest << G4endl; 
559       G4cout << "      bestdist : " << bestdis    542       G4cout << "      bestdist : " << bestdistance << G4endl;
560       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    543       G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
561    }                                              544    } 
562 #endif                                            545 #endif
563                                                   546 
564    return bestdistance;                           547    return bestdistance;
565 }                                                 548 }
566                                                   549 
567 //============================================    550 //=====================================================================
568 //* DistanceTo(p) ----------------------------    551 //* DistanceTo(p) -----------------------------------------------------
569                                                   552 
570 G4double G4VTwistSurface::DistanceTo(const G4T << 553 G4double G4VTwistSurface::DistanceTo(const G4ThreeVector &gp,
571                                            G4T << 554                                       G4ThreeVector &gxxbest)
572 {                                                 555 {
573 #ifdef G4TWISTDEBUG                               556 #ifdef G4TWISTDEBUG
574    G4cout << "~~~~~ G4VTwistSurface::DistanceT    557    G4cout << "~~~~~ G4VTwistSurface::DistanceTo(p) - Start ~~~~~~~~~" << G4endl;
575    G4cout << "      Name : " << fName << G4end    558    G4cout << "      Name : " << fName << G4endl;
576    G4cout << "      gp   : " << gp << G4endl;     559    G4cout << "      gp   : " << gp << G4endl;
577    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    560    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
578 #endif                                            561 #endif
579                                                   562 
580                                                   563 
581    G4ThreeVector gxx[G4VSURFACENXX];              564    G4ThreeVector gxx[G4VSURFACENXX];
582    G4double      distance[G4VSURFACENXX]  ;       565    G4double      distance[G4VSURFACENXX]  ; 
583    G4int         areacode[G4VSURFACENXX]  ;       566    G4int         areacode[G4VSURFACENXX]  ;
584                                                   567    
585    for (G4int i = 0 ; i<G4VSURFACENXX ; ++i )  << 568    for (G4int i = 0 ; i<G4VSURFACENXX ; i++ ) {
586    {                                           << 
587      distance[i] = kInfinity ;                    569      distance[i] = kInfinity ;
588      areacode[i] = sOutside ;                     570      areacode[i] = sOutside ;
589    }                                              571    }
590                                                   572 
                                                   >> 573 
591    DistanceToSurface(gp, gxx, distance, areaco    574    DistanceToSurface(gp, gxx, distance, areacode);
592    gxxbest = gxx[0];                              575    gxxbest = gxx[0];
593                                                   576 
594 #ifdef G4TWISTDEBUG                               577 #ifdef G4TWISTDEBUG
595    G4cout << "~~~~~ G4VTwistSurface::DistanceT    578    G4cout << "~~~~~ G4VTwistSurface::DistanceTo(p) - return ~~~~~~~~" << G4endl;
596    G4cout << "      Name     : " << fName << G    579    G4cout << "      Name     : " << fName << G4endl; 
597    G4cout << "      gxx      : " << gxxbest <<    580    G4cout << "      gxx      : " << gxxbest << G4endl; 
598    G4cout << "      bestdist : " << distance[0    581    G4cout << "      bestdist : " << distance[0] << G4endl;
599    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    582    G4cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << G4endl;
600 #endif                                            583 #endif
601                                                   584 
602    return distance[0];                            585    return distance[0];
603 }                                                 586 }
604                                                   587 
605 //============================================    588 //=====================================================================
606 //* IsSameBoundary ---------------------------    589 //* IsSameBoundary ----------------------------------------------------
607                                                   590 
608 G4bool                                         << 591 G4bool G4VTwistSurface::IsSameBoundary(G4VTwistSurface *surface1, G4int areacode1,
609 G4VTwistSurface::IsSameBoundary(G4VTwistSurfac << 592                                   G4VTwistSurface *surface2, G4int areacode2 ) const
610                                 G4VTwistSurfac << 
611 {                                                 593 {
612    //                                             594    //
613    // IsSameBoundary                              595    // IsSameBoundary
614    //                                             596    //
615    // checking tool whether two boundaries on     597    // checking tool whether two boundaries on different surfaces are same or not.
616    //                                             598    //
617                                                   599 
618    G4bool testbitmode = true;                     600    G4bool testbitmode = true;
619    G4bool iscorner[2] = {IsCorner(areacode1, t    601    G4bool iscorner[2] = {IsCorner(areacode1, testbitmode), 
620                          IsCorner(areacode2, t    602                          IsCorner(areacode2, testbitmode)};
621                                                   603 
622    if (iscorner[0] && iscorner[1])             << 604    if (iscorner[0] && iscorner[1]) {
623    {                                           << 
624       // on corner                                605       // on corner 
625       G4ThreeVector corner1 =                     606       G4ThreeVector corner1 = 
626            surf1->ComputeGlobalPoint(surf1->Ge << 607            surface1->ComputeGlobalPoint(surface1->GetCorner(areacode1));
627       G4ThreeVector corner2 =                     608       G4ThreeVector corner2 = 
628            surf2->ComputeGlobalPoint(surf2->Ge << 609            surface2->ComputeGlobalPoint(surface2->GetCorner(areacode2));
629                                                   610 
630       return (corner1 - corner2).mag() < kCarT << 611       if ((corner1 - corner2).mag() < kCarTolerance) {
631    }                                           << 612          return true;
632    else if ((IsBoundary(areacode1, testbitmode << 613       } else {
633             (IsBoundary(areacode2, testbitmode << 614          return false;
634    {                                           << 615       }
                                                   >> 616     
                                                   >> 617    } else if ((IsBoundary(areacode1, testbitmode) && (!iscorner[0])) &&
                                                   >> 618               (IsBoundary(areacode2, testbitmode) && (!iscorner[1]))) {
635       // on boundary                              619       // on boundary  
636       G4ThreeVector d1, d2, ld1, ld2;             620       G4ThreeVector d1, d2, ld1, ld2;
637       G4ThreeVector x01, x02, lx01, lx02;         621       G4ThreeVector x01, x02, lx01, lx02;
638       G4int         type1, type2;                 622       G4int         type1, type2;
639       surf1->GetBoundaryParameters(areacode1,  << 623       surface1->GetBoundaryParameters(areacode1, ld1, lx01, type1);
640       surf2->GetBoundaryParameters(areacode2,  << 624       surface2->GetBoundaryParameters(areacode2, ld2, lx02, type2);
641                                                   625 
642       x01 = surf1->ComputeGlobalPoint(lx01);   << 626       x01 = surface1->ComputeGlobalPoint(lx01);
643       x02 = surf2->ComputeGlobalPoint(lx02);   << 627       x02 = surface2->ComputeGlobalPoint(lx02);
644       d1  = surf1->ComputeGlobalDirection(ld1) << 628       d1  = surface1->ComputeGlobalDirection(ld1);
645       d2  = surf2->ComputeGlobalDirection(ld2) << 629       d2  = surface2->ComputeGlobalDirection(ld2);
                                                   >> 630 
                                                   >> 631       if ((x01 - x02).mag() < kCarTolerance &&
                                                   >> 632           (d1 - d2).mag() < kCarTolerance) {
                                                   >> 633         return true;
                                                   >> 634       } else {
                                                   >> 635         return false;
                                                   >> 636       }
646                                                   637 
647       return (x01 - x02).mag() < kCarTolerance << 638    } else {
648             && (d1 - d2).mag() < kCarTolerance << 
649    }                                           << 
650    else                                        << 
651    {                                           << 
652       return false;                               639       return false;
653    }                                              640    }
654 }                                                 641 }
655                                                   642 
656 //============================================    643 //=====================================================================
657 //* GetBoundaryParameters --------------------    644 //* GetBoundaryParameters ---------------------------------------------
658                                                   645 
659 void G4VTwistSurface::GetBoundaryParameters(co << 646 void G4VTwistSurface::GetBoundaryParameters(const G4int         &areacode,
660                                              G << 647                                              G4ThreeVector &d,
661                                              G << 648                                              G4ThreeVector &x0,
662                                              G << 649                                              G4int         &boundarytype) const
663 {                                                 650 {
664    // areacode must be one of them:               651    // areacode must be one of them:
665    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,       652    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
666    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.       653    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
667                                                   654    
668    for (const auto & boundary : fBoundaries)   << 655    G4int i;
669    {                                           << 656    for (i=0; i<4; i++) {
670       if (boundary.GetBoundaryParameters(areac << 657       if (fBoundaries[i].GetBoundaryParameters(areacode, d, x0,
671       {                                        << 658                                                boundarytype)) {
672          return;                                  659          return;
673       }                                           660       }
674    }                                              661    }
675                                                   662 
676    std::ostringstream message;                    663    std::ostringstream message;
677    message << "Not registered boundary." << G4    664    message << "Not registered boundary." << G4endl
678            << "        Boundary at areacode "     665            << "        Boundary at areacode " << std::hex << areacode
679            << std::dec << G4endl                  666            << std::dec << G4endl
680            << "        is not registered.";       667            << "        is not registered.";
681    G4Exception("G4VTwistSurface::GetBoundaryPa    668    G4Exception("G4VTwistSurface::GetBoundaryParameters()", "GeomSolids0002",
682                FatalException, message);          669                FatalException, message);
683 }                                                 670 }
684                                                   671 
685 //============================================    672 //=====================================================================
686 //* GetBoundaryAtPZ --------------------------    673 //* GetBoundaryAtPZ ---------------------------------------------------
687                                                   674 
688 G4ThreeVector G4VTwistSurface::GetBoundaryAtPZ    675 G4ThreeVector G4VTwistSurface::GetBoundaryAtPZ(G4int areacode,
689                                                << 676                                           const G4ThreeVector &p) const
690 {                                                 677 {
691    // areacode must be one of them:               678    // areacode must be one of them:
692    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,       679    // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
693    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.       680    // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
694                                                   681 
695    if (((areacode & sAxis0) != 0) && ((areacod << 682    if (areacode & sAxis0 && areacode & sAxis1) {
696    {                                           << 
697      std::ostringstream message;                  683      std::ostringstream message;
698      message << "Point is in the corner area."    684      message << "Point is in the corner area." << G4endl
699              << "        This function returns    685              << "        This function returns "
700              << "a direction vector of a bound    686              << "a direction vector of a boundary line." << G4endl
701              << "        areacode = " << areac    687              << "        areacode = " << areacode;
702      G4Exception("G4VTwistSurface::GetBoundary    688      G4Exception("G4VTwistSurface::GetBoundaryAtPZ()", "GeomSolids0003",
703                  FatalException, message);        689                  FatalException, message);
704    }                                              690    }
705                                                   691 
706    G4ThreeVector d;                               692    G4ThreeVector d;
707    G4ThreeVector x0;                              693    G4ThreeVector x0;
708    G4int         boundarytype = 0;             << 694    G4int         boundarytype;
709    G4bool        found = false;                   695    G4bool        found = false;
710                                                   696    
711    for (const auto & boundary : fBoundaries)   << 697    for (G4int i=0; i<4; i++) {
712    {                                           << 698       if (fBoundaries[i].GetBoundaryParameters(areacode, d, x0, 
713       if (boundary.GetBoundaryParameters(areac << 699                                                 boundarytype)){
714       {                                        << 
715          found = true;                            700          found = true;
716          continue;                                701          continue;
717       }                                           702       }
718    }                                              703    }
719                                                   704 
720    if (!found)                                 << 705    if (!found) {
721    {                                           << 
722      std::ostringstream message;                  706      std::ostringstream message;
723      message << "Not registered boundary." <<     707      message << "Not registered boundary." << G4endl
724              << "        Boundary at areacode     708              << "        Boundary at areacode " << areacode << G4endl
725              << "        is not registered.";     709              << "        is not registered.";
726      G4Exception("G4VTwistSurface::GetBoundary    710      G4Exception("G4VTwistSurface::GetBoundaryAtPZ()", "GeomSolids0002",
727                  FatalException, message);        711                  FatalException, message);
728    }                                              712    }
729                                                   713 
730    if (((boundarytype & sAxisPhi) == sAxisPhi)    714    if (((boundarytype & sAxisPhi) == sAxisPhi) ||
731        ((boundarytype & sAxisRho) == sAxisRho) << 715        ((boundarytype & sAxisRho) == sAxisRho)) {
732    {                                           << 
733      std::ostringstream message;                  716      std::ostringstream message;
734      message << "Not a z-depended line boundar    717      message << "Not a z-depended line boundary." << G4endl
735              << "        Boundary at areacode     718              << "        Boundary at areacode " << areacode << G4endl
736              << "        is not a z-depended l    719              << "        is not a z-depended line.";
737      G4Exception("G4VTwistSurface::GetBoundary    720      G4Exception("G4VTwistSurface::GetBoundaryAtPZ()", "GeomSolids0002",
738                  FatalException, message);        721                  FatalException, message);
739    }                                              722    }
740    return ((p.z() - x0.z()) / d.z()) * d + x0;    723    return ((p.z() - x0.z()) / d.z()) * d + x0;
741 }                                                 724 }
742                                                   725 
743 //============================================    726 //=====================================================================
744 //* SetCorner --------------------------------    727 //* SetCorner ---------------------------------------------------------
745                                                   728 
746 void G4VTwistSurface::SetCorner(G4int areacode << 729 void G4VTwistSurface::SetCorner(G4int areacode, G4double x, G4double y, G4double z)
747                                 G4double x, G4 << 
748 {                                                 730 {
749    if ((areacode & sCorner) != sCorner)        << 731    if ((areacode & sCorner) != sCorner){
750    {                                           << 
751      std::ostringstream message;                  732      std::ostringstream message;
752      message << "Area code must represents cor    733      message << "Area code must represents corner." << G4endl
753              << "        areacode " << areacod    734              << "        areacode " << areacode;
754      G4Exception("G4VTwistSurface::SetCorner()    735      G4Exception("G4VTwistSurface::SetCorner()", "GeomSolids0002",
755                  FatalException, message);        736                  FatalException, message);
756    }                                              737    }
757                                                   738 
758    if ((areacode & sC0Min1Min) == sC0Min1Min)     739    if ((areacode & sC0Min1Min) == sC0Min1Min) {
759       fCorners[0].set(x, y, z);                   740       fCorners[0].set(x, y, z);
760    } else if ((areacode & sC0Max1Min) == sC0Ma    741    } else if ((areacode & sC0Max1Min) == sC0Max1Min) {
761       fCorners[1].set(x, y, z);                   742       fCorners[1].set(x, y, z);
762    } else if ((areacode & sC0Max1Max) == sC0Ma    743    } else if ((areacode & sC0Max1Max) == sC0Max1Max) {
763       fCorners[2].set(x, y, z);                   744       fCorners[2].set(x, y, z);
764    } else if ((areacode & sC0Min1Max) == sC0Mi    745    } else if ((areacode & sC0Min1Max) == sC0Min1Max) {
765       fCorners[3].set(x, y, z);                   746       fCorners[3].set(x, y, z);
766    }                                              747    }
767 }                                                 748 }
768                                                   749 
769 //============================================    750 //=====================================================================
770 //* SetBoundaryAxis --------------------------    751 //* SetBoundaryAxis ---------------------------------------------------
771                                                   752 
772 void G4VTwistSurface::GetBoundaryAxis(G4int ar    753 void G4VTwistSurface::GetBoundaryAxis(G4int areacode, EAxis axis[]) const
773 {                                                 754 {
774    if ((areacode & sBoundary) != sBoundary) {     755    if ((areacode & sBoundary) != sBoundary) {
775      G4Exception("G4VTwistSurface::GetBoundary    756      G4Exception("G4VTwistSurface::GetBoundaryAxis()", "GeomSolids0003",
776                  FatalException, "Not located     757                  FatalException, "Not located on a boundary!");
777    }                                              758    }
778    for (G4int i=0; i<2; ++i)                   << 759    G4int i;
779    {                                           << 760    for (i=0; i<2; i++) {
                                                   >> 761 
780       G4int whichaxis = 0 ;                       762       G4int whichaxis = 0 ;
781       if (i == 0) {                               763       if (i == 0) {
782          whichaxis = sAxis0;                      764          whichaxis = sAxis0;
783       } else if (i == 1) {                        765       } else if (i == 1) {
784          whichaxis = sAxis1;                      766          whichaxis = sAxis1;
785       }                                           767       }
786                                                   768       
787       // extracted axiscode of whichaxis          769       // extracted axiscode of whichaxis
788       G4int axiscode = whichaxis & sAxisMask &    770       G4int axiscode = whichaxis & sAxisMask & areacode ; 
789       if (axiscode != 0) {                     << 771       if (axiscode) {
790          if (axiscode == (whichaxis & sAxisX))    772          if (axiscode == (whichaxis & sAxisX)) {
791             axis[i] = kXAxis;                     773             axis[i] = kXAxis;
792          } else if (axiscode == (whichaxis & s    774          } else if (axiscode == (whichaxis & sAxisY)) {
793             axis[i] = kYAxis;                     775             axis[i] = kYAxis;
794          } else if (axiscode == (whichaxis & s    776          } else if (axiscode == (whichaxis & sAxisZ)) {
795             axis[i] = kZAxis;                     777             axis[i] = kZAxis;
796          } else if (axiscode == (whichaxis & s    778          } else if (axiscode == (whichaxis & sAxisRho)) {
797             axis[i] = kRho;                       779             axis[i] = kRho;
798          } else if (axiscode == (whichaxis & s    780          } else if (axiscode == (whichaxis & sAxisPhi)) {
799             axis[i] = kPhi;                       781             axis[i] = kPhi;
800          } else {                                 782          } else {
801            std::ostringstream message;            783            std::ostringstream message;
802            message << "Not supported areacode.    784            message << "Not supported areacode." << G4endl
803                    << "        areacode " << a    785                    << "        areacode " << areacode;
804            G4Exception("G4VTwistSurface::GetBo    786            G4Exception("G4VTwistSurface::GetBoundaryAxis()", "GeomSolids0001",
805                        FatalException, message    787                        FatalException, message);
806          }                                        788          }
807       }                                           789       }
808    }                                              790    }
809 }                                                 791 }
810                                                   792 
811 //============================================    793 //=====================================================================
812 //* SetBoundaryLimit -------------------------    794 //* SetBoundaryLimit --------------------------------------------------
813                                                   795 
814 void G4VTwistSurface::GetBoundaryLimit(G4int a    796 void G4VTwistSurface::GetBoundaryLimit(G4int areacode, G4double limit[]) const
815 {                                                 797 {
816    if ((areacode & sCorner) != 0) {            << 798    if (areacode & sCorner) {
817       if ((areacode & sC0Min1Min) != 0) {      << 799       if (areacode & sC0Min1Min) {
818          limit[0] = fAxisMin[0];                  800          limit[0] = fAxisMin[0];
819          limit[1] = fAxisMin[1];                  801          limit[1] = fAxisMin[1];
820       } else if ((areacode & sC0Max1Min) != 0) << 802       } else if (areacode & sC0Max1Min) {
821          limit[0] = fAxisMax[0];                  803          limit[0] = fAxisMax[0];
822          limit[1] = fAxisMin[1];                  804          limit[1] = fAxisMin[1];
823       } else if ((areacode & sC0Max1Max) != 0) << 805       } else if (areacode & sC0Max1Max) {
824          limit[0] = fAxisMax[0];                  806          limit[0] = fAxisMax[0];
825          limit[1] = fAxisMax[1];                  807          limit[1] = fAxisMax[1];
826       } else if ((areacode & sC0Min1Max) != 0) << 808       } else if (areacode & sC0Min1Max) {
827          limit[0] = fAxisMin[0];                  809          limit[0] = fAxisMin[0];
828          limit[1] = fAxisMax[1];                  810          limit[1] = fAxisMax[1];
829       }                                           811       }
830    } else if ((areacode & sBoundary) != 0) {   << 812    } else if (areacode & sBoundary) {
831       if ((areacode & (sAxis0 | sAxisMin)) !=  << 813       if (areacode & (sAxis0 | sAxisMin)) {
832          limit[0] = fAxisMin[0];                  814          limit[0] = fAxisMin[0];
833       } else if ((areacode & (sAxis1 | sAxisMi << 815       } else if (areacode & (sAxis1 | sAxisMin)) {
834          limit[0] = fAxisMin[1];                  816          limit[0] = fAxisMin[1];
835       } else if ((areacode & (sAxis0 | sAxisMa << 817       } else if (areacode & (sAxis0 | sAxisMax)) {
836          limit[0] = fAxisMax[0];                  818          limit[0] = fAxisMax[0];
837       } else if ((areacode & (sAxis1 | sAxisMa << 819       } else if (areacode & (sAxis1 | sAxisMax)) {
838          limit[0] = fAxisMax[1];                  820          limit[0] = fAxisMax[1];
839       }                                           821       }
840    } else {                                       822    } else {
841      std::ostringstream message;                  823      std::ostringstream message;
842      message << "Not located on a boundary!" <    824      message << "Not located on a boundary!" << G4endl
843              << "          areacode " << areac    825              << "          areacode " << areacode;
844      G4Exception("G4VTwistSurface::GetBoundary    826      G4Exception("G4VTwistSurface::GetBoundaryLimit()", "GeomSolids1002",
845                  JustWarning, message);           827                  JustWarning, message);
846    }                                              828    }
847 }                                                 829 }
848                                                   830 
849 //============================================    831 //=====================================================================
850 //* SetBoundary ------------------------------    832 //* SetBoundary -------------------------------------------------------
851                                                   833 
852 void G4VTwistSurface::SetBoundary(const G4int& << 834 void G4VTwistSurface::SetBoundary(const G4int         &axiscode,
853                                   const G4Thre << 835                              const G4ThreeVector &direction,
854                                   const G4Thre << 836                              const G4ThreeVector &x0,
855                                   const G4int& << 837                              const G4int         &boundarytype)
856 {                                                 838 {
857    G4int code = (~sAxisMask) & axiscode;          839    G4int code = (~sAxisMask) & axiscode;
858    if ((code == (sAxis0 & sAxisMin)) ||           840    if ((code == (sAxis0 & sAxisMin)) ||
859        (code == (sAxis0 & sAxisMax)) ||           841        (code == (sAxis0 & sAxisMax)) ||
860        (code == (sAxis1 & sAxisMin)) ||           842        (code == (sAxis1 & sAxisMin)) ||
861        (code == (sAxis1 & sAxisMax)))          << 843        (code == (sAxis1 & sAxisMax))) {
862    {                                           << 844 
                                                   >> 845       G4int i;
863       G4bool done = false;                        846       G4bool done = false;
864       for (auto & boundary : fBoundaries)      << 847       for (i=0; i<4; i++) {
865       {                                        << 848          if (fBoundaries[i].IsEmpty()) {
866          if (boundary.IsEmpty())               << 849             fBoundaries[i].SetFields(axiscode, direction,
867          {                                     << 850                                      x0, boundarytype);
868             boundary.SetFields(axiscode, direc << 
869             done = true;                          851             done = true;
870             break;                                852             break;
871          }                                        853          }
872       }                                           854       }
873                                                   855 
874       if (!done)                               << 856       if (!done) {
875       {                                        << 
876          G4Exception("G4VTwistSurface::SetBoun    857          G4Exception("G4VTwistSurface::SetBoundary()", "GeomSolids0003",
877                       FatalException, "Number     858                       FatalException, "Number of boundary exceeding 4!");
878       }                                           859       }
879    }                                           << 860    } else {
880    else                                        << 
881    {                                           << 
882       std::ostringstream message;                 861       std::ostringstream message;
883       message << "Invalid axis-code." << G4end    862       message << "Invalid axis-code." << G4endl
884               << "        axiscode = "            863               << "        axiscode = "
885               << std::hex << axiscode << std::    864               << std::hex << axiscode << std::dec;
886       G4Exception("G4VTwistSurface::SetBoundar    865       G4Exception("G4VTwistSurface::SetBoundary()", "GeomSolids0003",
887                   FatalException, message);       866                   FatalException, message);
888    }                                              867    }
889 }                                                 868 }
890                                                   869 
891 //============================================    870 //=====================================================================
892 //* GetFace ----------------------------------    871 //* GetFace -----------------------------------------------------------
893                                                   872 
894 G4int G4VTwistSurface::GetFace( G4int i, G4int    873 G4int G4VTwistSurface::GetFace( G4int i, G4int j, G4int k,
895                                 G4int n, G4int    874                                 G4int n, G4int iside ) 
896 {                                                 875 {
897   // this is the face mapping function            876   // this is the face mapping function
898   // (i,j) -> face number                         877   // (i,j) -> face number
899                                                   878 
900   if ( iside == 0 ) {                             879   if ( iside == 0 ) {
901     return i * ( k - 1 ) + j ;                    880     return i * ( k - 1 ) + j ;
902   }                                               881   }
903                                                   882 
904   else if ( iside == 1 ) {                        883   else if ( iside == 1 ) {
905     return (k-1)*(k-1) + i*(k-1) + j ;            884     return (k-1)*(k-1) + i*(k-1) + j ;
906   }                                               885   }
907                                                   886 
908   else if ( iside == 2 ) {                        887   else if ( iside == 2 ) {
909     return 2*(k-1)*(k-1) + i*(k-1) + j ;          888     return 2*(k-1)*(k-1) + i*(k-1) + j ;
910   }                                               889   }
911                                                   890 
912   else if ( iside == 3 ) {                        891   else if ( iside == 3 ) {
913     return 2*(k-1)*(k-1) + (n-1)*(k-1) + i*(k-    892     return 2*(k-1)*(k-1) + (n-1)*(k-1) + i*(k-1) + j ;
914   }                                               893   }
915                                                   894   
916   else if ( iside == 4 ) {                        895   else if ( iside == 4 ) {
917     return 2*(k-1)*(k-1) + 2*(n-1)*(k-1) + i*(    896     return 2*(k-1)*(k-1) + 2*(n-1)*(k-1) + i*(k-1) + j ;
918   }                                               897   }
919                                                   898   
920   else if ( iside == 5 ) {                        899   else if ( iside == 5 ) {
921     return 2*(k-1)*(k-1) + 3*(n-1)*(k-1) + i*(    900     return 2*(k-1)*(k-1) + 3*(n-1)*(k-1) + i*(k-1) + j ;
922   }                                               901   }
923                                                   902 
924   else {                                          903   else {
                                                   >> 904 
925     std::ostringstream message;                   905     std::ostringstream message;
926     message << "Not correct side number: "        906     message << "Not correct side number: "
927             << GetName() << G4endl                907             << GetName() << G4endl
928             << "iside is " << iside << " but s    908             << "iside is " << iside << " but should be "
929             << "0,1,2,3,4 or 5" << ".";           909             << "0,1,2,3,4 or 5" << ".";
930     G4Exception("G4TwistSurface::G4GetFace()",    910     G4Exception("G4TwistSurface::G4GetFace()", "GeomSolids0002",
931                 FatalException, message);         911                 FatalException, message);
                                                   >> 912 
                                                   >> 913 
932   }                                               914   }
933                                                   915 
934   return -1 ;  // wrong face                      916   return -1 ;  // wrong face
935 }                                                 917 }
936                                                   918 
937 //============================================    919 //=====================================================================
938 //* GetNode ----------------------------------    920 //* GetNode -----------------------------------------------------------
939                                                   921 
940 G4int G4VTwistSurface::GetNode( G4int i, G4int    922 G4int G4VTwistSurface::GetNode( G4int i, G4int j, G4int k,
941                                 G4int n, G4int    923                                 G4int n, G4int iside ) 
942 {                                                 924 {
943   // this is the node mapping function            925   // this is the node mapping function
944   // (i,j) -> node number                         926   // (i,j) -> node number
945   // Depends on the side iside and the used me    927   // Depends on the side iside and the used meshing of the surface
946                                                   928 
947   if ( iside == 0 )                            << 929   if ( iside == 0 ) {
948   {                                            << 
949     // lower endcap is kxk squared.               930     // lower endcap is kxk squared. 
950     // n = k                                      931     // n = k 
951     return i * k + j ;                            932     return i * k + j ;
952   }                                               933   }
953                                                   934 
954   if ( iside == 1 )                            << 935   if ( iside == 1 ) {
955   {                                            << 
956     // upper endcap is kxk squared. Shift by k    936     // upper endcap is kxk squared. Shift by k*k
957     // n = k                                      937     // n = k 
958     return  k*k + i*k + j ;                       938     return  k*k + i*k + j ;
959   }                                               939   }
960                                                   940 
961   else if ( iside == 2 )                       << 941   else if ( iside == 2 ) {
962   {                                            << 
963     // front side.                                942     // front side.
964     if      ( i == 0 )   { return       j ;  } << 943     if      ( i == 0 )     {   return       j ;  }
965     else if ( i == n-1 ) { return k*k + j ;  } << 944     else if ( i == n-1 )   {   return k*k + j ;  } 
966     else                 { return 2*k*k + 4*(i << 945     else                   {   return 2*k*k + 4*(i-1)*(k-1) + j ; }
967   }                                               946   }
968                                                   947 
969   else if ( iside == 3 )                       << 948   else if ( iside == 3 ) {
970   {                                            << 
971     // right side                                 949     // right side
972     if      ( i == 0 )   { return       (j+1)* << 950     if      ( i == 0 )     {   return       (j+1)*k - 1 ; } 
973     else if ( i == n-1 ) { return k*k + (j+1)* << 951     else if ( i == n-1 )   {   return k*k + (j+1)*k - 1 ; }
974     else                                       << 952     else                   {   return 2*k*k + 4*(i-1)*(k-1) + (k-1) + j ; }
975     {                                          << 
976       return 2*k*k + 4*(i-1)*(k-1) + (k-1) + j << 
977     }                                          << 
978   }                                               953   }
979   else if ( iside == 4 )                       << 954   else if ( iside == 4 ) {
980   {                                            << 955     // back side.
981     // back side                               << 956     if      ( i == 0 )     {   return   k*k - 1 - j ; }               // reversed order
982     if      ( i == 0 )   { return   k*k - 1 -  << 957     else if ( i == n-1 )   {   return 2*k*k - 1 - j ; }               // reversed order 
983     else if ( i == n-1 ) { return 2*k*k - 1 -  << 958     else                   {   return 2*k*k + 4*(i-1)*(k-1) + 2*(k-1) + j ; // normal order
984     else                                       << 
985     {                                          << 
986       return 2*k*k + 4*(i-1)*(k-1) + 2*(k-1) + << 
987     }                                             959     }
988   }                                               960   }
989   else if ( iside == 5 )                       << 961   else if ( iside == 5 ) {
990   {                                            << 
991     // left side                                  962     // left side 
992     if      ( i == 0 )   { return k*k   - (j+1 << 963     if      ( i == 0 )     {   return k*k   - (j+1)*k ; }             // reversed order
993     else if ( i == n-1)  { return 2*k*k - (j+1 << 964     else if ( i == n-1)    {   return 2*k*k - (j+1)*k ; }             // reverded order
994     else                                       << 965     else {
995     {                                          << 966       if ( j == k-1 )      {   return 2*k*k + 4*(i-1)*(k-1) ; }       // special case
996       if ( j == k-1 ) { return 2*k*k + 4*(i-1) << 967       else                 {   return 2*k*k + 4*(i-1)*(k-1) + 3*(k-1) + j ; }  // normal order
997       else                                     << 968     }  
998       {                                        << 
999         return 2*k*k + 4*(i-1)*(k-1) + 3*(k-1) << 
1000       }                                       << 
1001     }                                         << 
1002   }                                              969   }
1003   else                                        << 970 
1004   {                                           << 971   else {
                                                   >> 972 
1005     std::ostringstream message;                  973     std::ostringstream message;
1006     message << "Not correct side number: "       974     message << "Not correct side number: "
1007             << GetName() << G4endl               975             << GetName() << G4endl
1008             << "iside is " << iside << " but     976             << "iside is " << iside << " but should be "
1009             << "0,1,2,3,4 or 5" << ".";          977             << "0,1,2,3,4 or 5" << ".";
1010     G4Exception("G4TwistSurface::G4GetNode()"    978     G4Exception("G4TwistSurface::G4GetNode()", "GeomSolids0002",
1011                 FatalException, message);        979                 FatalException, message);
1012   }                                              980   } 
1013   return -1 ;  // wrong node                     981   return -1 ;  // wrong node 
1014 }                                                982 } 
1015                                                  983 
1016 //===========================================    984 //=====================================================================
1017 //* GetEdgeVisiblility ----------------------    985 //* GetEdgeVisiblility ------------------------------------------------
1018                                                  986 
1019 G4int G4VTwistSurface::GetEdgeVisibility( G4i << 987 G4int G4VTwistSurface::GetEdgeVisibility( G4int i, G4int j, G4int k, G4int n, G4int number, G4int orientation) 
1020                                           G4i << 
1021 {                                                988 {
                                                   >> 989 
1022   // clockwise filling         -> positive or    990   // clockwise filling         -> positive orientation
1023   // counter clockwise filling -> negative or    991   // counter clockwise filling -> negative orientation 
1024                                                  992 
1025   //                                             993   //
1026   //   d    C    c                               994   //   d    C    c
1027   //     +------+                                995   //     +------+ 
1028   //     |      |                                996   //     |      |
1029   //     |      |                                997   //     |      |
1030   //     |      |                                998   //     |      |
1031   //   D |      |B                               999   //   D |      |B
1032   //     |      |                                1000   //     |      |
1033   //     |      |                                1001   //     |      |
1034   //     |      |                                1002   //     |      |
1035   //     +------+                                1003   //     +------+
1036   //    a   A    b                               1004   //    a   A    b
1037   //                                             1005   //    
1038   //  a = +--+    A = ---+                       1006   //  a = +--+    A = ---+
1039   //  b = --++    B = --+-                       1007   //  b = --++    B = --+-
1040   //  c = -++-    C = -+--                       1008   //  c = -++-    C = -+--
1041   //  d = ++--    D = +---                       1009   //  d = ++--    D = +---
1042                                                  1010 
1043                                                  1011 
1044   // check first invisible faces                 1012   // check first invisible faces
1045                                                  1013 
1046   if ( ( i>0 && i<n-2 ) && ( j>0 && j<k-2 ) ) << 1014   if ( ( i>0 && i<n-2 ) && ( j>0 && j<k-2 ) ) {
1047   {                                           << 
1048     return -1 ;   // always invisible, signs:    1015     return -1 ;   // always invisible, signs:   ----
1049   }                                              1016   }
1050                                                  1017   
1051   // change first the vertex number (depends     1018   // change first the vertex number (depends on the orientation)
1052   // 0,1,2,3  -> 3,2,1,0                         1019   // 0,1,2,3  -> 3,2,1,0
1053   if ( orientation < 0 ) { number = ( 3 - num    1020   if ( orientation < 0 ) { number = ( 3 - number ) ;  }
1054                                                  1021   
1055   // check true edges                            1022   // check true edges
1056   if ( ( j>=1 && j<=k-3 ) )                   << 1023   if ( ( j>=1 && j<=k-3 ) ) {
1057   {                                           << 1024 
1058     if ( i == 0 )  {        // signs (A):  --    1025     if ( i == 0 )  {        // signs (A):  ---+  
1059       return ( number == 3 ) ? 1 : -1 ;          1026       return ( number == 3 ) ? 1 : -1 ;
1060     }                                            1027     }
1061                                                  1028     
1062     else if ( i == n-2 ) {  // signs (C):  -+    1029     else if ( i == n-2 ) {  // signs (C):  -+--
1063       return  ( number == 1 ) ? 1 : -1 ;         1030       return  ( number == 1 ) ? 1 : -1 ; 
1064     }                                            1031     }
1065                                                  1032     
1066     else                                      << 1033     else {
1067     {                                         << 
1068       std::ostringstream message;                1034       std::ostringstream message;
1069       message << "Not correct face number: "     1035       message << "Not correct face number: " << GetName() << " !";
1070       G4Exception("G4TwistSurface::G4GetEdgeV    1036       G4Exception("G4TwistSurface::G4GetEdgeVisibility()",
1071                   "GeomSolids0003", FatalExce    1037                   "GeomSolids0003", FatalException, message);
1072     }                                            1038     }
1073   }                                              1039   }
1074                                                  1040   
1075   if ( ( i>=1 && i<=n-3 ) )                   << 1041   if ( ( i>=1 && i<=n-3 ) ) {
1076   {                                           << 1042 
1077     if ( j == 0 )  {        // signs (D):  +-    1043     if ( j == 0 )  {        // signs (D):  +---
1078       return ( number == 0 ) ? 1 : -1 ;          1044       return ( number == 0 ) ? 1 : -1 ;
1079     }                                            1045     }
1080                                                  1046 
1081     else if ( j == k-2 ) {  // signs (B):  --    1047     else if ( j == k-2 ) {  // signs (B):  --+-
1082       return  ( number == 2 ) ? 1 : -1 ;         1048       return  ( number == 2 ) ? 1 : -1 ; 
1083     }                                            1049     }
1084                                                  1050 
1085     else                                      << 1051     else {
1086     {                                         << 
1087       std::ostringstream message;                1052       std::ostringstream message;
1088       message << "Not correct face number: "     1053       message << "Not correct face number: " << GetName() << " !";
1089       G4Exception("G4TwistSurface::G4GetEdgeV    1054       G4Exception("G4TwistSurface::G4GetEdgeVisibility()",
1090                   "GeomSolids0003", FatalExce    1055                   "GeomSolids0003", FatalException, message);
1091     }                                            1056     }
1092   }                                              1057   }
1093                                                  1058   
1094   // now the corners                             1059   // now the corners
1095   if ( i == 0 && j == 0 ) {          // signs    1060   if ( i == 0 && j == 0 ) {          // signs (a) : +--+
1096     return ( number == 0 || number == 3 ) ? 1    1061     return ( number == 0 || number == 3 ) ? 1 : -1 ;
1097   }                                              1062   }
1098   else if ( i == 0 && j == k-2 ) {   // signs    1063   else if ( i == 0 && j == k-2 ) {   // signs (b) : --++
1099     return ( number == 2 || number == 3 ) ? 1    1064     return ( number == 2 || number == 3 ) ? 1 : -1 ;
1100   }                                              1065   }
1101   else if ( i == n-2 && j == k-2 ) { // signs    1066   else if ( i == n-2 && j == k-2 ) { // signs (c) : -++-
1102     return ( number == 1 || number == 2 ) ? 1    1067     return ( number == 1 || number == 2 ) ? 1 : -1 ;
1103   }                                              1068   }
1104   else if ( i == n-2 && j == 0 ) {   // signs    1069   else if ( i == n-2 && j == 0 ) {   // signs (d) : ++--
1105     return ( number == 0 || number == 1 ) ? 1    1070     return ( number == 0 || number == 1 ) ? 1 : -1 ;
1106   }                                              1071   }
1107   else                                        << 1072   else {
1108   {                                           << 
1109     std::ostringstream message;                  1073     std::ostringstream message;
1110     message << "Not correct face number: " <<    1074     message << "Not correct face number: " << GetName() << " !";
1111     G4Exception("G4TwistSurface::G4GetEdgeVis    1075     G4Exception("G4TwistSurface::G4GetEdgeVisibility()",
1112                 "GeomSolids0003", FatalExcept    1076                 "GeomSolids0003", FatalException, message);
1113   }                                              1077   }
1114                                                  1078 
1115   std::ostringstream message;                    1079   std::ostringstream message;
1116   message << "Not correct face number: " << G    1080   message << "Not correct face number: " << GetName() << " !";
1117   G4Exception("G4TwistSurface::G4GetEdgeVisib    1081   G4Exception("G4TwistSurface::G4GetEdgeVisibility()", "GeomSolids0003",
1118               FatalException, message);          1082               FatalException, message);
1119                                                  1083 
1120   return 0 ;                                     1084   return 0 ;
1121 }                                                1085 }
1122                                                  1086 
1123                                                  1087 
1124 //===========================================    1088 //=====================================================================
1125 //* DebugPrint ------------------------------    1089 //* DebugPrint --------------------------------------------------------
1126                                                  1090 
1127 void G4VTwistSurface::DebugPrint() const         1091 void G4VTwistSurface::DebugPrint() const
1128 {                                                1092 {
1129    G4ThreeVector A = fRot * GetCorner(sC0Min1    1093    G4ThreeVector A = fRot * GetCorner(sC0Min1Min) + fTrans;
1130    G4ThreeVector B = fRot * GetCorner(sC0Max1    1094    G4ThreeVector B = fRot * GetCorner(sC0Max1Min) + fTrans;
1131    G4ThreeVector C = fRot * GetCorner(sC0Max1    1095    G4ThreeVector C = fRot * GetCorner(sC0Max1Max) + fTrans;
1132    G4ThreeVector D = fRot * GetCorner(sC0Min1    1096    G4ThreeVector D = fRot * GetCorner(sC0Min1Max) + fTrans;
1133                                                  1097   
1134    G4cout << "/* G4VTwistSurface::DebugPrint( << 1098    G4cout << "/* G4VTwistSurface::DebugPrint():-------------------------------"
1135           << G4endl;                             1099           << G4endl;
1136    G4cout << "/* Name = " << fName << G4endl;    1100    G4cout << "/* Name = " << fName << G4endl;
1137    G4cout << "/* Axis = " << std::hex << fAxi    1101    G4cout << "/* Axis = " << std::hex << fAxis[0] << " "
1138           << std::hex << fAxis[1]                1102           << std::hex << fAxis[1] 
1139           << " (0,1,2,3,5 = kXAxis,kYAxis,kZA    1103           << " (0,1,2,3,5 = kXAxis,kYAxis,kZAxis,kRho,kPhi)"
1140           << std::dec << G4endl;                 1104           << std::dec << G4endl;
1141    G4cout << "/* BoundaryLimit(in local) fAxi    1105    G4cout << "/* BoundaryLimit(in local) fAxis0(min, max) = ("<<fAxisMin[0] 
1142           << ", " << fAxisMax[0] << ")" << G4    1106           << ", " << fAxisMax[0] << ")" << G4endl;
1143    G4cout << "/* BoundaryLimit(in local) fAxi    1107    G4cout << "/* BoundaryLimit(in local) fAxis1(min, max) = ("<<fAxisMin[1] 
1144           << ", " << fAxisMax[1] << ")" << G4    1108           << ", " << fAxisMax[1] << ")" << G4endl;
1145    G4cout << "/* Cornar point sC0Min1Min = "     1109    G4cout << "/* Cornar point sC0Min1Min = " << A << G4endl;
1146    G4cout << "/* Cornar point sC0Max1Min = "     1110    G4cout << "/* Cornar point sC0Max1Min = " << B << G4endl;
1147    G4cout << "/* Cornar point sC0Max1Max = "     1111    G4cout << "/* Cornar point sC0Max1Max = " << C << G4endl;
1148    G4cout << "/* Cornar point sC0Min1Max = "     1112    G4cout << "/* Cornar point sC0Min1Max = " << D << G4endl;
1149    G4cout << "/*-----------------------------    1113    G4cout << "/*---------------------------------------------------------"
1150           << G4endl;                             1114           << G4endl;
1151 }                                                1115 }
1152                                                  1116 
1153 //===========================================    1117 //=====================================================================
1154 // G4VTwistSurface::CurrentStatus class          1118 // G4VTwistSurface::CurrentStatus class
1155 //===========================================    1119 //=====================================================================
1156                                                  1120 
1157 //===========================================    1121 //=====================================================================
1158 //* CurrentStatus::CurrentStatus ------------    1122 //* CurrentStatus::CurrentStatus --------------------------------------
1159                                                  1123 
1160 G4VTwistSurface::CurrentStatus::CurrentStatus    1124 G4VTwistSurface::CurrentStatus::CurrentStatus() 
1161 {                                                1125 {
1162   for (size_t i=0; i<G4VSURFACENXX; ++i)      << 1126   for (size_t i=0; i<G4VSURFACENXX; i++)
1163   {                                              1127   {
1164     fDistance[i] = kInfinity;                    1128     fDistance[i] = kInfinity;
1165     fAreacode[i] = sOutside;                     1129     fAreacode[i] = sOutside;
1166     fIsValid[i]  = false;                        1130     fIsValid[i]  = false;
1167     fXX[i].set(kInfinity, kInfinity, kInfinit    1131     fXX[i].set(kInfinity, kInfinity, kInfinity);
1168   }                                              1132   }
1169   fNXX   = 0;                                    1133   fNXX   = 0;
1170   fLastp.set(kInfinity, kInfinity, kInfinity)    1134   fLastp.set(kInfinity, kInfinity, kInfinity);
1171   fLastv.set(kInfinity, kInfinity, kInfinity)    1135   fLastv.set(kInfinity, kInfinity, kInfinity);
1172   fLastValidate = kUninitialized;                1136   fLastValidate = kUninitialized;
1173   fDone = false;                                 1137   fDone = false;
1174 }                                                1138 }
1175                                                  1139 
1176 //===========================================    1140 //=====================================================================
1177 //* CurrentStatus::~CurrentStatus -----------    1141 //* CurrentStatus::~CurrentStatus -------------------------------------
1178                                                  1142 
1179 G4VTwistSurface::CurrentStatus::~CurrentStatu    1143 G4VTwistSurface::CurrentStatus::~CurrentStatus() 
1180 = default;                                    << 1144 {
                                                   >> 1145 }
1181                                                  1146 
1182 //===========================================    1147 //=====================================================================
1183 //* CurrentStatus::SetCurrentStatus ---------    1148 //* CurrentStatus::SetCurrentStatus -----------------------------------
1184                                                  1149 
1185 void                                             1150 void
1186 G4VTwistSurface::CurrentStatus::SetCurrentSta << 1151 G4VTwistSurface::CurrentStatus::SetCurrentStatus(G4int                i, 
1187                                               << 1152                                             G4ThreeVector       &xx, 
1188                                               << 1153                                             G4double            &dist, 
1189                                               << 1154                                             G4int               &areacode, 
1190                                               << 1155                                             G4bool              &isvalid,
1191                                               << 1156                                             G4int                nxx,
1192                                               << 1157                                             EValidate            validate,
1193                                            co << 1158                                       const G4ThreeVector *p, 
1194                                            co << 1159                                       const G4ThreeVector *v)
1195 {                                                1160 {
1196   fDistance[i]  = dist;                          1161   fDistance[i]  = dist;
1197   fAreacode[i]  = areacode;                      1162   fAreacode[i]  = areacode;
1198   fIsValid[i]   = isvalid;                       1163   fIsValid[i]   = isvalid;
1199   fXX[i]        = xx;                            1164   fXX[i]        = xx;
1200   fNXX          = nxx;                           1165   fNXX          = nxx;
1201   fLastValidate = validate;                      1166   fLastValidate = validate;
1202   if (p != nullptr)                           << 1167   if (p)
1203   {                                              1168   {
1204     fLastp = *p;                                 1169     fLastp = *p;
1205   }                                              1170   }
1206   else                                           1171   else
1207   {                                              1172   {
1208     G4Exception("G4VTwistSurface::CurrentStat    1173     G4Exception("G4VTwistSurface::CurrentStatus::SetCurrentStatus()",
1209                 "GeomSolids0003", FatalExcept    1174                 "GeomSolids0003", FatalException, "SetCurrentStatus: p = 0!");
1210   }                                              1175   }
1211   if (v != nullptr)                           << 1176   if (v) 
1212   {                                              1177   {
1213     fLastv = *v;                                 1178     fLastv = *v;
1214   }                                              1179   }
1215   else                                           1180   else
1216   {                                              1181   {
1217     fLastv.set(kInfinity, kInfinity, kInfinit    1182     fLastv.set(kInfinity, kInfinity, kInfinity);
1218   }                                              1183   }
1219   fDone = true;                                  1184   fDone = true;
1220 }                                                1185 }
1221                                                  1186 
1222 //===========================================    1187 //=====================================================================
1223 //* CurrentStatus::ResetfDone ---------------    1188 //* CurrentStatus::ResetfDone -----------------------------------------
1224                                                  1189 
1225 void                                             1190 void
1226 G4VTwistSurface::CurrentStatus::ResetfDone(EV << 1191 G4VTwistSurface::CurrentStatus::ResetfDone(EValidate     validate,
1227                                      const G4 << 1192                                 const G4ThreeVector *p, 
1228                                      const G4 << 1193                                 const G4ThreeVector *v)
1229                                                  1194 
1230 {                                                1195 {
1231   if (validate == fLastValidate && p != nullp << 1196   if (validate == fLastValidate && p && *p == fLastp)
1232   {                                              1197   {
1233      if (v == nullptr || (*v == fLastv)) retu << 1198      if (!v || (*v == fLastv)) return;
1234   }                                              1199   }         
1235   G4ThreeVector xx(kInfinity, kInfinity, kInf    1200   G4ThreeVector xx(kInfinity, kInfinity, kInfinity);
1236   for (size_t i=0; i<G4VSURFACENXX; ++i)      << 1201   for (size_t i=0; i<G4VSURFACENXX; i++)
1237   {                                              1202   {
1238     fDistance[i] = kInfinity;                    1203     fDistance[i] = kInfinity;
1239     fAreacode[i] = sOutside;                     1204     fAreacode[i] = sOutside;
1240     fIsValid[i]  = false;                        1205     fIsValid[i]  = false;
1241     fXX[i] = xx;   // bug in old code ( was f    1206     fXX[i] = xx;   // bug in old code ( was fXX[i] =  xx[i]  )
1242   }                                              1207   }
1243   fNXX = 0;                                   << 1208   fNXX   = 0;
1244   fLastp.set(kInfinity, kInfinity, kInfinity)    1209   fLastp.set(kInfinity, kInfinity, kInfinity);
1245   fLastv.set(kInfinity, kInfinity, kInfinity)    1210   fLastv.set(kInfinity, kInfinity, kInfinity);
1246   fLastValidate = kUninitialized;                1211   fLastValidate = kUninitialized;
1247   fDone = false;                                 1212   fDone = false;
1248 }                                                1213 }
1249                                                  1214 
1250 //===========================================    1215 //=====================================================================
1251 //* CurrentStatus::DebugPrint ---------------    1216 //* CurrentStatus::DebugPrint -----------------------------------------
1252                                                  1217 
1253 void                                             1218 void
1254 G4VTwistSurface::CurrentStatus::DebugPrint()     1219 G4VTwistSurface::CurrentStatus::DebugPrint() const
1255 {                                                1220 {
1256   G4cout << "CurrentStatus::Dist0,1= " << fDi    1221   G4cout << "CurrentStatus::Dist0,1= " << fDistance[0] 
1257          << " " << fDistance[1] << " areacode    1222          << " " << fDistance[1] << " areacode = " << fAreacode[0] 
1258          << " " << fAreacode[1] << G4endl;       1223          << " " << fAreacode[1] << G4endl;
1259 }                                                1224 }
1260                                                  1225 
1261 //===========================================    1226 //=====================================================================
1262 // G4VTwistSurface::Boundary class               1227 // G4VTwistSurface::Boundary class
1263 //===========================================    1228 //=====================================================================
1264                                                  1229 
1265 //===========================================    1230 //=====================================================================
                                                   >> 1231 //* Boundary::Boundary ------------------------------------------------
                                                   >> 1232 
                                                   >> 1233 G4VTwistSurface::Boundary::Boundary()
                                                   >> 1234  : fBoundaryAcode(-1), fBoundaryType(0)
                                                   >> 1235 {
                                                   >> 1236 }
                                                   >> 1237 
                                                   >> 1238 //=====================================================================
                                                   >> 1239 //* Boundary::~Boundary -----------------------------------------------
                                                   >> 1240 
                                                   >> 1241 G4VTwistSurface::Boundary::~Boundary()
                                                   >> 1242 {
                                                   >> 1243 }
                                                   >> 1244 
                                                   >> 1245 //=====================================================================
1266 //* Boundary::SetFields ---------------------    1246 //* Boundary::SetFields -----------------------------------------------
1267                                                  1247 
1268 void                                             1248 void
1269 G4VTwistSurface::Boundary::SetFields(const G4 << 1249 G4VTwistSurface::Boundary::SetFields(const G4int         &areacode, 
1270                                 const G4Three << 1250                                 const G4ThreeVector &d, 
1271                                 const G4Three << 1251                                 const G4ThreeVector &x0, 
1272                                 const G4int&  << 1252                                 const G4int         &boundarytype)
1273 {                                                1253 {
1274   fBoundaryAcode     = areacode;                 1254   fBoundaryAcode     = areacode;
1275   fBoundaryDirection = d;                        1255   fBoundaryDirection = d;
1276   fBoundaryX0        = x0;                       1256   fBoundaryX0        = x0;
1277   fBoundaryType      = boundarytype;             1257   fBoundaryType      = boundarytype;
1278 }                                                1258 }
1279                                                  1259 
1280 //===========================================    1260 //=====================================================================
1281 //* Boundary::IsEmpty -----------------------    1261 //* Boundary::IsEmpty -------------------------------------------------
1282                                                  1262 
1283 G4bool G4VTwistSurface::Boundary::IsEmpty() c    1263 G4bool G4VTwistSurface::Boundary::IsEmpty() const 
1284 {                                                1264 {
1285   return fBoundaryAcode == -1;                << 1265   if (fBoundaryAcode == -1) return true;
                                                   >> 1266   return false;
1286 }                                                1267 }
1287                                                  1268 
1288 //===========================================    1269 //=====================================================================
1289 //* Boundary::GetBoundaryParameters ---------    1270 //* Boundary::GetBoundaryParameters -----------------------------------
1290                                                  1271 
1291 G4bool                                           1272 G4bool
1292 G4VTwistSurface::Boundary::GetBoundaryParamet << 1273 G4VTwistSurface::Boundary::GetBoundaryParameters(const G4int         &areacode, 
1293                                               << 1274                                                   G4ThreeVector &d,
1294                                               << 1275                                                   G4ThreeVector &x0, 
1295                                               << 1276                                                   G4int  &boundarytype) const 
1296 {                                                1277 {  
1297   // areacode must be one of them:               1278   // areacode must be one of them:
1298   // sAxis0 & sAxisMin, sAxis0 & sAxisMax,       1279   // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
1299   // sAxis1 & sAxisMin, sAxis1 & sAxisMax        1280   // sAxis1 & sAxisMin, sAxis1 & sAxisMax
1300   //                                          << 1281   if ((areacode & sAxis0) && (areacode & sAxis1))
1301   if (((areacode & sAxis0) != 0) && ((areacod << 
1302   {                                              1282   {
1303     std::ostringstream message;                  1283     std::ostringstream message;
1304     message << "Located in the corner area."     1284     message << "Located in the corner area." << G4endl
1305             << "        This function returns    1285             << "        This function returns a direction vector of "
1306             << "a boundary line." << G4endl      1286             << "a boundary line." << G4endl
1307             << "        areacode = " << areac    1287             << "        areacode = " << areacode;
1308     G4Exception("G4VTwistSurface::Boundary::G    1288     G4Exception("G4VTwistSurface::Boundary::GetBoundaryParameters()",
1309                 "GeomSolids0003", FatalExcept    1289                 "GeomSolids0003", FatalException, message);
1310   }                                              1290   } 
1311   if ((areacode & sSizeMask) != (fBoundaryAco    1291   if ((areacode & sSizeMask) != (fBoundaryAcode & sSizeMask))
1312   {                                              1292   {
1313     return false;                                1293     return false;
1314   }                                              1294   }
1315   d  = fBoundaryDirection;                       1295   d  = fBoundaryDirection;
1316   x0 = fBoundaryX0;                              1296   x0 = fBoundaryX0;
1317   boundarytype = fBoundaryType;                  1297   boundarytype = fBoundaryType;
1318   return true;                                   1298   return true;
1319 }                                                1299 }
1320                                                  1300