Geant4  10.03
G4ReduciblePolygon.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4ReduciblePolygon.hh 72091 2013-07-09 09:55:52Z gcosmo $
28 //
29 //
30 // --------------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 //
34 // G4ReduciblePolygon.hh
35 //
36 // Class description:
37 //
38 // Utility class used to specify, test, reduce, and/or otherwise
39 // manipulate a 2D polygon.
40 //
41 // For this class, a polygon consists of n > 2 points in 2D
42 // space (a,b). The polygon is always closed by connecting the
43 // last point to the first. A G4ReduciblePolygon is guaranteed
44 // to fulfill this definition in all instances.
45 //
46 // Illegal manipulations (such that a valid polygon would be
47 // produced) result in an error return if possible and
48 // otherwise a G4Exception.
49 //
50 // The set of manipulations is limited currently to what
51 // is needed for G4Polycone and G4Polyhedra.
52 
53 // Author:
54 // David C. Williams (davidw@scipp.ucsc.edu)
55 // --------------------------------------------------------------------
56 #ifndef G4ReduciblePolygon_hh
57 #define G4ReduciblePolygon_hh
58 
59 #include "G4Types.hh"
60 
62 {
64 
65  public:
66  //
67  // Creator: via simple a/b arrays
68  //
69  G4ReduciblePolygon( const G4double a[], const G4double b[], G4int n );
70 
71  //
72  // Creator: a special version for G4Polygon and G4Polycone
73  // that takes two a points at planes of b
74  // (where a==r and b==z for the GEANT3 classic PCON and PGON)
75  //
76  G4ReduciblePolygon( const G4double rmin[], const G4double rmax[],
77  const G4double z[], G4int n );
78 
79  virtual ~G4ReduciblePolygon();
80 
81  //
82  // Queries
83  //
84  inline G4int NumVertices() const { return numVertices; }
85 
86  inline G4double Amin() const { return aMin; }
87  inline G4double Amax() const { return aMax; }
88  inline G4double Bmin() const { return bMin; }
89  inline G4double Bmax() const { return bMax; }
90 
91  void CopyVertices( G4double a[], G4double b[] ) const;
92 
93  //
94  // Manipulations
95  //
96  void ScaleA( G4double scale );
97  void ScaleB( G4double scale );
98 
101 
102  void ReverseOrder();
103  void StartWithZMin();
104 
105  //
106  // Tests
107  //
108  G4double Area();
109  G4bool CrossesItself( G4double tolerance );
111  G4double a2, G4double b2, G4double tolerance );
112 
113  void Print(); // Debugging only
114 
115  public: // without description
116 
117  G4ReduciblePolygon(__void__&);
118  // Fake default constructor for usage restricted to direct object
119  // persistency for clients requiring preallocation of memory for
120  // persistifiable objects.
121 
122  protected:
123 
124  void Create( const G4double a[], const G4double b[], G4int n );
125 
126  void CalculateMaxMin();
127 
128  //
129  // Below are member values that are *always* kept up to date (please!)
130  //
133 
134  //
135  // A subclass which holds the vertices in a single-linked list
136  //
137  // Yeah, call me an old-fashioned c hacker, but I cannot make
138  // myself use the rogue tools for this trivial list.
139  //
140  struct ABVertex; // Secret recipe for allowing
141  friend struct ABVertex; // protected nested structures
142  struct ABVertex
143  {
144  ABVertex() : a(0.), b(0.), next(0) {}
147  };
148 
150 
151  private:
152 
155  // Private copy constructor and assignment operator.
156 };
157 
158 
159 //
160 // A companion class for iterating over the vertices of our polygon.
161 // It is simple enough that all routines are declared inline here.
162 //
164 {
165  public:
166 
168  { subject = theSubject; current=0; }
169 
170  void Begin() { current = subject->vertexHead; }
171  G4bool Next() { if (current) current=current->next; return Valid(); }
172 
173  G4bool Valid() const { return current!=0; }
174 
175  G4double GetA() const { return current->a; }
176  G4double GetB() const { return current->b; }
177 
178  protected:
179 
180  const G4ReduciblePolygon *subject; // Who are we iterating over
182 };
183 
184 #endif
G4bool CrossesItself(G4double tolerance)
G4double Amax() const
G4ReduciblePolygonIterator(const G4ReduciblePolygon *theSubject)
void ScaleB(G4double scale)
G4ReduciblePolygon & operator=(const G4ReduciblePolygon &)
G4ReduciblePolygon::ABVertex * current
void Create(const G4double a[], const G4double b[], G4int n)
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
G4double Amin() const
int G4int
Definition: G4Types.hh:78
G4bool RemoveDuplicateVertices(G4double tolerance)
G4bool RemoveRedundantVertices(G4double tolerance)
G4int NumVertices() const
G4double Bmax() const
void ScaleA(G4double scale)
bool G4bool
Definition: G4Types.hh:79
const G4int n
void CopyVertices(G4double a[], G4double b[]) const
const G4ReduciblePolygon * subject
G4bool BisectedBy(G4double a1, G4double b1, G4double a2, G4double b2, G4double tolerance)
G4ReduciblePolygon(const G4double a[], const G4double b[], G4int n)
G4double Bmin() const
double G4double
Definition: G4Types.hh:76