Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4ReduciblePolygon
27//
28// Class description:
29//
30// Utility class used to specify, test, reduce, and/or otherwise
31// manipulate a 2D polygon.
32//
33// For this class, a polygon consists of n > 2 points in 2D
34// space (a,b). The polygon is always closed by connecting the
35// last point to the first. A G4ReduciblePolygon is guaranteed
36// to fulfill this definition in all instances.
37//
38// Illegal manipulations (such that a valid polygon would be
39// produced) result in an error return if possible and
40// otherwise a G4Exception.
41//
42// The set of manipulations is limited currently to what
43// is needed for G4Polycone and G4Polyhedra.
44
45// Author: David C. Williams ([email protected])
46// --------------------------------------------------------------------
47#ifndef G4REDUCIBLEPOLYGON_HH
48#define G4REDUCIBLEPOLYGON_HH
49
50#include "G4Types.hh"
51
53{
55
56 public:
57 //
58 // Creator: via simple a/b arrays
59 //
60 G4ReduciblePolygon( const G4double a[], const G4double b[], G4int n );
61
62 //
63 // Creator: a special version for G4Polygon and G4Polycone
64 // that takes two a points at planes of b
65 // (where a==r and b==z for the GEANT3 classic PCON and PGON)
66 //
67 G4ReduciblePolygon( const G4double rmin[], const G4double rmax[],
68 const G4double z[], G4int n );
69
70 virtual ~G4ReduciblePolygon();
71
72 //
73 // Queries
74 //
75 inline G4int NumVertices() const { return numVertices; }
76
77 inline G4double Amin() const { return aMin; }
78 inline G4double Amax() const { return aMax; }
79 inline G4double Bmin() const { return bMin; }
80 inline G4double Bmax() const { return bMax; }
81
82 void CopyVertices( G4double a[], G4double b[] ) const;
83
84 //
85 // Manipulations
86 //
87 void ScaleA( G4double scale );
88 void ScaleB( G4double scale );
89
92
93 void ReverseOrder();
94 void StartWithZMin();
95
96 //
97 // Tests
98 //
99 G4double Area();
100 G4bool CrossesItself( G4double tolerance );
102 G4double a2, G4double b2, G4double tolerance );
103
104 void Print(); // Debugging only
105
106 public: // without description
107
108 G4ReduciblePolygon(__void__&);
109 // Fake default constructor for usage restricted to direct object
110 // persistency for clients requiring preallocation of memory for
111 // persistifiable objects.
112
113 protected:
114
115 void Create( const G4double a[], const G4double b[], G4int n );
116
117 void CalculateMaxMin();
118
119 //
120 // Below are member values that are *always* kept up to date (please!)
121 //
124
125 //
126 // A subclass which holds the vertices in a single-linked list
127 //
128 // Yeah, call me an old-fashioned c hacker, but I cannot make
129 // myself use the rogue tools for this trivial list.
130 //
131 struct ABVertex; // Secret recipe for allowing
132 friend struct ABVertex; // protected nested structures
133 struct ABVertex
134 {
135 ABVertex() : a(0.), b(0.), next(0) {}
138 };
139
141
142 private:
143
145 G4ReduciblePolygon& operator=(const G4ReduciblePolygon&);
146 // Private copy constructor and assignment operator.
147};
148
149// A companion class for iterating over the vertices of our polygon.
150// It is simple enough that all routines are declared inline here.
151//
153{
154 public:
155
157 { subject = theSubject; current = nullptr; }
158
161 {
162 if (current != nullptr) current=current->next;
163 return Valid();
164 }
165
166 G4bool Valid() const { return current != nullptr; }
167
168 G4double GetA() const { return current->a; }
169 G4double GetB() const { return current->b; }
170
171 protected:
172
173 const G4ReduciblePolygon* subject = nullptr; // Who are we iterating over
174 G4ReduciblePolygon::ABVertex* current = nullptr; // Current vertex
175};
176
177#endif
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4ReduciblePolygon::ABVertex * current
G4ReduciblePolygonIterator(const G4ReduciblePolygon *theSubject)
const G4ReduciblePolygon * subject
G4bool BisectedBy(G4double a1, G4double b1, G4double a2, G4double b2, G4double tolerance)
void Create(const G4double a[], const G4double b[], G4int n)
void ScaleB(G4double scale)
G4double Amin() const
void CopyVertices(G4double a[], G4double b[]) const
G4bool RemoveDuplicateVertices(G4double tolerance)
G4int NumVertices() const
G4bool RemoveRedundantVertices(G4double tolerance)
G4double Bmin() const
G4bool CrossesItself(G4double tolerance)
G4double Bmax() const
G4double Amax() const
void ScaleA(G4double scale)